@@ -56,10 +56,16 @@ void ContextWrap::Initialize(Handle<Object> target) {
56
56
NODE_SET_PROTOTYPE_METHOD (constructor_template,
57
57
" onContextCreationFromWebKit" ,
58
58
ContextWrap::OnContextCreationFromWebKit);
59
+ NODE_SET_PROTOTYPE_METHOD (constructor_template,
60
+ " runScript" ,
61
+ ContextWrap::RunScript);
59
62
60
63
NODE_SET_METHOD (constructor_template,
61
64
" onContextCreationFromWebKit" ,
62
65
ContextWrap::OnContextCreationFromWebKit);
66
+ NODE_SET_METHOD (constructor_template,
67
+ " runScript" ,
68
+ ContextWrap::RunScript);
63
69
64
70
target->Set (String::NewSymbol (" Context" ),
65
71
constructor_template->GetFunction ());
@@ -103,10 +109,6 @@ Persistent<Context> ContextWrap::GetV8Context() {
103
109
Handle<Value> ContextWrap::OnContextCreationFromWebKit (const Arguments& args) {
104
110
HandleScope scope;
105
111
106
- if (args.Length () > 0 ) {
107
- Local<Object> sandbox = args[0 ]->ToObject ();
108
- }
109
-
110
112
ContextWrap* context_wrap = ObjectWrap::Unwrap<ContextWrap> (args.Holder ());
111
113
v8::Context* p = static_cast <v8::Context*>(args.Holder ()->GetPointerFromInternalField (1 ));
112
114
context_wrap->context_ = p;
@@ -115,4 +117,32 @@ Handle<Value> ContextWrap::OnContextCreationFromWebKit(const Arguments& args) {
115
117
return v8::Undefined ();
116
118
}
117
119
120
+ Handle<Value> ContextWrap::RunScript (const Arguments& args) {
121
+ HandleScope scope;
122
+
123
+ ContextWrap* context_wrap = ObjectWrap::Unwrap<ContextWrap> (args.Holder ());
124
+ if (!context_wrap->context_valid ) {
125
+ return v8::Undefined ();
126
+ }
127
+
128
+ TryCatch try_catch;
129
+ Local<String> code = args[0 ]->ToString ();
130
+ context_wrap->context_ ->Enter ();
131
+ Handle<Script> script = Script::Compile (code, String::New (" nwebkit.<anonymous>" ));
132
+ if (script.IsEmpty ()) {
133
+ // FIXME UGLY HACK TO DISPLAY SYNTAX ERRORS.
134
+ node::DisplayExceptionLine (try_catch);
135
+
136
+ // Hack because I can't get a proper stacktrace on SyntaxError
137
+ return try_catch.ReThrow ();
138
+ }
139
+ Handle<Value> result;
140
+ result = script->Run ();
141
+ context_wrap->context_ ->Exit ();
142
+ if (result.IsEmpty ()) {
143
+ return try_catch.ReThrow ();
144
+ }
145
+
146
+ return result == args.This () ? result : scope.Close (result);
147
+ }
118
148
}
0 commit comments