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

nodeeps

 nodeeps

jserinfo 5周年イベントで発表した Node-EPs の紹介です。

D76231a2114896dfcc7b79ac69558b79?s=128

Yosuke Furukawa
PRO

January 16, 2016
Tweet

Transcript

  1. nodejs/node-eps @yosuke_furukawa

  2. JSer.info 5प೥ ͓ΊͰͱ͏͍͟͝·͢

  3. NodeEPS • Node Enhancement Proposals (Node EPs)

  4. ఏҊ͞Ε͍ͯΔ΋ͷ঺հ

  5. C++ Streams

  6. C++ Streams • Fedor Indutny ͕ఏҊ • Node.js ͷ C++

    ͷϨΠϠͰ Stream Λ࣮૷͢Δͱ͍͏ ΋ͷ • C++Addon Λ࡞Δͱ͖ʹStreamͰॻ͚Δ • ࣮͸Nodeͷcore API ͸طʹ͜ͷC++ Stream͕࢖ΘΕ ͍ͯΔɻ
  7. C++ Streams • ఏҊ͍ͯ͠Δ಺༰͸ྑ͔͕ͬͨͪΐͬͱείʔ ϓ͕ҧ͏ͱ͍͏͜ͱͰClose… • JSͷAPI͕มΘΔΘ͚Ͱ͸ͳ͍ͷͰɺείʔϓ ֎ • ͱ͸͍͑C++ͷpublic

    APIʹ͸͍͔ͭͳΔ͔΋
  8. ES6 modules interop

  9. None
  10. ES6 modules interop • Bradly Meck͕ఏҊ • interoperability for ES6

    modules and node’s existing modules • create Registry Object (Ϟδϡʔϧͷঢ়گ(fetch, translate, ready ౳)Λ·ͱΊ͓ͯ͘Map instance) for interop • (∩´∀ʆ)∩ƂŖŘ
  11. ES6 modules interop • JSͷϨΠϠ͡Όͳͯ͘ɺC++ͷϨΠϠͰ fallbackͤͯ͞CJSͳͷ͔ES6ͳͷ͔try͢Δ // ٖࣅίʔυ try {

    v8::Script::Compile // ES6ͰίϯύΠϧͰ͖Δ͔Ͳ͏͔ } catch (e) { v8::Script::CompileModule // CJSͰίϯύΠϧͯ͠ΈΔ }
  12. ES6 modules interop • require͕ߦΘΕͨΒ 1. ·ͣ͸CJS ͔ ES6 ͔ΛνΣοΫ͢Δ

    2. ΋͠ CJS ͩͬͨΒ 1. ଈ࣌ධՁͯ͠ module.exportsʹೖ͍ͬͯΔΦϒδΣΫτ͕͋Ε͹࣋ͬͯ͘Δ 3. ΋͠ ES6 ͩͬͨΒ 1. import / export Λparse͢Δ 2. ࠶ؼతʹ require Λ࣮ߦͯ͠αϒϞδϡʔϧΛऩू͢Δ 3. ͢΂ͯͷαϒϞδϡʔϧΛ import ͔Βݺ͹ΕΔΑ͏ʹϚοϓ͢Δ 4. ධՁ͢Δ
  13. ES6 modules interop • require͕ߦΘΕͨΒ 1. ·ͣ͸CJS ͔ ES6 ͔ΛνΣοΫ͢Δ

    2. ΋͠ CJS ͩͬͨΒ 1. ଈ࣌ධՁͯ͠ module.exportsʹೖ͍ͬͯΔΦϒδΣΫτ͕͋Ε͹࣋ͬͯ͘Δ 3. ΋͠ ES6 ͩͬͨΒ 1. import / export Λparse͢Δ 2. ࠶ؼతʹ require Λ࣮ߦͯ͠αϒϞδϡʔϧΛऩू͢Δ 3. ͢΂ͯͷαϒϞδϡʔϧΛ import ͔Βݺ͹ΕΔΑ͏ʹϚοϓ͢Δ 4. ධՁ͢Δ
  14. ES6 modules interop • ·ͩσΟεΧογϣϯத… • whatwg-loaderͷਓ΋ؚΊͯ࿩͍ͯ͠Δ͕ɺ ίΞϝϯόʔͷ൓Ԡ͕ͳ͍

  15. Buffer.alloc / Buffer.zalloc / Buffer.from

  16. Buffer.alloc / Buffer.zalloc / Buffer.from • James N Snell ͕ఏҊ

    • ৽͘͠Buffer APIʹίϯετϥΫτ͢Δํ๏͕ ૿͑Δ • ͋ͱ new Buffer ͕ soft deprecated ʹͳΔ…
  17. soft deprecated new Buffer …

  18. Buffer.alloc / Buffer.zalloc / Buffer.from • new Buffer(Number) ͸ةݥ •

    ༩͑ΒΕͨ਺ࣈͷαΠζ෼ϝϞϦΛୣ͏ • ΍Ζ͏ͱࢥ͑͹αʔόʔͰ೚ҙͷϝϞϦαΠ ζ֬อͰ͖Δ => DoS ߈ܸͰ͖Δ
  19. Buffer.alloc / Buffer.zalloc / Buffer.from var server = http.createServer(function (req,

    res) { var data = '' req.setEncoding('utf8') req.on('data', function (chunk) { data += chunk }) req.on('end', function () { var body = JSON.parse(data) res.end(new Buffer(body.str).toString('hex')) }) }) server.listen(8080) ຊདྷ͜͜͸stringΛ ظ଴͍ͯ͠Δ
  20. Buffer.alloc / Buffer.zalloc / Buffer.from var server = http.createServer(function (req,

    res) { var data = '' req.setEncoding('utf8') req.on('data', function (chunk) { data += chunk }) req.on('end', function () { var body = JSON.parse(data) res.end(new Buffer(body.str).toString('hex')) }) }) server.listen(8080) body.str = 1,000,000
  21. Buffer.alloc / Buffer.zalloc / Buffer.from var server = http.createServer(function (req,

    res) { var data = '' req.setEncoding('utf8') req.on('data', function (chunk) { data += chunk }) req.on('end', function () { var body = JSON.parse(data) res.end(new Buffer(body.str).toString('hex')) }) }) server.listen(8080) body.str = 1,000,000 .CZUFͷϝϞϦ͕֬อͰ͖Δɺ΋ͬͱ૿΍͢ͱଟ෼00.Ωϥʔʹࡴ͞ΕΔ ҐͷϝϞϦ΋֬อͰ͖ͪΌ͏ɻ
  22. ΍͹͍…

  23. Buffer.alloc / Buffer.zalloc / Buffer.from • ࣮ࡍʹ ws ͍ͬͯ͏Ϟδϡʔϧʹͦͷඃ֐͕͋ Γ͏Δͱ͍͏͜ͱͰطʹΞοϓσʔτࡁΈɻ

    • security ৘ใ΋ใࠂࡁΈ
  24. Buffer.alloc / Buffer.zalloc / Buffer.from • new Buffer ͸ deprecated

    ʹͳΓͦ͏ • ͦͷ୅ΘΓ৽͍͠ઐ༻ίϯετϥΫλ͕૿͑ Δ • ࠓͷ new Buffer Ͱ੍ݶ஋Λ࣋ͭΑ͏ʹͳΔ͔ ౳ͷৄࡉ͸·ͩdiscussing
  25. ·ͱΊ

  26. ·ͱΊ • C++ Stream ͱ͔ఏҊ͞ΕͯΔ • ES6 modules interop ͷఏҊ΋͋Δʂ

    • new Buffer ࢖Θͳ͍Α͏ʹ…
 (wsΞοϓσʔτ͍ͯͩ͘͠͞Ͷ…)