MCPcopy Create free account
hub / github.com/Snapchat/Valdi / newTypedArrayFromArrayBuffer

Method newTypedArrayFromArrayBuffer

valdi/src/valdi/v8/V8JavaScriptContext.cpp:438–489  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

436 const char* message,
437 JSExceptionTracker& exceptionTracker) {
438 if (catcher.HasCaught()) {
439 exceptionTracker.storeException(
440 toRetainedJSValueRef(IndirectV8Persistent::make(_isolate, catcher.Exception())));
441 } else {
442 exceptionTracker.onError(message);
443 }
444}
445
446JSValueRef V8JavaScriptContext::newStringUTF8(const std::string_view& str, JSExceptionTracker& exceptionTracker) {
447 v8::HandleScope handleScope(_isolate);
448 auto maybeValue =
449 v8::String::NewFromUtf8(_isolate, str.data(), v8::NewStringType::kNormal, static_cast<int32_t>(str.length()));
450 v8::Local<v8::String> val;
451 if (!maybeValue.ToLocal(&val)) {
452 exceptionTracker.onError("Cannot create utf8 string");
453 }
454 return toRetainedJSValueRef(IndirectV8Persistent::make(_isolate, val));
455}
456
457JSValueRef V8JavaScriptContext::newStringUTF16(const std::u16string_view& str, JSExceptionTracker& exceptionTracker) {
458 v8::HandleScope handleScope(_isolate);
459 v8::MaybeLocal<v8::String> maybeValue = v8::String::NewFromTwoByte(_isolate,
460 reinterpret_cast<const uint16_t*>(str.data()),
461 v8::NewStringType::kNormal,
462 static_cast<int32_t>(str.length()));
463
464 if (maybeValue.IsEmpty()) {
465 exceptionTracker.onError("Cannot create utf16 string");
466 }
467 return toRetainedJSValueRef(IndirectV8Persistent::make(_isolate, maybeValue.ToLocalChecked()));
468}
469
470JSValueRef V8JavaScriptContext::newArray(size_t initialSize, JSExceptionTracker& exceptionTracker) {
471 v8::HandleScope handleScope(_isolate);
472 auto val = v8::Array::New(_isolate, 0);
473 return toRetainedJSValueRef(IndirectV8Persistent::make(_isolate, val));
474}
475
476JSValueRef V8JavaScriptContext::newArrayWithValues(const JSValue* values,
477 size_t size,
478 JSExceptionTracker& exceptionTracker) {
479 v8::HandleScope handleScope(_isolate);
480
481 auto* valuesUnpacked = static_cast<v8::Local<v8::Value>*>(alloca(sizeof(v8::Local<v8::Value>) * size));
482
483 for (size_t i = 0; i < size; i++) {
484 auto val = fromValdiJSValue(_isolate, values[i], exceptionTracker);
485 if (!exceptionTracker) {
486 return JSValueRef();
487 }
488 valuesUnpacked[i] = val;
489 }
490
491 auto val = v8::Array::New(_isolate, valuesUnpacked, size);
492 return toRetainedJSValueRef(IndirectV8Persistent::make(_isolate, val));

Callers 1

Calls 4

fromValdiJSValueFunction · 0.70
onErrorMethod · 0.65
CastFunction · 0.50
NewFunction · 0.50

Tested by

no test coverage detected