Skip to content

Commit c7214fe

Browse files
bnoordhuisindutny
authored andcommitted
src: fix up after v8 upgrade
The two biggest changes are that v8::Script::New() has been removed and that a v8::Script object now has to be explicitly bound to a context if you want to run it from another context. We can accommodate both changes without breaking the vm module's public API or even the internal JS API.
1 parent 5e24adb commit c7214fe

3 files changed

Lines changed: 13 additions & 9 deletions

File tree

src/node.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1491,7 +1491,7 @@ static void ReportException(Environment* env, const TryCatch& try_catch) {
14911491
// Executes a str within the current v8 context.
14921492
static Local<Value> ExecuteString(Environment* env,
14931493
Handle<String> source,
1494-
Handle<Value> filename) {
1494+
Handle<String> filename) {
14951495
EscapableHandleScope scope(env->isolate());
14961496
TryCatch try_catch;
14971497

src/node_contextify.cc

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,11 @@ using v8::ObjectTemplate;
5151
using v8::Persistent;
5252
using v8::PropertyCallbackInfo;
5353
using v8::Script;
54+
using v8::ScriptCompiler;
55+
using v8::ScriptOrigin;
5456
using v8::String;
5557
using v8::TryCatch;
58+
using v8::UnboundScript;
5659
using v8::V8;
5760
using v8::Value;
5861
using v8::WeakCallbackData;
@@ -430,7 +433,7 @@ class ContextifyContext {
430433

431434
class ContextifyScript : public BaseObject {
432435
private:
433-
Persistent<Script> script_;
436+
Persistent<UnboundScript> script_;
434437

435438
public:
436439
static void Init(Environment* env, Local<Object> target) {
@@ -473,10 +476,10 @@ class ContextifyScript : public BaseObject {
473476
return;
474477
}
475478

476-
Local<Context> context = env->context();
477-
Context::Scope context_scope(context);
478-
479-
Local<Script> v8_script = Script::New(code, filename);
479+
ScriptOrigin origin(filename);
480+
ScriptCompiler::Source source(code, origin);
481+
Local<UnboundScript> v8_script =
482+
ScriptCompiler::CompileUnbound(env->isolate(), &source);
480483

481484
if (v8_script.IsEmpty()) {
482485
if (display_errors) {
@@ -639,8 +642,9 @@ class ContextifyScript : public BaseObject {
639642

640643
ContextifyScript* wrapped_script =
641644
Unwrap<ContextifyScript>(args.This());
642-
Local<Script> script = PersistentToLocal(env->isolate(),
643-
wrapped_script->script_);
645+
Local<UnboundScript> unbound_script =
646+
PersistentToLocal(env->isolate(), wrapped_script->script_);
647+
Local<Script> script = unbound_script->BindToCurrentContext();
644648

645649
Local<Value> result;
646650
if (timeout != -1) {

test/simple/test-vm-syntax-error-stderr.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ p.stdout.on('data', function(data) {
4545
process.on('exit', function() {
4646
assert(/BEGIN CERT/.test(output));
4747
assert(/^\s+\^/m.test(output));
48-
assert(/Unexpected identifier/.test(output));
48+
assert(/Invalid left-hand side expression in prefix operation/.test(output));
4949
});

0 commit comments

Comments
 (0)