int FXJS_Execute(v8::Isolate* pIsolate, IFXJS_Context* pJSContext, const wchar_t* script, long length, FXJSErr* pError) { v8::Isolate::Scope isolate_scope(pIsolate); v8::TryCatch try_catch(pIsolate); CFX_WideString wsScript(script); CFX_ByteString bsScript = wsScript.UTF8Encode(); v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); v8::Local<v8::Script> compiled_script; if (!v8::Script::Compile( context, v8::String::NewFromUtf8( pIsolate, bsScript.c_str(), v8::NewStringType::kNormal, bsScript.GetLength()).ToLocalChecked()) .ToLocal(&compiled_script)) { v8::String::Utf8Value error(try_catch.Exception()); // TODO(tsepez): return error via pError->message. return -1; } v8::Local<v8::Value> result; if (!compiled_script->Run(context).ToLocal(&result)) { v8::String::Utf8Value error(try_catch.Exception()); // TODO(tsepez): return error via pError->message. return -1; } return 0; }
int JS_Parse(IJS_Runtime* pJSRuntime, IFXJS_Context* pJSContext, const wchar_t* script, long length, FXJSErr* perror) { v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; v8::Isolate::Scope isolate_scope(isolate); v8::TryCatch try_catch; CFX_WideString wsScript(script); CFX_ByteString bsScript = wsScript.UTF8Encode(); v8::Handle<v8::Script> compiled_script = v8::Script::Compile(v8::String::NewFromUtf8(isolate, bsScript.c_str(), v8::String::kNormalString, bsScript.GetLength())); if (compiled_script.IsEmpty()) { v8::String::Utf8Value error(try_catch.Exception()); return -1; } return 0; }