Upgrade to Pro — share decks privately, control downloads, hide ads and more …

new_urlparser.pdf

 new_urlparser.pdf

Yosuke Furukawa

May 09, 2023
Tweet

More Decks by Yosuke Furukawa

Other Decks in Programming

Transcript

  1. URL Parser ͳʹͦΕ͓͍͍͠ ͷʁ • URL Parser ͦ΋ͦ΋Կʁ > new

    URL("https://example.com"); URL { href: 'https://example.com/', origin: 'https://example.com', protocol: 'https:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/', search: '', searchParams: URLSearchParams {}, hash: '' }
  2. URL Parser ͳʹͦΕ͓͍͍͠ ͷʁ • URL Parser ͦ΋ͦ΋Կʁ > new

    URL("https://example.com"); URL { href: 'https://example.com/', origin: 'https://example.com', protocol: 'https:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/', search: '', searchParams: URLSearchParams {}, hash: '' } ͜͏͍͏΍ͭ
  3. Legacy URL Parser • const url = require("url"); • Ͱݺͼग़͢΍ͭ

    • JavaScript ੡ • Legacy URL Parser ͱͯ͠ղઆ͞Ε͍ͯΔ • طʹࠓ͸ deprecated ѻ͍
  4. Ұݸલͷ URL Parser • new URL() Ͱݺͼग़͢΍ͭ • JavaScript Ͱ

    binding ͞ΕͯΔ͕ɺ parser ຊମ ͸ C++ (not ada) • φΠʔϒͳ࣮૷ • ଎͍͜ͱΑΓ΋ spec ʹ஧࣮ͳ͜ͱΛ໨ࢦͯͨ͠
  5. JavaScript vs C++ • Αٞ͘࿦ʹͳΔ໰୊ • JavaScript ͰίʔυΛॻ͘ͱॳظίετ͸஗͍͕ɺJITͷӨڹͰߴ଎ԽͰ ͖Δɻ •

    C++ ͰίʔυΛॻ͘ͱ଎͍͕ɺJITͷԸܙ͸ड͚ΒΕͳ͍ɻ • C++ Ͱશ෦ॻ͍ͨΒ͡Ό͋ྑ͍ͷ͔ʁͱ͍͏ͱɺͦ͏Ͱ΋ͳ͍ɻ։ൃί ετ΍ϝϞϦ΁ͷέΞ͕ॏཁʹͳΔɻ • ͜ͷ࣌఺Ͱ͸ WHATWG URL vs Legacy URL ͸ͲͪΒ΋࢒͍ͯ͘͠ํ਑ Ͱ։ൃ͞Ε͍ͯͯɺύϑΥʔϚϯεൺֱ͸ͦΜͳʹଟ͘͞Ε͍ͯͳ͍ɻ
  6. JavaScript and C++ • ݁ہ C++ Ͱॻ͘ͱͯ͠΋ JavaScript ͷΠϯλϑΣʔεͰఏڙ͞ Ε͍ͯΔͷͰɺJS

    <=> C++ ؒͷ৘ใͷड͚౉͕͠ඞཁʹͳΔɻ • ݴ͍׵͑Δͱ JS ͷੈքͱ C++ ͷੈք͕ Node.js ʹ͸ଘࡏ͢Δɻ • JS ͔Β C++ ʹ৘ใͷड͚౉͠Λ͢Δ࣌ʹߦ͍ͬͯΔͷ͕ String ͷ serialize ͱ͍͏ॲཧɻ • Node.jsͰBuffer Λ௚઀࢖ͬͨ͜ͱ͕͋Δਓ͸ serialize ͞Εͨจ ࣈྻΛ௚઀࢖͍ͬͯΔɻ
  7. ݱࡏͷ URL Parser • new URL() Ͱݺͼग़͢΍ͭ • Ada ͱݺ͹ΕΔύʔαʔ(C++)Ͱ࣮૷͞Εͯ

    Δɻ • JSͱC++ͷόΠϯσΟϯά΋༻ҙ͞Ε͍ͯΔɻ • String ͷ serialize ΛۃྗলྗԽ͍ͯ͠Δɻ