Chromium Code Reviews| Index: src/wasm/wasm-js.cc |
| diff --git a/src/wasm/wasm-js.cc b/src/wasm/wasm-js.cc |
| index baec27d3cc5661af4d47b0a9bfc8d71c332c63ef..0cdb3987db5afb74cee8a45561f758502d6c7a67 100644 |
| --- a/src/wasm/wasm-js.cc |
| +++ b/src/wasm/wasm-js.cc |
| @@ -79,9 +79,17 @@ RawBuffer GetRawBufferSource( |
| static i::MaybeHandle<i::WasmModuleObject> CreateModuleObject( |
| v8::Isolate* isolate, const v8::Local<v8::Value> source, |
| - ErrorThrower* thrower) { |
| + ErrorThrower* thrower, bool async) { |
| i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| - i::MaybeHandle<i::JSObject> nothing; |
| + i::MaybeHandle<i::WasmModuleObject> nothing; |
| + |
| + AllowWasmCompileCallback callback = |
| + reinterpret_cast<i::Isolate*>(isolate)->allow_wasm_compile_callback(); |
| + if (callback != nullptr && !callback(source, async)) { |
| + thrower->RangeError( |
| + "Wasm compilation disallowed in this context for provided argument"); |
|
bradnelson
2017/02/18 00:28:42
How about:
Wasm compilation exceeds internal limit
Mircea Trofin
2017/02/18 00:41:47
Done.
|
| + return nothing; |
| + } |
| RawBuffer buffer = GetRawBufferSource(source, thrower); |
| if (buffer.start == nullptr) return i::MaybeHandle<i::WasmModuleObject>(); |
| @@ -139,7 +147,7 @@ void WebAssemblyCompile(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| return; |
| } |
| i::MaybeHandle<i::JSObject> module_obj = |
| - CreateModuleObject(isolate, args[0], &thrower); |
| + CreateModuleObject(isolate, args[0], &thrower, true); |
| if (thrower.error()) { |
| resolver->Reject(context, Utils::ToLocal(thrower.Reify())); |
| @@ -180,7 +188,7 @@ void WebAssemblyModule(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| } |
| i::MaybeHandle<i::JSObject> module_obj = |
| - CreateModuleObject(isolate, args[0], &thrower); |
| + CreateModuleObject(isolate, args[0], &thrower, false); |
| if (module_obj.is_null()) return; |
| v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); |
| @@ -189,7 +197,8 @@ void WebAssemblyModule(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| MaybeLocal<Value> InstantiateModuleImpl( |
| i::Isolate* i_isolate, i::Handle<i::WasmModuleObject> i_module_obj, |
| - const v8::FunctionCallbackInfo<v8::Value>& args, ErrorThrower* thrower) { |
| + const v8::FunctionCallbackInfo<v8::Value>& args, ErrorThrower* thrower, |
| + bool as_promise) { |
| // It so happens that in both the WebAssembly.instantiate, as well as |
| // WebAssembly.Instance ctor, the positions of the ffi object and memory |
| // are the same. If that changes later, we refactor the consts into |
| @@ -210,6 +219,16 @@ MaybeLocal<Value> InstantiateModuleImpl( |
| Local<Object> obj = Local<Object>::Cast(args[kFfiOffset]); |
| ffi = i::Handle<i::JSReceiver>::cast(v8::Utils::OpenHandle(*obj)); |
| } |
| + AllowWasmInstantiateCallback allow_instantiate = |
| + i_isolate->allow_wasm_instantiate_callback(); |
| + if (allow_instantiate != nullptr && |
| + !allow_instantiate(Local<WasmCompiledModule>::Cast(Utils::ToLocal( |
| + i::Handle<i::JSObject>::cast(i_module_obj))), |
| + Utils::ToLocal(ffi), as_promise)) { |
| + thrower->RangeError( |
| + "WebAssembly Instantiation is not permitted in this context"); |
|
bradnelson
2017/02/18 00:28:42
How about:
Wasm instantiation exceeds internal lim
Mircea Trofin
2017/02/18 00:41:47
Done.
|
| + return nothing; |
| + } |
| i::MaybeHandle<i::JSObject> instance = |
| i::wasm::WasmModule::Instantiate(i_isolate, thrower, i_module_obj, ffi); |
| @@ -316,7 +335,7 @@ void WebAssemblyInstance(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| if (!maybe_module.is_null()) { |
| MaybeLocal<Value> instance = InstantiateModuleImpl( |
| - i_isolate, maybe_module.ToHandleChecked(), args, &thrower); |
| + i_isolate, maybe_module.ToHandleChecked(), args, &thrower, false); |
| if (instance.IsEmpty()) { |
| DCHECK(thrower.error()); |
| @@ -361,7 +380,7 @@ void WebAssemblyInstantiate(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| i::Handle<i::WasmModuleObject> module_obj; |
| if (want_pair) { |
| i::MaybeHandle<i::WasmModuleObject> maybe_module_obj = |
| - CreateModuleObject(isolate, args[0], &thrower); |
| + CreateModuleObject(isolate, args[0], &thrower, true); |
| if (!maybe_module_obj.ToHandle(&module_obj)) { |
| DCHECK(thrower.error()); |
| resolver->Reject(context, Utils::ToLocal(thrower.Reify())); |
| @@ -372,7 +391,7 @@ void WebAssemblyInstantiate(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| } |
| DCHECK(!module_obj.is_null()); |
| MaybeLocal<Value> instance = |
| - InstantiateModuleImpl(i_isolate, module_obj, args, &thrower); |
| + InstantiateModuleImpl(i_isolate, module_obj, args, &thrower, true); |
| if (instance.IsEmpty()) { |
| DCHECK(thrower.error()); |
| resolver->Reject(context, Utils::ToLocal(thrower.Reify())); |