Commit 6226576e authored by mtrofin's avatar mtrofin Committed by Commit bot

[wasm] Deleted old way of checking embedder limits on wasm size.

BUG=v8:6027

Review-Url: https://codereview.chromium.org/2772203005
Cr-Commit-Position: refs/heads/master@{#44168}
parent 85cf24da
...@@ -5994,20 +5994,6 @@ typedef void (*FailedAccessCheckCallback)(Local<Object> target, ...@@ -5994,20 +5994,6 @@ typedef void (*FailedAccessCheckCallback)(Local<Object> target,
typedef bool (*AllowCodeGenerationFromStringsCallback)(Local<Context> context); typedef bool (*AllowCodeGenerationFromStringsCallback)(Local<Context> context);
// --- WASM compilation callbacks --- // --- WASM compilation callbacks ---
/**
* Callback to check if a buffer source may be compiled to WASM, given
* the compilation is attempted as a promise or not.
*/
typedef bool (*AllowWasmCompileCallback)(Isolate* isolate, Local<Value> source,
bool as_promise);
typedef bool (*AllowWasmInstantiateCallback)(Isolate* isolate,
Local<Value> module_or_bytes,
MaybeLocal<Value> ffi,
bool as_promise);
typedef bool (*ExtensionCallback)(const FunctionCallbackInfo<Value>&); typedef bool (*ExtensionCallback)(const FunctionCallbackInfo<Value>&);
// --- Garbage Collection Callbacks --- // --- Garbage Collection Callbacks ---
...@@ -7244,15 +7230,8 @@ class V8_EXPORT Isolate { ...@@ -7244,15 +7230,8 @@ class V8_EXPORT Isolate {
AllowCodeGenerationFromStringsCallback callback); AllowCodeGenerationFromStringsCallback callback);
/** /**
* Set the callback to invoke to check if wasm compilation from * Embedder over{ride|load} injection points for wasm APIs.
* the specified object is allowed. By default, wasm compilation
* is allowed.
*
* Similar for instantiate.
*/ */
void SetAllowWasmCompileCallback(AllowWasmCompileCallback callback);
void SetAllowWasmInstantiateCallback(AllowWasmInstantiateCallback callback);
void SetWasmModuleCallback(ExtensionCallback callback); void SetWasmModuleCallback(ExtensionCallback callback);
void SetWasmCompileCallback(ExtensionCallback callback); void SetWasmCompileCallback(ExtensionCallback callback);
void SetWasmInstanceCallback(ExtensionCallback callback); void SetWasmInstanceCallback(ExtensionCallback callback);
......
...@@ -8724,17 +8724,6 @@ void Isolate::SetAllowCodeGenerationFromStringsCallback( ...@@ -8724,17 +8724,6 @@ void Isolate::SetAllowCodeGenerationFromStringsCallback(
isolate->set_allow_code_gen_callback(callback); isolate->set_allow_code_gen_callback(callback);
} }
void Isolate::SetAllowWasmCompileCallback(AllowWasmCompileCallback callback) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
isolate->set_allow_wasm_compile_callback(callback);
}
void Isolate::SetAllowWasmInstantiateCallback(
AllowWasmInstantiateCallback callback) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
isolate->set_allow_wasm_instantiate_callback(callback);
}
#define CALLBACK_SETTER(ExternalName, Type, InternalName) \ #define CALLBACK_SETTER(ExternalName, Type, InternalName) \
void Isolate::Set##ExternalName(Type callback) { \ void Isolate::Set##ExternalName(Type callback) { \
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); \ i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); \
......
...@@ -395,8 +395,6 @@ typedef List<HeapObject*> DebugObjectCache; ...@@ -395,8 +395,6 @@ typedef List<HeapObject*> DebugObjectCache;
V(OOMErrorCallback, oom_behavior, nullptr) \ V(OOMErrorCallback, oom_behavior, nullptr) \
V(LogEventCallback, event_logger, nullptr) \ V(LogEventCallback, event_logger, nullptr) \
V(AllowCodeGenerationFromStringsCallback, allow_code_gen_callback, nullptr) \ V(AllowCodeGenerationFromStringsCallback, allow_code_gen_callback, nullptr) \
V(AllowWasmCompileCallback, allow_wasm_compile_callback, nullptr) \
V(AllowWasmInstantiateCallback, allow_wasm_instantiate_callback, nullptr) \
V(ExtensionCallback, wasm_module_callback, &NoExtension) \ V(ExtensionCallback, wasm_module_callback, &NoExtension) \
V(ExtensionCallback, wasm_instance_callback, &NoExtension) \ V(ExtensionCallback, wasm_instance_callback, &NoExtension) \
V(ExtensionCallback, wasm_compile_callback, &NoExtension) \ V(ExtensionCallback, wasm_compile_callback, &NoExtension) \
......
...@@ -74,50 +74,6 @@ i::MaybeHandle<i::WasmModuleObject> GetFirstArgumentAsModule( ...@@ -74,50 +74,6 @@ i::MaybeHandle<i::WasmModuleObject> GetFirstArgumentAsModule(
v8::Utils::OpenHandle(*module_obj)); v8::Utils::OpenHandle(*module_obj));
} }
bool IsCompilationAllowed(i::Isolate* isolate, ErrorThrower* thrower,
v8::Local<v8::Value> source, bool is_async) {
// Allow caller to do one final check on thrower state, rather than
// one at each step. No information is lost - failure reason is captured
// in the thrower state.
if (thrower->error()) return false;
AllowWasmCompileCallback callback = isolate->allow_wasm_compile_callback();
if (callback != nullptr &&
!callback(reinterpret_cast<v8::Isolate*>(isolate), source, is_async)) {
thrower->RangeError(
"%ssynchronous compilation disallowed due to module size limit set by "
"embedder",
is_async ? "a" : "");
return false;
}
return true;
}
bool IsInstantiationAllowed(i::Isolate* isolate, ErrorThrower* thrower,
v8::Local<v8::Value> module_or_bytes,
i::MaybeHandle<i::JSReceiver> ffi, bool is_async) {
// Allow caller to do one final check on thrower state, rather than
// one at each step. No information is lost - failure reason is captured
// in the thrower state.
if (thrower->error()) return false;
v8::MaybeLocal<v8::Value> v8_ffi;
if (!ffi.is_null()) {
v8_ffi = v8::Local<v8::Value>::Cast(Utils::ToLocal(ffi.ToHandleChecked()));
}
AllowWasmInstantiateCallback callback =
isolate->allow_wasm_instantiate_callback();
if (callback != nullptr &&
!callback(reinterpret_cast<v8::Isolate*>(isolate), module_or_bytes,
v8_ffi, is_async)) {
thrower->RangeError(
"%ssynchronous instantiation disallowed due to module size limit set "
"by embedder",
is_async ? "a" : "");
return false;
}
return true;
}
i::wasm::ModuleWireBytes GetFirstArgumentAsBytes( i::wasm::ModuleWireBytes GetFirstArgumentAsBytes(
const v8::FunctionCallbackInfo<v8::Value>& args, ErrorThrower* thrower) { const v8::FunctionCallbackInfo<v8::Value>& args, ErrorThrower* thrower) {
if (args.Length() < 1) { if (args.Length() < 1) {
...@@ -190,12 +146,11 @@ void WebAssemblyCompile(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -190,12 +146,11 @@ void WebAssemblyCompile(const v8::FunctionCallbackInfo<v8::Value>& args) {
return_value.Set(resolver->GetPromise()); return_value.Set(resolver->GetPromise());
auto bytes = GetFirstArgumentAsBytes(args, &thrower); auto bytes = GetFirstArgumentAsBytes(args, &thrower);
if (!IsCompilationAllowed(i_isolate, &thrower, args[0], true)) { if (thrower.error()) {
auto maybe = resolver->Reject(context, Utils::ToLocal(thrower.Reify())); auto maybe = resolver->Reject(context, Utils::ToLocal(thrower.Reify()));
CHECK(!maybe.IsNothing()); CHECK(!maybe.IsNothing());
return; return;
} }
DCHECK(!thrower.error());
i::Handle<i::JSPromise> promise = Utils::OpenHandle(*resolver->GetPromise()); i::Handle<i::JSPromise> promise = Utils::OpenHandle(*resolver->GetPromise());
i::wasm::AsyncCompile(i_isolate, promise, bytes); i::wasm::AsyncCompile(i_isolate, promise, bytes);
} }
...@@ -230,9 +185,10 @@ void WebAssemblyModule(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -230,9 +185,10 @@ void WebAssemblyModule(const v8::FunctionCallbackInfo<v8::Value>& args) {
ErrorThrower thrower(i_isolate, "WebAssembly.Module()"); ErrorThrower thrower(i_isolate, "WebAssembly.Module()");
auto bytes = GetFirstArgumentAsBytes(args, &thrower); auto bytes = GetFirstArgumentAsBytes(args, &thrower);
if (!IsCompilationAllowed(i_isolate, &thrower, args[0], false)) return;
DCHECK(!thrower.error()); if (thrower.error()) {
return;
}
i::MaybeHandle<i::Object> module_obj = i::MaybeHandle<i::Object> module_obj =
i::wasm::SyncCompile(i_isolate, &thrower, bytes); i::wasm::SyncCompile(i_isolate, &thrower, bytes);
if (module_obj.is_null()) return; if (module_obj.is_null()) return;
...@@ -309,11 +265,7 @@ void WebAssemblyInstance(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -309,11 +265,7 @@ void WebAssemblyInstance(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (thrower.error()) return; if (thrower.error()) return;
auto maybe_imports = GetSecondArgumentAsImports(args, &thrower); auto maybe_imports = GetSecondArgumentAsImports(args, &thrower);
if (!IsInstantiationAllowed(i_isolate, &thrower, args[0], maybe_imports, if (thrower.error()) return;
false)) {
return;
}
DCHECK(!thrower.error());
i::MaybeHandle<i::Object> instance_object = i::wasm::SyncInstantiate( i::MaybeHandle<i::Object> instance_object = i::wasm::SyncInstantiate(
i_isolate, &thrower, maybe_module.ToHandleChecked(), maybe_imports, i_isolate, &thrower, maybe_module.ToHandleChecked(), maybe_imports,
...@@ -366,12 +318,6 @@ void WebAssemblyInstantiate(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -366,12 +318,6 @@ void WebAssemblyInstantiate(const v8::FunctionCallbackInfo<v8::Value>& args) {
CHECK(!maybe.IsNothing()); CHECK(!maybe.IsNothing());
return; return;
} }
if (!IsInstantiationAllowed(i_isolate, &thrower, args[0], maybe_imports,
true)) {
auto maybe = resolver->Reject(context, Utils::ToLocal(thrower.Reify()));
CHECK(!maybe.IsNothing());
return;
}
i::Handle<i::JSPromise> promise = Utils::OpenHandle(*resolver->GetPromise()); i::Handle<i::JSPromise> promise = Utils::OpenHandle(*resolver->GetPromise());
if (HasBrand(first_arg, i::Handle<i::Symbol>(i_context->wasm_module_sym()))) { if (HasBrand(first_arg, i::Handle<i::Symbol>(i_context->wasm_module_sym()))) {
// WebAssembly.instantiate(module, imports) -> WebAssembly.Instance // WebAssembly.instantiate(module, imports) -> WebAssembly.Instance
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment