| Index: src/wasm/wasm-js.cc
|
| diff --git a/src/wasm/wasm-js.cc b/src/wasm/wasm-js.cc
|
| index 92e0e2232bd42df8a3708311595d17a292335d42..254fd7061abf9363a390deec8a8b00d560d5f330 100644
|
| --- a/src/wasm/wasm-js.cc
|
| +++ b/src/wasm/wasm-js.cc
|
| @@ -197,6 +197,21 @@ static i::MaybeHandle<i::JSObject> CreateModuleObject(
|
| i::wasm::ModuleOrigin::kWasmOrigin);
|
| }
|
|
|
| +static bool ValidateModule(v8::Isolate* isolate,
|
| + const v8::Local<v8::Value> source,
|
| + ErrorThrower* thrower) {
|
| + i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
| + i::MaybeHandle<i::JSObject> nothing;
|
| +
|
| + RawBuffer buffer = GetRawBufferSource(source, thrower);
|
| + if (buffer.start == nullptr) return false;
|
| +
|
| + DCHECK(source->IsArrayBuffer() || source->IsTypedArray());
|
| + return i::wasm::ValidateModuleBytes(i_isolate, buffer.start, buffer.end,
|
| + thrower,
|
| + i::wasm::ModuleOrigin::kWasmOrigin);
|
| +}
|
| +
|
| bool BrandCheck(Isolate* isolate, i::Handle<i::Object> value,
|
| i::Handle<i::Symbol> sym, const char* msg) {
|
| if (value->IsJSObject()) {
|
| @@ -235,6 +250,25 @@ void WebAssemblyCompile(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
| return_value.Set(resolver->GetPromise());
|
| }
|
|
|
| +void WebAssemblyValidate(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
| + v8::Isolate* isolate = args.GetIsolate();
|
| + HandleScope scope(isolate);
|
| + ErrorThrower thrower(reinterpret_cast<i::Isolate*>(isolate),
|
| + "WebAssembly.validate()");
|
| +
|
| + if (args.Length() < 1) {
|
| + thrower.TypeError("Argument 0 must be a buffer source");
|
| + return;
|
| + }
|
| +
|
| + v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
|
| + if (ValidateModule(isolate, args[0], &thrower)) {
|
| + return_value.Set(v8::True(isolate));
|
| + } else {
|
| + return_value.Set(v8::False(isolate));
|
| + }
|
| +}
|
| +
|
| void WebAssemblyModule(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
| v8::Isolate* isolate = args.GetIsolate();
|
| HandleScope scope(isolate);
|
| @@ -578,6 +612,9 @@ void WasmJs::InstallWasmConstructors(Isolate* isolate,
|
| // Setup compile
|
| InstallFunc(isolate, wasm_object, "compile", WebAssemblyCompile);
|
|
|
| + // Setup compile
|
| + InstallFunc(isolate, wasm_object, "validate", WebAssemblyValidate);
|
| +
|
| // Setup Module
|
| Handle<JSFunction> module_constructor =
|
| InstallFunc(isolate, wasm_object, "Module", WebAssemblyModule);
|
|
|