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

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

Issue 2392943006: [wasm] Implement importing of WebAssembly.Memory. (Closed)
Patch Set: Address review comments Created 4 years, 2 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 | « src/wasm/wasm-js.h ('k') | src/wasm/wasm-module.cc » ('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 254fd7061abf9363a390deec8a8b00d560d5f330..57ee2654f9981e96d4b9a513d09689f5c60f590d 100644
--- a/src/wasm/wasm-js.cc
+++ b/src/wasm/wasm-js.cc
@@ -27,6 +27,8 @@ using v8::internal::wasm::ErrorThrower;
namespace v8 {
+static const int kWasmMemoryBufferFieldIndex = 0;
+
namespace {
i::Handle<i::String> v8_str(i::Isolate* isolate, const char* str) {
return isolate->factory()->NewStringFromAsciiChecked(str);
@@ -509,7 +511,8 @@ void WebAssemblyMemoryGetBuffer(
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
i::Handle<i::JSObject> receiver =
i::Handle<i::JSObject>::cast(Utils::OpenHandle(*args.This()));
- i::Handle<i::Object> buffer(receiver->GetInternalField(0), i_isolate);
+ i::Handle<i::Object> buffer(
+ receiver->GetInternalField(kWasmMemoryBufferFieldIndex), i_isolate);
DCHECK(buffer->IsJSArrayBuffer());
v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
return_value.Set(Utils::ToLocal(buffer));
@@ -523,7 +526,7 @@ i::Handle<i::JSObject> i::WasmJs::CreateWasmMemoryObject(
i_isolate->native_context()->wasm_memory_constructor());
i::Handle<i::JSObject> memory_obj =
i_isolate->factory()->NewJSObject(memory_ctor);
- memory_obj->SetInternalField(0, *buffer);
+ memory_obj->SetInternalField(kWasmMemoryBufferFieldIndex, *buffer);
memory_obj->SetInternalField(
1, has_maximum
? static_cast<i::Object*>(i::Smi::FromInt(maximum))
@@ -737,5 +740,24 @@ void WasmJs::InstallWasmMapsIfNeeded(Isolate* isolate,
}
}
+bool WasmJs::IsWasmMemoryObject(Isolate* isolate, Handle<Object> value) {
+ if (value->IsJSObject()) {
+ i::Handle<i::JSObject> object = i::Handle<i::JSObject>::cast(value);
+ i::Handle<i::Symbol> sym(isolate->context()->wasm_memory_sym(), isolate);
+ Maybe<bool> has_brand = i::JSObject::HasOwnProperty(object, sym);
+ if (has_brand.IsNothing()) return false;
+ if (has_brand.ToChecked()) return true;
+ }
+ return false;
+}
+
+Handle<JSArrayBuffer> WasmJs::GetWasmMemoryArrayBuffer(Isolate* isolate,
+ Handle<Object> value) {
+ DCHECK(IsWasmMemoryObject(isolate, value));
+ Handle<Object> buf(
+ JSObject::cast(*value)->GetInternalField(kWasmMemoryBufferFieldIndex),
+ isolate);
+ return Handle<JSArrayBuffer>::cast(buf);
+}
} // namespace internal
} // namespace v8
« no previous file with comments | « src/wasm/wasm-js.h ('k') | src/wasm/wasm-module.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698