5 #include "src/wasm/wasm-js.h" 7 #include "src/api-inl.h" 8 #include "src/api-natives.h" 9 #include "src/assert-scope.h" 10 #include "src/ast/ast.h" 11 #include "src/execution.h" 12 #include "src/handles.h" 13 #include "src/heap/factory.h" 14 #include "src/isolate.h" 15 #include "src/objects-inl.h" 16 #include "src/objects/js-promise-inl.h" 17 #include "src/objects/templates.h" 18 #include "src/parsing/parse-info.h" 19 #include "src/trap-handler/trap-handler.h" 20 #include "src/wasm/streaming-decoder.h" 21 #include "src/wasm/wasm-engine.h" 22 #include "src/wasm/wasm-limits.h" 23 #include "src/wasm/wasm-memory.h" 24 #include "src/wasm/wasm-objects-inl.h" 25 #include "src/wasm/wasm-serialization.h" 35 std::shared_ptr<internal::wasm::CompilationResultResolver> resolver)
36 : isolate_(isolate), resolver_(std::move(resolver)) {
38 auto enabled_features = i::wasm::WasmFeaturesFromIsolate(i_isolate);
39 streaming_decoder_ = i_isolate->wasm_engine()->StartStreamingCompilation(
40 i_isolate, enabled_features, handle(i_isolate->context(), i_isolate),
44 void OnBytesReceived(
const uint8_t* bytes,
size_t size) {
47 void Finish() { streaming_decoder_->Finish(); }
51 streaming_decoder_->Abort();
56 if (exception.IsEmpty())
return;
58 resolver_->OnCompilationFailed(
66 streaming_decoder_->SetModuleCompiledCallback(
73 bool SetCompiledModuleBytes(
const uint8_t* bytes,
size_t size) {
74 if (!i::wasm::IsSupportedVersion(reinterpret_cast<i::Isolate*>(isolate_),
77 return streaming_decoder_->SetCompiledModuleBytes({bytes, size});
81 Isolate* isolate_ =
nullptr;
82 std::shared_ptr<internal::wasm::StreamingDecoder> streaming_decoder_;
83 std::shared_ptr<internal::wasm::CompilationResultResolver> resolver_;
86 WasmStreaming::WasmStreaming(std::unique_ptr<WasmStreamingImpl> impl)
87 : impl_(
std::move(impl)) {}
91 WasmStreaming::~WasmStreaming() =
default;
94 impl_->OnBytesReceived(bytes, size);
100 impl_->Abort(exception);
105 impl_->SetModuleCompiledCallback(callback, data);
109 return impl_->SetCompiledModuleBytes(bytes, size);
118 return managed->get();
123 #define ASSIGN(type, var, expr) \ 126 if (!expr.ToLocal(&var)) { \ 127 DCHECK(i_isolate->has_scheduled_exception()); \ 130 DCHECK(!i_isolate->has_scheduled_exception()); \ 142 ScheduledErrorThrower(
i::Isolate* isolate,
const char* context)
145 ~ScheduledErrorThrower();
148 ScheduledErrorThrower::~ScheduledErrorThrower() {
150 DCHECK(!isolate()->has_scheduled_exception() ||
151 !isolate()->has_pending_exception());
153 if (isolate()->has_scheduled_exception()) {
155 }
else if (isolate()->has_pending_exception()) {
157 isolate()->OptionalRescheduleException(
false);
158 }
else if (error()) {
159 isolate()->ScheduleThrow(*Reify());
164 return isolate->factory()->NewStringFromAsciiChecked(str);
166 Local<String> v8_str(Isolate* isolate,
const char* str) {
167 return Utils::ToLocal(v8_str(reinterpret_cast<i::Isolate*>(isolate), str));
173 if (!arg0->IsWasmModuleObject()) {
174 thrower->TypeError(
"Argument 0 must be a WebAssembly.Module");
180 v8::Utils::OpenHandle(*module_obj));
183 i::wasm::ModuleWireBytes GetFirstArgumentAsBytes(
186 const uint8_t* start =
nullptr;
189 if (source->IsArrayBuffer()) {
192 ArrayBuffer::Contents contents = buffer->GetContents();
194 start =
reinterpret_cast<const uint8_t*
>(contents.Data());
195 length = contents.ByteLength();
196 *is_shared = buffer->IsSharedArrayBuffer();
197 }
else if (source->IsTypedArray()) {
200 Local<ArrayBuffer> buffer = array->Buffer();
202 ArrayBuffer::Contents contents = buffer->GetContents();
205 reinterpret_cast<const uint8_t*
>(contents.Data()) + array->ByteOffset();
206 length = array->ByteLength();
207 *is_shared = buffer->IsSharedArrayBuffer();
209 thrower->TypeError(
"Argument 0 must be a buffer source");
211 DCHECK_IMPLIES(length, start !=
nullptr);
213 thrower->CompileError(
"BufferSource argument is empty");
215 if (length > i::wasm::kV8MaxWasmModuleSize) {
216 thrower->RangeError(
"buffer source exceeds maximum size of %zu (is %zu)",
217 i::wasm::kV8MaxWasmModuleSize, length);
219 if (thrower->error())
return i::wasm::ModuleWireBytes(
nullptr,
nullptr);
220 return i::wasm::ModuleWireBytes(start, start + length);
225 if (arg->IsUndefined())
return {};
227 if (!arg->IsObject()) {
228 thrower->TypeError(
"Argument 1 must be an object");
238 class AsyncCompilationResolver :
public i::wasm::CompilationResultResolver {
241 : promise_(isolate->global_handles()->Create(*promise)) {}
243 ~AsyncCompilationResolver()
override {
244 i::GlobalHandles::Destroy(promise_.location());
248 if (finished_)
return;
251 i::JSPromise::Resolve(promise_, result);
252 CHECK_EQ(promise_result.is_null(),
253 promise_->GetIsolate()->has_pending_exception());
257 if (finished_)
return;
260 i::JSPromise::Reject(promise_, error_reason);
261 CHECK_EQ(promise_result.is_null(),
262 promise_->GetIsolate()->has_pending_exception());
266 bool finished_ =
false;
272 class InstantiateModuleResultResolver
273 :
public i::wasm::InstantiationResultResolver {
275 InstantiateModuleResultResolver(
i::Isolate* isolate,
277 : promise_(isolate->global_handles()->Create(*promise)) {}
279 ~InstantiateModuleResultResolver()
override {
280 i::GlobalHandles::Destroy(promise_.location());
283 void OnInstantiationSucceeded(
286 i::JSPromise::Resolve(promise_, instance);
287 CHECK_EQ(promise_result.is_null(),
288 promise_->GetIsolate()->has_pending_exception());
293 i::JSPromise::Reject(promise_, error_reason);
294 CHECK_EQ(promise_result.is_null(),
295 promise_->GetIsolate()->has_pending_exception());
305 class InstantiateBytesResultResolver
306 :
public i::wasm::InstantiationResultResolver {
308 InstantiateBytesResultResolver(
i::Isolate* isolate,
312 promise_(isolate_->global_handles()->Create(*promise)),
313 module_(isolate_->global_handles()->Create(*module)) {}
315 ~InstantiateBytesResultResolver()
override {
316 i::GlobalHandles::Destroy(promise_.location());
317 i::GlobalHandles::Destroy(module_.location());
320 void OnInstantiationSucceeded(
325 isolate_->factory()->NewJSObject(isolate_->object_function());
327 const uint8_t* instance_str =
reinterpret_cast<const uint8_t*
>(
"instance");
332 i::StrLength(reinterpret_cast<const char*>(instance_str))))
335 const uint8_t* module_str =
reinterpret_cast<const uint8_t*
>(
"module");
340 i::StrLength(reinterpret_cast<const char*>(module_str))))
343 i::JSObject::AddProperty(isolate_, result, instance_name, instance,
345 i::JSObject::AddProperty(isolate_, result, module_name, module_, i::NONE);
348 i::JSPromise::Resolve(promise_, result);
349 CHECK_EQ(promise_result.is_null(), isolate_->has_pending_exception());
354 i::JSPromise::Reject(promise_, error_reason);
355 CHECK_EQ(promise_result.is_null(), isolate_->has_pending_exception());
367 class AsyncInstantiateCompileResultResolver
368 :
public i::wasm::CompilationResultResolver {
370 AsyncInstantiateCompileResultResolver(
374 promise_(isolate_->global_handles()->Create(*promise)),
375 maybe_imports_(maybe_imports.is_null()
377 : isolate_->global_handles()->Create(
378 *maybe_imports.ToHandleChecked())) {}
380 ~AsyncInstantiateCompileResultResolver()
override {
381 i::GlobalHandles::Destroy(promise_.location());
382 if (!maybe_imports_.is_null()) {
383 i::GlobalHandles::Destroy(maybe_imports_.ToHandleChecked().location());
388 if (finished_)
return;
390 isolate_->wasm_engine()->AsyncInstantiate(
392 base::make_unique<InstantiateBytesResultResolver>(isolate_, promise_,
394 result, maybe_imports_);
398 if (finished_)
return;
401 i::JSPromise::Reject(promise_, error_reason);
402 CHECK_EQ(promise_result.is_null(), isolate_->has_pending_exception());
406 bool finished_ =
false;
416 v8::Isolate* isolate = args.GetIsolate();
419 HandleScope scope(isolate);
420 ScheduledErrorThrower thrower(i_isolate,
"WebAssembly.compile()");
422 if (!i::wasm::IsWasmCodegenAllowed(i_isolate, i_isolate->native_context())) {
423 thrower.CompileError(
"Wasm code generation disallowed by embedder");
426 Local<Context> context = isolate->GetCurrentContext();
428 Local<Promise> promise = promise_resolver->GetPromise();
430 return_value.Set(promise);
432 std::shared_ptr<i::wasm::CompilationResultResolver> resolver(
433 new AsyncCompilationResolver(i_isolate, Utils::OpenHandle(*promise)));
435 bool is_shared =
false;
436 auto bytes = GetFirstArgumentAsBytes(args, &thrower, &is_shared);
437 if (thrower.error()) {
438 resolver->OnCompilationFailed(thrower.Reify());
442 auto enabled_features = i::wasm::WasmFeaturesFromIsolate(i_isolate);
443 i_isolate->wasm_engine()->AsyncCompile(i_isolate, enabled_features,
444 std::move(resolver), bytes, is_shared);
448 void WebAssemblyCompileStreaming(
450 v8::Isolate* isolate = args.GetIsolate();
452 HandleScope scope(isolate);
453 ScheduledErrorThrower thrower(i_isolate,
"WebAssembly.compile()");
454 Local<Context> context = isolate->GetCurrentContext();
458 Local<Promise> promise = result_resolver->GetPromise();
460 return_value.Set(promise);
463 auto resolver = std::make_shared<AsyncCompilationResolver>(
464 i_isolate, Utils::OpenHandle(*promise));
466 if (!i::wasm::IsWasmCodegenAllowed(i_isolate, i_isolate->native_context())) {
467 thrower.CompileError(
"Wasm code generation disallowed by embedder");
468 resolver->OnCompilationFailed(thrower.Reify());
477 base::make_unique<WasmStreaming::WasmStreamingImpl>(isolate,
480 DCHECK_NOT_NULL(i_isolate->wasm_streaming_callback());
493 if (!input_resolver->Resolve(context, args[0]).IsJust())
return;
498 USE(input_resolver->GetPromise()->Then(context, compile_callback));
503 v8::Isolate* isolate = args.GetIsolate();
505 HandleScope scope(isolate);
506 ScheduledErrorThrower thrower(i_isolate,
"WebAssembly.validate()");
508 bool is_shared =
false;
509 auto bytes = GetFirstArgumentAsBytes(args, &thrower, &is_shared);
513 if (thrower.error()) {
514 if (thrower.wasm_error()) thrower.Reset();
515 return_value.Set(v8::False(isolate));
519 auto enabled_features = i::wasm::WasmFeaturesFromIsolate(i_isolate);
520 bool validated =
false;
523 std::unique_ptr<uint8_t[]> copy(
new uint8_t[bytes.length()]);
524 memcpy(copy.get(), bytes.start(), bytes.length());
525 i::wasm::ModuleWireBytes bytes_copy(copy.get(),
526 copy.get() + bytes.length());
527 validated = i_isolate->wasm_engine()->SyncValidate(
528 i_isolate, enabled_features, bytes_copy);
531 validated = i_isolate->wasm_engine()->SyncValidate(i_isolate,
532 enabled_features, bytes);
535 return_value.Set(Boolean::New(isolate, validated));
540 v8::Isolate* isolate = args.GetIsolate();
542 if (i_isolate->wasm_module_callback()(args))
return;
544 HandleScope scope(isolate);
545 ScheduledErrorThrower thrower(i_isolate,
"WebAssembly.Module()");
547 if (!args.IsConstructCall()) {
548 thrower.TypeError(
"WebAssembly.Module must be invoked with 'new'");
551 if (!i::wasm::IsWasmCodegenAllowed(i_isolate, i_isolate->native_context())) {
552 thrower.CompileError(
"Wasm code generation disallowed by embedder");
556 bool is_shared =
false;
557 auto bytes = GetFirstArgumentAsBytes(args, &thrower, &is_shared);
559 if (thrower.error()) {
562 auto enabled_features = i::wasm::WasmFeaturesFromIsolate(i_isolate);
566 std::unique_ptr<uint8_t[]> copy(
new uint8_t[bytes.length()]);
567 memcpy(copy.get(), bytes.start(), bytes.length());
568 i::wasm::ModuleWireBytes bytes_copy(copy.get(),
569 copy.get() + bytes.length());
570 module_obj = i_isolate->wasm_engine()->SyncCompile(
571 i_isolate, enabled_features, &thrower, bytes_copy);
574 module_obj = i_isolate->wasm_engine()->SyncCompile(
575 i_isolate, enabled_features, &thrower, bytes);
578 if (module_obj.is_null())
return;
581 return_value.Set(Utils::ToLocal(module_obj.ToHandleChecked()));
586 HandleScope scope(args.GetIsolate());
587 v8::Isolate* isolate = args.GetIsolate();
589 ScheduledErrorThrower thrower(i_isolate,
"WebAssembly.Module.imports()");
591 auto maybe_module = GetFirstArgumentAsModule(args, &thrower);
592 if (thrower.error())
return;
593 auto imports = i::wasm::GetImports(i_isolate, maybe_module.ToHandleChecked());
594 args.GetReturnValue().Set(Utils::ToLocal(imports));
599 HandleScope scope(args.GetIsolate());
600 v8::Isolate* isolate = args.GetIsolate();
602 ScheduledErrorThrower thrower(i_isolate,
"WebAssembly.Module.exports()");
604 auto maybe_module = GetFirstArgumentAsModule(args, &thrower);
605 if (thrower.error())
return;
606 auto exports = i::wasm::GetExports(i_isolate, maybe_module.ToHandleChecked());
607 args.GetReturnValue().Set(Utils::ToLocal(exports));
611 void WebAssemblyModuleCustomSections(
613 HandleScope scope(args.GetIsolate());
614 v8::Isolate* isolate = args.GetIsolate();
616 ScheduledErrorThrower thrower(i_isolate,
617 "WebAssembly.Module.customSections()");
619 auto maybe_module = GetFirstArgumentAsModule(args, &thrower);
620 if (thrower.error())
return;
623 i::Object::ToString(i_isolate, Utils::OpenHandle(*args[1]));
625 if (!maybe_name.ToHandle(&name))
return;
626 auto custom_sections =
627 i::wasm::GetCustomSections(i_isolate, maybe_module.ToHandleChecked(),
629 if (thrower.error())
return;
630 args.GetReturnValue().Set(Utils::ToLocal(custom_sections));
633 MaybeLocal<Value> WebAssemblyInstantiateImpl(Isolate* isolate,
640 ScheduledErrorThrower thrower(i_isolate,
"WebAssembly Instantiation");
645 if (!module_obj->IsWasmModuleObject()) {
646 thrower.TypeError(
"Argument 0 must be a WebAssembly.Module object");
651 GetValueAsImports(ffi, &thrower);
652 if (thrower.error())
return {};
654 instance_object = i_isolate->wasm_engine()->SyncInstantiate(
659 DCHECK_EQ(instance_object.is_null(), i_isolate->has_scheduled_exception());
660 if (instance_object.is_null())
return {};
661 return Utils::ToLocal(instance_object.ToHandleChecked());
666 Isolate* isolate = args.GetIsolate();
668 i_isolate->CountUsage(
669 v8::Isolate::UseCounterFeature::kWebAssemblyInstantiation);
671 HandleScope scope(args.GetIsolate());
672 if (i_isolate->wasm_instance_callback()(args))
return;
674 ScheduledErrorThrower thrower(i_isolate,
"WebAssembly.Instance()");
675 if (!args.IsConstructCall()) {
676 thrower.TypeError(
"WebAssembly.Instance must be invoked with 'new'");
680 GetFirstArgumentAsModule(args, &thrower);
681 if (thrower.error())
return;
685 Local<Value> data = args[1];
687 Local<Value> instance;
688 if (WebAssemblyInstantiateImpl(isolate, args[0], data).ToLocal(&instance)) {
689 args.GetReturnValue().Set(instance);
693 void WebAssemblyInstantiateStreaming(
695 v8::Isolate* isolate = args.GetIsolate();
697 i_isolate->CountUsage(
698 v8::Isolate::UseCounterFeature::kWebAssemblyInstantiation);
700 HandleScope scope(isolate);
701 Local<Context> context = isolate->GetCurrentContext();
702 ScheduledErrorThrower thrower(i_isolate,
703 "WebAssembly.instantiateStreaming()");
707 Local<Promise> promise = result_resolver->GetPromise();
709 return_value.Set(promise);
713 std::unique_ptr<i::wasm::InstantiationResultResolver> resolver(
714 new InstantiateModuleResultResolver(i_isolate,
715 Utils::OpenHandle(*promise)));
717 if (!i::wasm::IsWasmCodegenAllowed(i_isolate, i_isolate->native_context())) {
718 thrower.CompileError(
"Wasm code generation disallowed by embedder");
719 resolver->OnInstantiationFailed(thrower.Reify());
724 Local<Value> ffi = args[1];
726 GetValueAsImports(ffi, &thrower);
728 if (thrower.error()) {
729 resolver->OnInstantiationFailed(thrower.Reify());
737 std::shared_ptr<i::wasm::CompilationResultResolver> compilation_resolver(
738 new AsyncInstantiateCompileResultResolver(
739 i_isolate, Utils::OpenHandle(*promise), maybe_imports));
746 base::make_unique<WasmStreaming::WasmStreamingImpl>(
747 isolate, compilation_resolver));
749 DCHECK_NOT_NULL(i_isolate->wasm_streaming_callback());
762 if (!input_resolver->Resolve(context, args[0]).IsJust())
return;
767 USE(input_resolver->GetPromise()->Then(context, compile_callback));
774 v8::Isolate* isolate = args.GetIsolate();
776 i_isolate->CountUsage(
777 v8::Isolate::UseCounterFeature::kWebAssemblyInstantiation);
779 ScheduledErrorThrower thrower(i_isolate,
"WebAssembly Instantiation");
781 HandleScope scope(isolate);
783 Local<Context> context = isolate->GetCurrentContext();
786 Local<Promise> promise = promise_resolver->GetPromise();
787 args.GetReturnValue().Set(promise);
789 std::unique_ptr<i::wasm::InstantiationResultResolver> resolver(
790 new InstantiateModuleResultResolver(i_isolate,
791 Utils::OpenHandle(*promise)));
793 Local<Value> first_arg_value = args[0];
795 if (!first_arg->IsJSObject()) {
797 "Argument 0 must be a buffer source or a WebAssembly.Module object");
798 resolver->OnInstantiationFailed(thrower.Reify());
803 Local<Value> ffi = args[1];
805 GetValueAsImports(ffi, &thrower);
807 if (thrower.error()) {
808 resolver->OnInstantiationFailed(thrower.Reify());
812 if (first_arg->IsWasmModuleObject()) {
816 i_isolate->wasm_engine()->AsyncInstantiate(i_isolate, std::move(resolver),
817 module_obj, maybe_imports);
821 bool is_shared =
false;
822 auto bytes = GetFirstArgumentAsBytes(args, &thrower, &is_shared);
823 if (thrower.error()) {
824 resolver->OnInstantiationFailed(thrower.Reify());
832 std::shared_ptr<i::wasm::CompilationResultResolver> compilation_resolver(
833 new AsyncInstantiateCompileResultResolver(
834 i_isolate, Utils::OpenHandle(*promise), maybe_imports));
838 if (!i::wasm::IsWasmCodegenAllowed(i_isolate, i_isolate->native_context())) {
839 thrower.CompileError(
"Wasm code generation disallowed by embedder");
840 compilation_resolver->OnCompilationFailed(thrower.Reify());
845 auto enabled_features = i::wasm::WasmFeaturesFromIsolate(i_isolate);
846 i_isolate->wasm_engine()->AsyncCompile(i_isolate, enabled_features,
847 std::move(compilation_resolver), bytes,
851 bool GetIntegerProperty(v8::Isolate* isolate,
ErrorThrower* thrower,
852 Local<Context> context, Local<v8::Object>
object,
853 Local<String> property,
int64_t* result,
854 int64_t lower_bound, uint64_t upper_bound) {
859 if (!value->IntegerValue(context).To(&number))
return false;
860 if (number < lower_bound) {
861 thrower->RangeError(
"Property value %" PRId64
862 " is below the lower bound %" PRIx64,
863 number, lower_bound);
866 if (number > static_cast<int64_t>(upper_bound)) {
867 thrower->RangeError(
"Property value %" PRId64
868 " is above the upper bound %" PRIu64,
869 number, upper_bound);
872 *result =
static_cast<int>(number);
880 v8::Isolate* isolate = args.GetIsolate();
882 HandleScope scope(isolate);
883 ScheduledErrorThrower thrower(i_isolate,
"WebAssembly.Module()");
884 if (!args.IsConstructCall()) {
885 thrower.TypeError(
"WebAssembly.Table must be invoked with 'new'");
888 if (!args[0]->IsObject()) {
889 thrower.TypeError(
"Argument 0 must be a table descriptor");
892 Local<Context> context = isolate->GetCurrentContext();
897 descriptor->Get(context, v8_str(isolate,
"element"));
899 if (!maybe.
ToLocal(&value))
return;
901 if (!value->ToString(context).ToLocal(&
string))
return;
902 if (!string->
StringEquals(v8_str(isolate,
"anyfunc"))) {
903 thrower.TypeError(
"Descriptor property 'element' must be 'anyfunc'");
909 if (!GetIntegerProperty(isolate, &thrower, context, descriptor,
910 v8_str(isolate,
"initial"), &initial, 0,
911 i::FLAG_wasm_max_table_size)) {
916 Local<String> maximum_key = v8_str(isolate,
"maximum");
917 Maybe<bool> has_maximum = descriptor->Has(context, maximum_key);
919 if (!has_maximum.IsNothing() && has_maximum.FromJust()) {
920 if (!GetIntegerProperty(isolate, &thrower, context, descriptor, maximum_key,
922 i::wasm::kSpecMaxWasmTableSize)) {
929 i_isolate, static_cast<uint32_t>(initial), maximum, &fixed_array);
931 return_value.Set(Utils::ToLocal(table_obj));
935 v8::Isolate* isolate = args.GetIsolate();
937 HandleScope scope(isolate);
938 ScheduledErrorThrower thrower(i_isolate,
"WebAssembly.Memory()");
939 if (!args.IsConstructCall()) {
940 thrower.TypeError(
"WebAssembly.Memory must be invoked with 'new'");
943 if (!args[0]->IsObject()) {
944 thrower.TypeError(
"Argument 0 must be a memory descriptor");
947 Local<Context> context = isolate->GetCurrentContext();
951 if (!GetIntegerProperty(isolate, &thrower, context, descriptor,
952 v8_str(isolate,
"initial"), &initial, 0,
953 i::wasm::max_mem_pages())) {
958 Local<String> maximum_key = v8_str(isolate,
"maximum");
959 Maybe<bool> has_maximum = descriptor->Has(context, maximum_key);
961 if (!has_maximum.IsNothing() && has_maximum.FromJust()) {
962 if (!GetIntegerProperty(isolate, &thrower, context, descriptor, maximum_key,
964 i::wasm::kSpecMaxWasmMemoryPages)) {
969 bool is_shared_memory =
false;
970 auto enabled_features = i::wasm::WasmFeaturesFromIsolate(i_isolate);
971 if (enabled_features.threads) {
973 Local<String> shared_key = v8_str(isolate,
"shared");
974 Maybe<bool> has_shared = descriptor->Has(context, shared_key);
975 if (!has_shared.IsNothing() && has_shared.FromJust()) {
979 is_shared_memory = value->BooleanValue(isolate);
983 if (is_shared_memory && maximum == -1) {
985 "If shared is true, maximum property should be defined.");
989 i::SharedFlag shared_flag =
990 is_shared_memory ? i::SharedFlag::kShared : i::SharedFlag::kNotShared;
992 size_t size =
static_cast<size_t>(i::wasm::kWasmPageSize) *
993 static_cast<size_t>(initial);
994 if (!i::wasm::NewArrayBuffer(i_isolate, size, shared_flag)
995 .ToHandle(&buffer)) {
996 thrower.RangeError(
"could not allocate memory");
999 if (buffer->is_shared()) {
1000 Maybe<bool> result =
1001 buffer->SetIntegrityLevel(buffer, i::FROZEN, i::kDontThrow);
1002 if (!result.FromJust()) {
1004 "Status of setting SetIntegrityLevel of buffer is false.");
1008 i_isolate, buffer, static_cast<int32_t>(maximum));
1009 args.GetReturnValue().Set(Utils::ToLocal(memory_obj));
1013 v8::Isolate* isolate = args.GetIsolate();
1015 HandleScope scope(isolate);
1016 ScheduledErrorThrower thrower(i_isolate,
"WebAssembly.Global()");
1017 if (!args.IsConstructCall()) {
1018 thrower.TypeError(
"WebAssembly.Global must be invoked with 'new'");
1021 if (!args[0]->IsObject()) {
1022 thrower.TypeError(
"Argument 0 must be a global descriptor");
1025 Local<Context> context = isolate->GetCurrentContext();
1029 bool is_mutable =
false;
1031 Local<String> mutable_key = v8_str(isolate,
"mutable");
1035 is_mutable = value->BooleanValue(isolate);
1042 i::wasm::ValueType
type;
1045 descriptor->Get(context, v8_str(isolate,
"value"));
1047 if (!maybe.
ToLocal(&value))
return;
1049 if (!value->ToString(context).ToLocal(&
string))
return;
1052 type = i::wasm::kWasmI32;
1053 }
else if (string->
StringEquals(v8_str(isolate,
"f32"))) {
1054 type = i::wasm::kWasmF32;
1055 }
else if (string->
StringEquals(v8_str(isolate,
"f64"))) {
1056 type = i::wasm::kWasmF64;
1059 "Descriptor property 'value' must be 'i32', 'f32', or 'f64'");
1067 type, offset, is_mutable);
1070 if (!maybe_global_obj.ToHandle(&global_obj)) {
1071 thrower.RangeError(
"could not allocate memory");
1078 case i::wasm::kWasmI32: {
1079 int32_t i32_value = 0;
1080 if (!value->IsUndefined()) {
1082 if (!value->ToInt32(context).ToLocal(&int32_value))
return;
1083 if (!int32_value->Int32Value(context).To(&i32_value))
return;
1085 global_obj->SetI32(i32_value);
1088 case i::wasm::kWasmF32: {
1089 float f32_value = 0;
1090 if (!value->IsUndefined()) {
1091 double f64_value = 0;
1093 if (!value->ToNumber(context).ToLocal(&number_value))
return;
1094 if (!number_value->NumberValue(context).To(&f64_value))
return;
1095 f32_value =
static_cast<float>(f64_value);
1097 global_obj->SetF32(f32_value);
1100 case i::wasm::kWasmF64: {
1101 double f64_value = 0;
1102 if (!value->IsUndefined()) {
1104 if (!value->ToNumber(context).ToLocal(&number_value))
return;
1105 if (!number_value->NumberValue(context).To(&f64_value))
return;
1107 global_obj->SetF64(f64_value);
1115 args.GetReturnValue().Set(Utils::ToLocal(global_js_object));
1120 v8::Isolate* isolate = args.GetIsolate();
1122 HandleScope scope(isolate);
1123 ScheduledErrorThrower thrower(i_isolate,
"WebAssembly.Excepion()");
1124 thrower.TypeError(
"WebAssembly.Exception cannot be called");
1127 constexpr
const char* kName_WasmGlobalObject =
"WebAssembly.Global";
1128 constexpr
const char* kName_WasmMemoryObject =
"WebAssembly.Memory";
1129 constexpr
const char* kName_WasmInstanceObject =
"WebAssembly.Instance";
1130 constexpr
const char* kName_WasmTableObject =
"WebAssembly.Table";
1132 #define EXTRACT_THIS(var, WasmType) \ 1133 i::Handle<i::WasmType> var; \ 1135 i::Handle<i::Object> this_arg = Utils::OpenHandle(*args.This()); \ 1136 if (!this_arg->Is##WasmType()) { \ 1137 thrower.TypeError("Receiver is not a %s", kName_##WasmType); \ 1140 var = i::Handle<i::WasmType>::cast(this_arg); \ 1143 void WebAssemblyInstanceGetExports(
1145 v8::Isolate* isolate = args.GetIsolate();
1147 HandleScope scope(isolate);
1148 ScheduledErrorThrower thrower(i_isolate,
"WebAssembly.Instance.exports()");
1149 EXTRACT_THIS(receiver, WasmInstanceObject);
1151 args.GetReturnValue().Set(Utils::ToLocal(exports_object));
1154 void WebAssemblyTableGetLength(
1156 v8::Isolate* isolate = args.GetIsolate();
1158 HandleScope scope(isolate);
1159 ScheduledErrorThrower thrower(i_isolate,
"WebAssembly.Table.length()");
1160 EXTRACT_THIS(receiver, WasmTableObject);
1161 args.GetReturnValue().Set(
1162 v8::Number::New(isolate, receiver->current_length()));
1167 v8::Isolate* isolate = args.GetIsolate();
1169 HandleScope scope(isolate);
1170 ScheduledErrorThrower thrower(i_isolate,
"WebAssembly.Table.grow()");
1171 Local<Context> context = isolate->GetCurrentContext();
1172 EXTRACT_THIS(receiver, WasmTableObject);
1175 if (!args[0]->IntegerValue(context).To(&grow_by))
return;
1177 int old_size = old_array->length();
1179 int64_t max_size64 = receiver->maximum_length()->Number();
1180 if (max_size64 < 0 || max_size64 > i::FLAG_wasm_max_table_size) {
1181 max_size64 = i::FLAG_wasm_max_table_size;
1184 if (grow_by < 0 || grow_by > max_size64 - old_size) {
1185 thrower.RangeError(grow_by < 0 ?
"trying to shrink table" 1186 :
"maximum table size exceeded");
1190 int new_size =
static_cast<int>(old_size + grow_by);
1191 receiver->Grow(i_isolate, static_cast<uint32_t>(new_size - old_size));
1193 if (new_size != old_size) {
1195 i_isolate->factory()->NewFixedArray(new_size);
1196 for (
int i = 0;
i < old_size; ++
i) new_array->set(
i, old_array->get(
i));
1198 for (
int i = old_size;
i < new_size; ++
i) new_array->set(
i, null);
1199 receiver->set_functions(*new_array);
1204 return_value.Set(old_size);
1209 v8::Isolate* isolate = args.GetIsolate();
1211 HandleScope scope(isolate);
1212 ScheduledErrorThrower thrower(i_isolate,
"WebAssembly.Table.get()");
1213 Local<Context> context = isolate->GetCurrentContext();
1214 EXTRACT_THIS(receiver, WasmTableObject);
1217 if (!args[0]->IntegerValue(context).To(&
i))
return;
1219 if (i < 0 || i >= array->length()) {
1220 thrower.RangeError(
"index out of bounds");
1225 return_value.Set(Utils::ToLocal(value));
1230 v8::Isolate* isolate = args.GetIsolate();
1232 HandleScope scope(isolate);
1233 ScheduledErrorThrower thrower(i_isolate,
"WebAssembly.Table.set()");
1234 Local<Context> context = isolate->GetCurrentContext();
1235 EXTRACT_THIS(receiver, WasmTableObject);
1239 if (!args[0]->IntegerValue(context).To(&index))
return;
1243 if (!value->IsNull(i_isolate) &&
1244 !i::WasmExportedFunction::IsWasmExportedFunction(*value)) {
1245 thrower.TypeError(
"Argument 1 must be null or a WebAssembly function");
1249 if (index < 0 || index >= receiver->functions()->length()) {
1250 thrower.RangeError(
"index out of bounds");
1254 i::WasmTableObject::Set(i_isolate, receiver, static_cast<int32_t>(index),
1255 value->IsNull(i_isolate)
1257 :
i::Handle<
i::JSFunction>::cast(value));
1262 v8::Isolate* isolate = args.GetIsolate();
1264 HandleScope scope(isolate);
1265 ScheduledErrorThrower thrower(i_isolate,
"WebAssembly.Memory.grow()");
1266 Local<Context> context = isolate->GetCurrentContext();
1267 EXTRACT_THIS(receiver, WasmMemoryObject);
1270 if (!args[0]->IntegerValue(context).To(&delta_size))
return;
1272 int64_t max_size64 = receiver->maximum_pages();
1273 if (max_size64 < 0 || max_size64 >
int64_t{i::wasm::max_mem_pages()}) {
1274 max_size64 = i::wasm::max_mem_pages();
1277 if (!old_buffer->is_growable()) {
1278 thrower.RangeError(
"This memory cannot be grown");
1281 int64_t old_size = old_buffer->byte_length() / i::wasm::kWasmPageSize;
1282 int64_t new_size64 = old_size + delta_size;
1283 if (delta_size < 0 || max_size64 < new_size64 || new_size64 < old_size) {
1284 thrower.RangeError(new_size64 < old_size ?
"trying to shrink memory" 1285 :
"maximum memory size exceeded");
1288 int32_t ret = i::WasmMemoryObject::Grow(i_isolate, receiver,
1289 static_cast<uint32_t>(delta_size));
1291 thrower.RangeError(
"Unable to grow instance memory.");
1295 return_value.Set(ret);
1299 void WebAssemblyMemoryGetBuffer(
1301 v8::Isolate* isolate = args.GetIsolate();
1303 HandleScope scope(isolate);
1304 ScheduledErrorThrower thrower(i_isolate,
"WebAssembly.Memory.buffer");
1305 EXTRACT_THIS(receiver, WasmMemoryObject);
1308 DCHECK(buffer_obj->IsJSArrayBuffer());
1311 if (buffer->is_shared()) {
1315 Maybe<bool> result =
1316 buffer->SetIntegrityLevel(buffer, i::FROZEN, i::kDontThrow);
1317 if (!result.FromJust()) {
1319 "Status of setting SetIntegrityLevel of buffer is false.");
1323 return_value.Set(Utils::ToLocal(buffer));
1326 void WebAssemblyGlobalGetValueCommon(
1328 v8::Isolate* isolate = args.GetIsolate();
1330 HandleScope scope(isolate);
1331 ScheduledErrorThrower thrower(i_isolate, name);
1332 EXTRACT_THIS(receiver, WasmGlobalObject);
1336 switch (receiver->type()) {
1337 case i::wasm::kWasmI32:
1338 return_value.Set(receiver->GetI32());
1340 case i::wasm::kWasmI64:
1341 thrower.TypeError(
"Can't get the value of i64 WebAssembly.Global");
1343 case i::wasm::kWasmF32:
1344 return_value.Set(receiver->GetF32());
1346 case i::wasm::kWasmF64:
1347 return_value.Set(receiver->GetF64());
1356 return WebAssemblyGlobalGetValueCommon(args,
"WebAssembly.Global.valueOf()");
1360 void WebAssemblyGlobalGetValue(
1362 return WebAssemblyGlobalGetValueCommon(args,
"get WebAssembly.Global.value");
1366 void WebAssemblyGlobalSetValue(
1368 v8::Isolate* isolate = args.GetIsolate();
1370 HandleScope scope(isolate);
1371 Local<Context> context = isolate->GetCurrentContext();
1372 ScheduledErrorThrower thrower(i_isolate,
"set WebAssembly.Global.value");
1373 EXTRACT_THIS(receiver, WasmGlobalObject);
1375 if (!receiver->is_mutable()) {
1376 thrower.TypeError(
"Can't set the value of an immutable global.");
1380 switch (receiver->type()) {
1381 case i::wasm::kWasmI32: {
1382 int32_t i32_value = 0;
1383 if (!args[0]->Int32Value(context).To(&i32_value))
return;
1384 receiver->SetI32(i32_value);
1387 case i::wasm::kWasmI64:
1388 thrower.TypeError(
"Can't set the value of i64 WebAssembly.Global");
1390 case i::wasm::kWasmF32: {
1391 double f64_value = 0;
1392 if (!args[0]->NumberValue(context).To(&f64_value))
return;
1393 receiver->SetF32(static_cast<float>(f64_value));
1396 case i::wasm::kWasmF64: {
1397 double f64_value = 0;
1398 if (!args[0]->NumberValue(context).To(&f64_value))
return;
1399 receiver->SetF64(f64_value);
1412 i::Isolate* i_isolate, FunctionCallback func) {
1413 Isolate* isolate =
reinterpret_cast<Isolate*
>(i_isolate);
1415 templ->ReadOnlyPrototype();
1416 return v8::Utils::OpenHandle(*templ);
1421 Isolate* isolate =
reinterpret_cast<Isolate*
>(i_isolate);
1423 return v8::Utils::OpenHandle(*templ);
1426 namespace internal {
1428 Handle<JSFunction> CreateFunc(Isolate* isolate, Handle<String> name,
1429 FunctionCallback func) {
1430 Handle<FunctionTemplateInfo> temp = NewFunctionTemplate(isolate, func);
1431 Handle<JSFunction>
function =
1432 ApiNatives::InstantiateFunction(temp, name).ToHandleChecked();
1433 DCHECK(function->shared()->HasSharedName());
1437 Handle<JSFunction> InstallFunc(Isolate* isolate, Handle<JSObject>
object,
1438 const char* str, FunctionCallback func,
1440 Handle<String> name = v8_str(isolate, str);
1441 Handle<JSFunction>
function = CreateFunc(isolate, name, func);
1442 function->shared()->set_length(length);
1443 PropertyAttributes attributes =
static_cast<PropertyAttributes
>(DONT_ENUM);
1444 JSObject::AddProperty(isolate,
object, name,
function, attributes);
1448 Handle<String> GetterName(Isolate* isolate, Handle<String> name) {
1449 return Name::ToFunctionName(isolate, name, isolate->factory()->get_string())
1453 void InstallGetter(Isolate* isolate, Handle<JSObject>
object,
1454 const char* str, FunctionCallback func) {
1455 Handle<String> name = v8_str(isolate, str);
1456 Handle<JSFunction>
function =
1457 CreateFunc(isolate, GetterName(isolate, name), func);
1461 Utils::ToLocal(
object)->SetAccessorProperty(Utils::ToLocal(name),
1462 Utils::ToLocal(
function),
1463 Local<Function>(), attributes);
1466 Handle<String> SetterName(Isolate* isolate, Handle<String> name) {
1467 return Name::ToFunctionName(isolate, name, isolate->factory()->set_string())
1471 void InstallGetterSetter(Isolate* isolate, Handle<JSObject>
object,
1472 const char* str, FunctionCallback getter,
1473 FunctionCallback setter) {
1474 Handle<String> name = v8_str(isolate, str);
1475 Handle<JSFunction> getter_func =
1476 CreateFunc(isolate, GetterName(isolate, name), getter);
1477 Handle<JSFunction> setter_func =
1478 CreateFunc(isolate, SetterName(isolate, name), setter);
1479 setter_func->shared()->set_length(1);
1484 Utils::ToLocal(
object)->SetAccessorProperty(
1485 Utils::ToLocal(name), Utils::ToLocal(getter_func),
1486 Utils::ToLocal(setter_func), attributes);
1493 void SetDummyInstanceTemplate(Isolate* isolate, Handle<JSFunction> fun) {
1494 Handle<ObjectTemplateInfo> instance_template = NewObjectTemplate(isolate);
1495 FunctionTemplateInfo::SetInstanceTemplate(
1496 isolate, handle(fun->shared()->get_api_func_data(), isolate),
1501 void WasmJs::Install(Isolate* isolate,
bool exposed_on_global_object) {
1502 Handle<JSGlobalObject> global = isolate->global_object();
1503 Handle<Context> context(global->native_context(), isolate);
1505 Object* prev = context->get(Context::WASM_MODULE_CONSTRUCTOR_INDEX);
1506 if (!prev->IsUndefined(isolate)) {
1507 DCHECK(prev->IsJSFunction());
1511 Factory* factory = isolate->factory();
1514 Handle<String> name = v8_str(isolate,
"WebAssembly");
1515 NewFunctionArgs args = NewFunctionArgs::ForFunctionWithoutCode(
1516 name, isolate->strict_function_map(), LanguageMode::kStrict);
1517 Handle<JSFunction> cons = factory->NewFunction(args);
1518 JSFunction::SetPrototype(cons, isolate->initial_object_prototype());
1519 Handle<JSObject> webassembly = factory->NewJSObject(cons, TENURED);
1520 PropertyAttributes attributes =
static_cast<PropertyAttributes
>(DONT_ENUM);
1522 PropertyAttributes ro_attributes =
1523 static_cast<PropertyAttributes
>(DONT_ENUM | READ_ONLY);
1524 JSObject::AddProperty(isolate, webassembly, factory->to_string_tag_symbol(),
1525 name, ro_attributes);
1526 InstallFunc(isolate, webassembly,
"compile", WebAssemblyCompile, 1);
1527 InstallFunc(isolate, webassembly,
"validate", WebAssemblyValidate, 1);
1528 InstallFunc(isolate, webassembly,
"instantiate", WebAssemblyInstantiate, 1);
1530 if (isolate->wasm_streaming_callback() !=
nullptr) {
1531 InstallFunc(isolate, webassembly,
"compileStreaming",
1532 WebAssemblyCompileStreaming, 1);
1533 InstallFunc(isolate, webassembly,
"instantiateStreaming",
1534 WebAssemblyInstantiateStreaming, 1);
1538 if (exposed_on_global_object) {
1539 JSObject::AddProperty(isolate, global, name, webassembly, attributes);
1543 Handle<JSFunction> module_constructor =
1544 InstallFunc(isolate, webassembly,
"Module", WebAssemblyModule, 1);
1545 context->set_wasm_module_constructor(*module_constructor);
1546 SetDummyInstanceTemplate(isolate, module_constructor);
1547 JSFunction::EnsureHasInitialMap(module_constructor);
1548 Handle<JSObject> module_proto(
1549 JSObject::cast(module_constructor->instance_prototype()), isolate);
1551 isolate->factory()->NewMap(i::WASM_MODULE_TYPE, WasmModuleObject::kSize);
1552 JSFunction::SetInitialMap(module_constructor, module_map, module_proto);
1553 InstallFunc(isolate, module_constructor,
"imports", WebAssemblyModuleImports,
1555 InstallFunc(isolate, module_constructor,
"exports", WebAssemblyModuleExports,
1557 InstallFunc(isolate, module_constructor,
"customSections",
1558 WebAssemblyModuleCustomSections, 2);
1559 JSObject::AddProperty(isolate, module_proto, factory->to_string_tag_symbol(),
1560 v8_str(isolate,
"WebAssembly.Module"), ro_attributes);
1563 Handle<JSFunction> instance_constructor =
1564 InstallFunc(isolate, webassembly,
"Instance", WebAssemblyInstance, 1);
1565 context->set_wasm_instance_constructor(*instance_constructor);
1566 SetDummyInstanceTemplate(isolate, instance_constructor);
1567 JSFunction::EnsureHasInitialMap(instance_constructor);
1568 Handle<JSObject> instance_proto(
1569 JSObject::cast(instance_constructor->instance_prototype()), isolate);
1571 i::WASM_INSTANCE_TYPE, WasmInstanceObject::kSize);
1572 JSFunction::SetInitialMap(instance_constructor, instance_map, instance_proto);
1573 InstallGetter(isolate, instance_proto,
"exports",
1574 WebAssemblyInstanceGetExports);
1575 JSObject::AddProperty(isolate, instance_proto,
1576 factory->to_string_tag_symbol(),
1577 v8_str(isolate,
"WebAssembly.Instance"), ro_attributes);
1580 Handle<JSFunction> table_constructor =
1581 InstallFunc(isolate, webassembly,
"Table", WebAssemblyTable, 1);
1582 context->set_wasm_table_constructor(*table_constructor);
1583 SetDummyInstanceTemplate(isolate, table_constructor);
1584 JSFunction::EnsureHasInitialMap(table_constructor);
1585 Handle<JSObject> table_proto(
1586 JSObject::cast(table_constructor->instance_prototype()), isolate);
1588 isolate->factory()->NewMap(i::WASM_TABLE_TYPE, WasmTableObject::kSize);
1589 JSFunction::SetInitialMap(table_constructor, table_map, table_proto);
1590 InstallGetter(isolate, table_proto,
"length", WebAssemblyTableGetLength);
1591 InstallFunc(isolate, table_proto,
"grow", WebAssemblyTableGrow, 1);
1592 InstallFunc(isolate, table_proto,
"get", WebAssemblyTableGet, 1);
1593 InstallFunc(isolate, table_proto,
"set", WebAssemblyTableSet, 2);
1594 JSObject::AddProperty(isolate, table_proto, factory->to_string_tag_symbol(),
1595 v8_str(isolate,
"WebAssembly.Table"), ro_attributes);
1598 Handle<JSFunction> memory_constructor =
1599 InstallFunc(isolate, webassembly,
"Memory", WebAssemblyMemory, 1);
1600 context->set_wasm_memory_constructor(*memory_constructor);
1601 SetDummyInstanceTemplate(isolate, memory_constructor);
1602 JSFunction::EnsureHasInitialMap(memory_constructor);
1603 Handle<JSObject> memory_proto(
1604 JSObject::cast(memory_constructor->instance_prototype()), isolate);
1606 isolate->factory()->NewMap(i::WASM_MEMORY_TYPE, WasmMemoryObject::kSize);
1607 JSFunction::SetInitialMap(memory_constructor, memory_map, memory_proto);
1608 InstallFunc(isolate, memory_proto,
"grow", WebAssemblyMemoryGrow, 1);
1609 InstallGetter(isolate, memory_proto,
"buffer", WebAssemblyMemoryGetBuffer);
1610 JSObject::AddProperty(isolate, memory_proto, factory->to_string_tag_symbol(),
1611 v8_str(isolate,
"WebAssembly.Memory"), ro_attributes);
1615 auto enabled_features = i::wasm::WasmFeaturesFromFlags();
1618 if (enabled_features.mut_global) {
1619 Handle<JSFunction> global_constructor =
1620 InstallFunc(isolate, webassembly,
"Global", WebAssemblyGlobal, 1);
1621 context->set_wasm_global_constructor(*global_constructor);
1622 SetDummyInstanceTemplate(isolate, global_constructor);
1623 JSFunction::EnsureHasInitialMap(global_constructor);
1624 Handle<JSObject> global_proto(
1625 JSObject::cast(global_constructor->instance_prototype()), isolate);
1627 i::WASM_GLOBAL_TYPE, WasmGlobalObject::kSize);
1628 JSFunction::SetInitialMap(global_constructor, global_map, global_proto);
1629 InstallFunc(isolate, global_proto,
"valueOf", WebAssemblyGlobalValueOf, 0);
1630 InstallGetterSetter(isolate, global_proto,
"value",
1631 WebAssemblyGlobalGetValue, WebAssemblyGlobalSetValue);
1632 JSObject::AddProperty(isolate, global_proto,
1633 factory->to_string_tag_symbol(),
1634 v8_str(isolate,
"WebAssembly.Global"), ro_attributes);
1638 if (enabled_features.eh) {
1639 Handle<JSFunction> exception_constructor =
1640 InstallFunc(isolate, webassembly,
"Exception", WebAssemblyException, 1);
1641 context->set_wasm_exception_constructor(*exception_constructor);
1642 SetDummyInstanceTemplate(isolate, exception_constructor);
1643 JSFunction::EnsureHasInitialMap(exception_constructor);
1644 Handle<JSObject> exception_proto(
1645 JSObject::cast(exception_constructor->instance_prototype()), isolate);
1647 i::WASM_EXCEPTION_TYPE, WasmExceptionObject::kSize);
1648 JSFunction::SetInitialMap(exception_constructor, exception_map,
1653 attributes =
static_cast<PropertyAttributes
>(DONT_ENUM);
1654 Handle<JSFunction> compile_error(
1655 isolate->native_context()->wasm_compile_error_function(), isolate);
1656 JSObject::AddProperty(isolate, webassembly,
1657 isolate->factory()->CompileError_string(),
1658 compile_error, attributes);
1659 Handle<JSFunction> link_error(
1660 isolate->native_context()->wasm_link_error_function(), isolate);
1661 JSObject::AddProperty(isolate, webassembly,
1662 isolate->factory()->LinkError_string(), link_error,
1664 Handle<JSFunction> runtime_error(
1665 isolate->native_context()->wasm_runtime_error_function(), isolate);
1666 JSObject::AddProperty(isolate, webassembly,
1667 isolate->factory()->RuntimeError_string(),
1668 runtime_error, attributes);
void SetModuleCompiledCallback(ModuleCompiledCallback callback, intptr_t data)
static V8_WARN_UNUSED_RESULT MaybeLocal< Resolver > New(Local< Context > context)
bool StringEquals(Local< String > str)
void OnBytesReceived(const uint8_t *bytes, size_t size)
static V8_INLINE Local< T > Cast(Local< S > that)
static MaybeLocal< Function > New(Local< Context > context, FunctionCallback callback, Local< Value > data=Local< Value >(), int length=0, ConstructorBehavior behavior=ConstructorBehavior::kAllow, SideEffectType side_effect_type=SideEffectType::kHasSideEffect)
static std::shared_ptr< WasmStreaming > Unpack(Isolate *isolate, Local< Value > value)
V8_WARN_UNUSED_RESULT V8_INLINE bool ToLocal(Local< S > *out) const
void(* ModuleCompiledCallback)(intptr_t data, Local< WasmCompiledModule > compiled_module)
static Local< ObjectTemplate > New(Isolate *isolate, Local< FunctionTemplate > constructor=Local< FunctionTemplate >())
V8_INLINE Local< T > ToLocalChecked()
static Local< FunctionTemplate > New(Isolate *isolate, FunctionCallback callback=nullptr, Local< Value > data=Local< Value >(), Local< Signature > signature=Local< Signature >(), int length=0, ConstructorBehavior behavior=ConstructorBehavior::kAllow, SideEffectType side_effect_type=SideEffectType::kHasSideEffect)
void Abort(MaybeLocal< Value > exception)
bool SetCompiledModuleBytes(const uint8_t *bytes, size_t size)