Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1479)

Unified Diff: src/wasm/wasm-js.cc

Issue 2384513002: [wasm] Implement WebAssembly.validate() (Closed)
Patch Set: Address review comments. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/wasm/wasm-module.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
« no previous file with comments | « no previous file | src/wasm/wasm-module.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698