| 87 | }*/ |
| 88 | |
| 89 | bool JSFunction::Invoke(bool HasResult) |
| 90 | { |
| 91 | v8::Isolate* Isolate = ResultInfo.Isolate; |
| 92 | v8::Isolate::Scope IsolateScope(Isolate); |
| 93 | v8::HandleScope HandleScope(Isolate); |
| 94 | v8::Local<v8::Context> Context = ResultInfo.Context.Get(Isolate); |
| 95 | v8::Context::Scope ContextScope(Context); |
| 96 | |
| 97 | V8Arguments.clear(); |
| 98 | for (int i = 0; i < Arguments.size(); ++i) |
| 99 | { |
| 100 | V8Arguments.push_back(ToV8(Isolate, Context, Arguments[i])); |
| 101 | } |
| 102 | v8::TryCatch TryCatch(Isolate); |
| 103 | auto maybeValue = GFunction.Get(Isolate)->Call(Context, Context->Global(), static_cast<int>(V8Arguments.size()), V8Arguments.data()); |
| 104 | Arguments.clear(); |
| 105 | |
| 106 | if (TryCatch.HasCaught()) |
| 107 | { |
| 108 | LastExceptionInfo = FV8Utils::ExceptionToString(Isolate, TryCatch); |
| 109 | return false; |
| 110 | } |
| 111 | else |
| 112 | { |
| 113 | if (HasResult && !maybeValue.IsEmpty()) |
| 114 | { |
| 115 | ResultInfo.Result.Reset(Isolate, maybeValue.ToLocalChecked()); |
| 116 | } |
| 117 | return true; |
| 118 | } |
| 119 | } |
| 120 | } |