| 335 | } |
| 336 | } |
| 337 | |
| 338 | JSValueRef V8JavaScriptContext::newFunction(const Ref<JSFunction>& callable, JSExceptionTracker& exceptionTracker) { |
| 339 | v8::HandleScope handleScope(_isolate); |
| 340 | |
| 341 | auto externalData = |
| 342 | IndirectV8Persistent::makeWeakExternal(_isolate, unsafeBridgeRetain(callable.get()), freeWrappedPointer); |
| 343 | auto funcTemplate = v8::FunctionTemplate::New(_isolate, InvokeCallable, externalData); |
| 344 | |
| 345 | v8::Local<v8::Function> func; |
| 346 | funcTemplate->SetClassName(v8::String::NewFromUtf8Literal(_isolate, "ValdiFunctionObject")); |
| 347 | |
| 348 | v8::Local<v8::Context> context = v8::Local<v8::Context>::New(_isolate, _context); |
| 349 | |
| 350 | if (!funcTemplate->GetFunction(context).ToLocal(&func)) { |
| 351 | exceptionTracker.onError("Failed to create function"); |
| 352 | return JSValueRef(); |
| 353 | } |
| 354 | |
| 355 | if (!callable->getReferenceInfo().getName().isEmpty()) { |
| 356 | auto callableName = callable->getReferenceInfo().getName().toStringView(); |
| 357 | v8::MaybeLocal<v8::String> maybeValue = v8::String::NewFromUtf8( |
| 358 | _isolate, callableName.data(), v8::NewStringType::kNormal, static_cast<int32_t>(callableName.length())); |
| 359 | |
| 360 | if (maybeValue.IsEmpty()) { |
| 361 | exceptionTracker.onError("Failed to convert function name to string"); |
| 362 | return JSValueRef(); |
| 363 | } |
| 364 | |
| 365 | func->SetName(maybeValue.ToLocalChecked()); |
| 366 | } |
| 367 | |
| 368 | func->SetPrivate(context, _functionDataProperty.Get(_isolate), externalData); |
| 369 | return toRetainedJSValueRef(IndirectV8Persistent::make(_isolate, func)); |
| 370 | } |
| 371 | |
| 372 | Valdi::JSValueRef V8JavaScriptContext::newBigInt(const Valdi::BigInt& value, |
no test coverage detected