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.
This commit is contained in:
Ben Noordhuis 2014-03-31 15:13:37 +02:00 committed by Fedor Indutny
parent 5e24adbb90
commit c7214fe355
3 changed files with 13 additions and 9 deletions

View File

@ -1491,7 +1491,7 @@ static void ReportException(Environment* env, const TryCatch& try_catch) {
// Executes a str within the current v8 context. // Executes a str within the current v8 context.
static Local<Value> ExecuteString(Environment* env, static Local<Value> ExecuteString(Environment* env,
Handle<String> source, Handle<String> source,
Handle<Value> filename) { Handle<String> filename) {
EscapableHandleScope scope(env->isolate()); EscapableHandleScope scope(env->isolate());
TryCatch try_catch; TryCatch try_catch;

View File

@ -51,8 +51,11 @@ using v8::ObjectTemplate;
using v8::Persistent; using v8::Persistent;
using v8::PropertyCallbackInfo; using v8::PropertyCallbackInfo;
using v8::Script; using v8::Script;
using v8::ScriptCompiler;
using v8::ScriptOrigin;
using v8::String; using v8::String;
using v8::TryCatch; using v8::TryCatch;
using v8::UnboundScript;
using v8::V8; using v8::V8;
using v8::Value; using v8::Value;
using v8::WeakCallbackData; using v8::WeakCallbackData;
@ -430,7 +433,7 @@ class ContextifyContext {
class ContextifyScript : public BaseObject { class ContextifyScript : public BaseObject {
private: private:
Persistent<Script> script_; Persistent<UnboundScript> script_;
public: public:
static void Init(Environment* env, Local<Object> target) { static void Init(Environment* env, Local<Object> target) {
@ -473,10 +476,10 @@ class ContextifyScript : public BaseObject {
return; return;
} }
Local<Context> context = env->context(); ScriptOrigin origin(filename);
Context::Scope context_scope(context); ScriptCompiler::Source source(code, origin);
Local<UnboundScript> v8_script =
Local<Script> v8_script = Script::New(code, filename); ScriptCompiler::CompileUnbound(env->isolate(), &source);
if (v8_script.IsEmpty()) { if (v8_script.IsEmpty()) {
if (display_errors) { if (display_errors) {
@ -639,8 +642,9 @@ class ContextifyScript : public BaseObject {
ContextifyScript* wrapped_script = ContextifyScript* wrapped_script =
Unwrap<ContextifyScript>(args.This()); Unwrap<ContextifyScript>(args.This());
Local<Script> script = PersistentToLocal(env->isolate(), Local<UnboundScript> unbound_script =
wrapped_script->script_); PersistentToLocal(env->isolate(), wrapped_script->script_);
Local<Script> script = unbound_script->BindToCurrentContext();
Local<Value> result; Local<Value> result;
if (timeout != -1) { if (timeout != -1) {

View File

@ -45,5 +45,5 @@ p.stdout.on('data', function(data) {
process.on('exit', function() { process.on('exit', function() {
assert(/BEGIN CERT/.test(output)); assert(/BEGIN CERT/.test(output));
assert(/^\s+\^/m.test(output)); assert(/^\s+\^/m.test(output));
assert(/Unexpected identifier/.test(output)); assert(/Invalid left-hand side expression in prefix operation/.test(output));
}); });