nodeeps

 nodeeps

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

D76231a2114896dfcc7b79ac69558b79?s=128

Yosuke Furukawa

January 16, 2016
Tweet

Transcript

  1. 6.

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

    ͷϨΠϠͰ Stream Λ࣮૷͢Δͱ͍͏ ΋ͷ • C++Addon Λ࡞Δͱ͖ʹStreamͰॻ͚Δ • ࣮͸Nodeͷcore API ͸طʹ͜ͷC++ Stream͕࢖ΘΕ ͍ͯΔɻ
  2. 9.
  3. 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 • (∩´∀ʆ)∩ƂŖŘ
  4. 11.

    ES6 modules interop • JSͷϨΠϠ͡Όͳͯ͘ɺC++ͷϨΠϠͰ fallbackͤͯ͞CJSͳͷ͔ES6ͳͷ͔try͢Δ // ٖࣅίʔυ try {

    v8::Script::Compile // ES6ͰίϯύΠϧͰ͖Δ͔Ͳ͏͔ } catch (e) { v8::Script::CompileModule // CJSͰίϯύΠϧͯ͠ΈΔ }
  5. 12.

    ES6 modules interop • require͕ߦΘΕͨΒ 1. ·ͣ͸CJS ͔ ES6 ͔ΛνΣοΫ͢Δ

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

    ES6 modules interop • require͕ߦΘΕͨΒ 1. ·ͣ͸CJS ͔ ES6 ͔ΛνΣοΫ͢Δ

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

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

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

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

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

    Buffer.alloc / Buffer.zalloc / Buffer.from • new Buffer ͸ deprecated

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

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

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