MCPcopy Create free account
hub / github.com/Tencent/puerts / EvalWithPath

Function EvalWithPath

unity/native_src/Src/JSEngine.cpp:24–52  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22 }
23
24 static void EvalWithPath(const v8::FunctionCallbackInfo<v8::Value>& Info)
25 {
26 v8::Isolate* Isolate = Info.GetIsolate();
27 v8::Isolate::Scope IsolateScope(Isolate);
28 v8::HandleScope HandleScope(Isolate);
29 v8::Local<v8::Context> Context = Isolate->GetCurrentContext();
30 v8::Context::Scope ContextScope(Context);
31
32 if (Info.Length() != 2 || !Info[0]->IsString() || !Info[1]->IsString())
33 {
34 FV8Utils::ThrowException(Isolate, "invalid argument for evalScript");
35 return;
36 }
37
38 v8::Local<v8::String> Source = Info[0]->ToString(Context).ToLocalChecked();
39 v8::Local<v8::String> Name = Info[1]->ToString(Context).ToLocalChecked();
40 v8::ScriptOrigin Origin(Name);
41 auto Script = v8::Script::Compile(Context, Source, &Origin);
42 if (Script.IsEmpty())
43 {
44 return;
45 }
46 auto Result = Script.ToLocalChecked()->Run(Context);
47 if (Result.IsEmpty())
48 {
49 return;
50 }
51 Info.GetReturnValue().Set(Result.ToLocalChecked());
52 }
53
54 void JSEngine::JSEngineWithNode()
55 {

Callers

nothing calls this directly

Calls 10

RunMethod · 0.80
ThrowExceptionFunction · 0.70
GetIsolateMethod · 0.45
LengthMethod · 0.45
IsStringMethod · 0.45
ToLocalCheckedMethod · 0.45
ToStringMethod · 0.45
IsEmptyMethod · 0.45
SetMethod · 0.45
GetReturnValueMethod · 0.45

Tested by

no test coverage detected