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

nodeeps

 nodeeps

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

Yosuke Furukawa

January 16, 2016
Tweet

More Decks by Yosuke Furukawa

Other Decks in Programming

Transcript

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

    ͷϨΠϠͰ Stream Λ࣮૷͢Δͱ͍͏ ΋ͷ • C++Addon Λ࡞Δͱ͖ʹStreamͰॻ͚Δ • ࣮͸Nodeͷcore API ͸طʹ͜ͷC++ Stream͕࢖ΘΕ ͍ͯΔɻ
  2. ES6 modules interop • Bradly Meck͕ఏҊ • interoperability for ES6

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

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

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

    2. ΋͠ CJS ͩͬͨΒ 1. ଈ࣌ධՁͯ͠ module.exportsʹೖ͍ͬͯΔΦϒδΣΫτ͕͋Ε͹࣋ͬͯ͘Δ 3. ΋͠ ES6 ͩͬͨΒ 1. import / export Λparse͢Δ 2. ࠶ؼతʹ require Λ࣮ߦͯ͠αϒϞδϡʔϧΛऩू͢Δ 3. ͢΂ͯͷαϒϞδϡʔϧΛ import ͔Βݺ͹ΕΔΑ͏ʹϚοϓ͢Δ 4. ධՁ͢Δ
  6. Buffer.alloc / Buffer.zalloc / Buffer.from • James N Snell ͕ఏҊ

    • ৽͘͠Buffer APIʹίϯετϥΫτ͢Δํ๏͕ ૿͑Δ • ͋ͱ new Buffer ͕ soft deprecated ʹͳΔ…
  7. Buffer.alloc / Buffer.zalloc / Buffer.from • new Buffer(Number) ͸ةݥ •

    ༩͑ΒΕͨ਺ࣈͷαΠζ෼ϝϞϦΛୣ͏ • ΍Ζ͏ͱࢥ͑͹αʔόʔͰ೚ҙͷϝϞϦαΠ ζ֬อͰ͖Δ => DoS ߈ܸͰ͖Δ
  8. 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Λ ظ଴͍ͯ͠Δ
  9. 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
  10. 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.Ωϥʔʹࡴ͞ΕΔ ҐͷϝϞϦ΋֬อͰ͖ͪΌ͏ɻ
  11. Buffer.alloc / Buffer.zalloc / Buffer.from • new Buffer ͸ deprecated

    ʹͳΓͦ͏ • ͦͷ୅ΘΓ৽͍͠ઐ༻ίϯετϥΫλ͕૿͑ Δ • ࠓͷ new Buffer Ͱ੍ݶ஋Λ࣋ͭΑ͏ʹͳΔ͔ ౳ͷৄࡉ͸·ͩdiscussing
  12. ·ͱΊ • C++ Stream ͱ͔ఏҊ͞ΕͯΔ • ES6 modules interop ͷఏҊ΋͋Δʂ

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