pulumi/sdk/nodejs/runtime/native/binding.gyp

25 lines
699 B
Text
Raw Normal View History

Take an initial stab at closure serialization This change contains an initial implementation of closure serialization built atop V8, rather than our own custom runtime. This requires that we use a Node.js dynamic C++ module, so that we can access the V8 APIs directly. No build magic is required beyond node-gyp. For the most part, this was straight forward, except for one part: we have to use internal V8 APIs. This is required for two reasons: 1) We need access to the function's lexical closure environment, so that we may look up closure variables. Although there is a tantalizingly-close v8::Object::CreationContext, its implementation intentionally pokes through closure contexts in order to recover the Function constructor context instead. That's not what we want. We want the raw, unadulterated Function::context. 2) We need to control the lexical lookups of free variables so that they can look past chained contexts, lexical contexts, withs, and eval-style context extensions. Simply runing a v8::Script, or simulating an eval, doesn't do the trick. Hence, we need to access the unexported v8::internal::Context::Lookup function. There is a third reason which is not yet implemented: free variable calculation. I could use Esprima, or do my own scanner for free variables, but I'd prefer to simply use the V8 parser so that we're using the same JavaScript parser across all components. That too is not part of the v8.h API, so we'll need to crack it open more. To be clear, these are still exported public APIs, in proper headers that are distributed with both Node and V8. They simply aren't part of the "stable" v8.h surface area. As a result, I do expect that maintaining this will be tricky, and I'd like to keep exploring how to do this without needing the internal dependency. For instance, although this works with node-gyp just fine, we will probably be brittle across versions of Node/V8, when the internal APIs might be changing. This will introduce unfortunate versioning headaches (all, hopefully and thankfully, caught at compile-time).
2017-09-02 22:09:28 +02:00
{
"targets": [
{
"target_name": "nativeruntime",
"sources": [
"closure.cc"
],
"conditions": [
[ 'OS=="win"',
{
"include_dirs": [
"<!(node -e \"console.log(`third_party/node/node-${process.version}/deps/v8`)\")"
]
},
{
"include_dirs": [
"<!(node -e \"console.log(\`third_party/node/node-\${process.version}/deps/v8\`)\")"
]
}
]
Take an initial stab at closure serialization This change contains an initial implementation of closure serialization built atop V8, rather than our own custom runtime. This requires that we use a Node.js dynamic C++ module, so that we can access the V8 APIs directly. No build magic is required beyond node-gyp. For the most part, this was straight forward, except for one part: we have to use internal V8 APIs. This is required for two reasons: 1) We need access to the function's lexical closure environment, so that we may look up closure variables. Although there is a tantalizingly-close v8::Object::CreationContext, its implementation intentionally pokes through closure contexts in order to recover the Function constructor context instead. That's not what we want. We want the raw, unadulterated Function::context. 2) We need to control the lexical lookups of free variables so that they can look past chained contexts, lexical contexts, withs, and eval-style context extensions. Simply runing a v8::Script, or simulating an eval, doesn't do the trick. Hence, we need to access the unexported v8::internal::Context::Lookup function. There is a third reason which is not yet implemented: free variable calculation. I could use Esprima, or do my own scanner for free variables, but I'd prefer to simply use the V8 parser so that we're using the same JavaScript parser across all components. That too is not part of the v8.h API, so we'll need to crack it open more. To be clear, these are still exported public APIs, in proper headers that are distributed with both Node and V8. They simply aren't part of the "stable" v8.h surface area. As a result, I do expect that maintaining this will be tricky, and I'd like to keep exploring how to do this without needing the internal dependency. For instance, although this works with node-gyp just fine, we will probably be brittle across versions of Node/V8, when the internal APIs might be changing. This will introduce unfortunate versioning headaches (all, hopefully and thankfully, caught at compile-time).
2017-09-02 22:09:28 +02:00
]
}
]
}