Skip to content

Commit

Permalink
[wasm] Deleted old way of checking embedder limits on wasm size.
Browse files Browse the repository at this point in the history
BUG=v8:6027

Review-Url: https://codereview.chromium.org/2772203005
Cr-Commit-Position: refs/heads/master@{#44168}
  • Loading branch information
mtrofin authored and Commit bot committed Mar 28, 2017
1 parent 85cf24d commit 6226576
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 94 deletions.
23 changes: 1 addition & 22 deletions include/v8.h
Original file line number Diff line number Diff line change
Expand Up @@ -5994,20 +5994,6 @@ typedef void (*FailedAccessCheckCallback)(Local<Object> target,
typedef bool (*AllowCodeGenerationFromStringsCallback)(Local<Context> context);

// --- 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>&);

// --- Garbage Collection Callbacks ---
Expand Down Expand Up @@ -7244,15 +7230,8 @@ class V8_EXPORT Isolate {
AllowCodeGenerationFromStringsCallback callback);

/**
* Set the callback to invoke to check if wasm compilation from
* the specified object is allowed. By default, wasm compilation
* is allowed.
*
* Similar for instantiate.
* Embedder over{ride|load} injection points for wasm APIs.
*/
void SetAllowWasmCompileCallback(AllowWasmCompileCallback callback);
void SetAllowWasmInstantiateCallback(AllowWasmInstantiateCallback callback);

void SetWasmModuleCallback(ExtensionCallback callback);
void SetWasmCompileCallback(ExtensionCallback callback);
void SetWasmInstanceCallback(ExtensionCallback callback);
Expand Down
11 changes: 0 additions & 11 deletions src/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8724,17 +8724,6 @@ void Isolate::SetAllowCodeGenerationFromStringsCallback(
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) \
void Isolate::Set##ExternalName(Type callback) { \
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); \
Expand Down
2 changes: 0 additions & 2 deletions src/isolate.h
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,6 @@ typedef List<HeapObject*> DebugObjectCache;
V(OOMErrorCallback, oom_behavior, nullptr) \
V(LogEventCallback, event_logger, 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_instance_callback, &NoExtension) \
V(ExtensionCallback, wasm_compile_callback, &NoExtension) \
Expand Down
64 changes: 5 additions & 59 deletions src/wasm/wasm-js.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,50 +74,6 @@ i::MaybeHandle<i::WasmModuleObject> GetFirstArgumentAsModule(
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(
const v8::FunctionCallbackInfo<v8::Value>& args, ErrorThrower* thrower) {
if (args.Length() < 1) {
Expand Down Expand Up @@ -190,12 +146,11 @@ void WebAssemblyCompile(const v8::FunctionCallbackInfo<v8::Value>& args) {
return_value.Set(resolver->GetPromise());

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()));
CHECK(!maybe.IsNothing());
return;
}
DCHECK(!thrower.error());
i::Handle<i::JSPromise> promise = Utils::OpenHandle(*resolver->GetPromise());
i::wasm::AsyncCompile(i_isolate, promise, bytes);
}
Expand Down Expand Up @@ -230,9 +185,10 @@ void WebAssemblyModule(const v8::FunctionCallbackInfo<v8::Value>& args) {
ErrorThrower thrower(i_isolate, "WebAssembly.Module()");

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::wasm::SyncCompile(i_isolate, &thrower, bytes);
if (module_obj.is_null()) return;
Expand Down Expand Up @@ -309,11 +265,7 @@ void WebAssemblyInstance(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (thrower.error()) return;

auto maybe_imports = GetSecondArgumentAsImports(args, &thrower);
if (!IsInstantiationAllowed(i_isolate, &thrower, args[0], maybe_imports,
false)) {
return;
}
DCHECK(!thrower.error());
if (thrower.error()) return;

i::MaybeHandle<i::Object> instance_object = i::wasm::SyncInstantiate(
i_isolate, &thrower, maybe_module.ToHandleChecked(), maybe_imports,
Expand Down Expand Up @@ -366,12 +318,6 @@ void WebAssemblyInstantiate(const v8::FunctionCallbackInfo<v8::Value>& args) {
CHECK(!maybe.IsNothing());
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());
if (HasBrand(first_arg, i::Handle<i::Symbol>(i_context->wasm_module_sym()))) {
// WebAssembly.instantiate(module, imports) -> WebAssembly.Instance
Expand Down

0 comments on commit 6226576

Please sign in to comment.