From 923674ab97219036f1319e2aa195e7d13d251f43 Mon Sep 17 00:00:00 2001 From: Ohad Rau Date: Mon, 29 Jul 2019 11:42:49 -0700 Subject: [PATCH 1/2] Add WASM + Embedder Builtins to V8 API --- deps/v8/BUILD.gn | 3 + deps/v8/include/v8-wasm.h | 123 ++++++++++ deps/v8/src/api/api-wasm.cc | 317 ++++++++++++++++++++++++++ deps/v8/src/api/api-wasm.h | 32 +++ deps/v8/src/compiler/wasm-compiler.cc | 24 +- deps/v8/src/compiler/wasm-compiler.h | 3 +- deps/v8/src/execution/isolate.h | 1 + deps/v8/src/wasm/c-api.cc | 8 +- deps/v8/src/wasm/wasm-feature-flags.h | 4 +- deps/v8/src/wasm/wasm-js.cc | 29 +++ 10 files changed, 535 insertions(+), 9 deletions(-) create mode 100644 deps/v8/include/v8-wasm.h create mode 100644 deps/v8/src/api/api-wasm.cc create mode 100644 deps/v8/src/api/api-wasm.h diff --git a/deps/v8/BUILD.gn b/deps/v8/BUILD.gn index 31b9d1776eb..fd9fe9d0a4c 100644 --- a/deps/v8/BUILD.gn +++ b/deps/v8/BUILD.gn @@ -1970,6 +1970,7 @@ v8_source_set("v8_base_without_compiler") { "include/v8-testing.h", "include/v8-util.h", "include/v8-wasm-trap-handler-posix.h", + "include/v8-wasm.h" "include/v8.h", "include/v8config.h", "src/api/api-arguments-inl.h", @@ -1977,6 +1978,8 @@ v8_source_set("v8_base_without_compiler") { "src/api/api-arguments.h", "src/api/api-natives.cc", "src/api/api-natives.h", + "src/api/api-wasm.cc", + "src/api/api-wasm.h", "src/api/api.cc", "src/api/api.h", "src/asmjs/asm-js.cc", diff --git a/deps/v8/include/v8-wasm.h b/deps/v8/include/v8-wasm.h new file mode 100644 index 00000000000..e2112b6d05c --- /dev/null +++ b/deps/v8/include/v8-wasm.h @@ -0,0 +1,123 @@ +// Copyright 2019 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef INCLUDE_V8_WASM_H_ +#define INCLUDE_V8_WASM_H_ + +#include +#include +#include +#include "v8.h" + +namespace v8 { +namespace wasm { + +#define PAGE_SIZE 0x10000 + +class V8_EXPORT Memory { + private: + size_t pages_; + uint8_t* data_; + public: + Memory(size_t pages, uint8_t* data); + Memory(const Memory& memory); + size_t size(); + size_t pages(); + uint8_t* data(); +}; + +class V8_EXPORT Table { + private: + void* tableObject_; + public: + Table(void* tableObject); + Table(const Table& table); + ~Table(); + MaybeLocal get(int index) const; +}; + +class V8_EXPORT Context { + public: + Context(Memory* memory, Table* table); + Context(Memory* memory, Table* table, v8::Isolate* isolate); + Context(const Context& context); + ~Context(); + Memory* memory; + Table* table; + v8::Isolate* isolate; +}; + +enum V8_EXPORT ValKind : uint8_t { + I32, + I64, + F32, + F64, + ANYREF = 128, + FUNCREF +}; + +// TODO(ohadrau): Should we enforce Ref ownership like the C API? +class V8_EXPORT Val { + private: + ValKind kind_; + union value { + int32_t i32; + int64_t i64; + float f32; + double f64; + void* ref; + } value_; + + Val(ValKind kind, value value); + + public: + Val(); + Val(Val&& val); + explicit Val(int32_t i); + explicit Val(int64_t i); + explicit Val(float i); + explicit Val(double i); + explicit Val(void* r); + + Val& operator=(Val&&); + + ValKind kind() const; + int32_t i32() const; + int64_t i64() const; + float f32() const; + double f64() const; + void* ref() const; +}; + +class V8_EXPORT FuncType { + private: + std::vector params_, results_; + public: + FuncType(std::vector params, std::vector results); + + std::vector params() const; + std::vector results() const; +}; + +class V8_EXPORT Func { + public: + using callbackType = void (*)(const Context*, const Val[], Val[]); + Func(const FuncType, callbackType); + + const FuncType type(); + callbackType callback(); + private: + const FuncType type_; + callbackType callback_; +}; + +void RegisterEmbedderBuiltin(Isolate* isolate, + const char* module_name, + const char* name, + Func import); + +} // namespace wasm +} // namespace v8 + +#endif // INCLUDE_V8_WASM_H_ diff --git a/deps/v8/src/api/api-wasm.cc b/deps/v8/src/api/api-wasm.cc new file mode 100644 index 00000000000..9947920a4bc --- /dev/null +++ b/deps/v8/src/api/api-wasm.cc @@ -0,0 +1,317 @@ +// Copyright 2019 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "src/api/api-wasm.h" +#include "src/base/memory.h" +#include "src/common/globals.h" +#include "src/api/api-inl.h" +#include "src/objects/contexts.h" +#include "src/objects/lookup.h" +#include "src/execution/isolate.h" + +#define IGNORE(X) ((void) (X)) + +namespace b = v8::base; +namespace i = v8::internal; + +namespace v8 { +namespace wasm { + +Memory::Memory(size_t pages, uint8_t* data) : pages_(pages), data_(data) {} +Memory::Memory(const Memory& memory) + : pages_(memory.pages_), data_(memory.data_) {} +size_t Memory::size() { return pages_ * PAGE_SIZE; } +size_t Memory::pages() { return pages_; } +uint8_t* Memory::data() { return data_; } + +Table::Table(void* tableObject) { + tableObject_ = (void*) new i::WasmTableObject( + *(i::WasmTableObject*) tableObject); +} +Table::Table(const Table& table) { + tableObject_ = (void*) new i::WasmTableObject( + *(i::WasmTableObject*) table.tableObject_); +} +Table::~Table() { delete tableObject_; } +MaybeLocal Table::get(int index) const { + i::Isolate* i_isolate = i::Isolate::TryGetCurrent(); + i::WasmTableObject* table = (i::WasmTableObject*) tableObject_; + i::Handle tableHandle = + i::Handle(*table, i_isolate); + i::Handle entry = + i::WasmTableObject::Get(i_isolate, tableHandle, index); + + // TODO(ohadrau): Assumes this is a FUNCREF table + if (i::WasmExportedFunction::IsWasmExportedFunction(*entry) || + i::WasmCapiFunction::IsWasmCapiFunction(*entry)) { + return Utils::ToLocal(i::Handle::cast(entry)); + } else { + return MaybeLocal(); + } +} + +Context::Context(Memory* memory, Table* table) + : isolate(Isolate::GetCurrent()), memory(memory), table(table) {} +Context::Context(Memory* memory, Table* table, Isolate* isolate) + : isolate(isolate), memory(memory), table(table) {} +Context::Context(const Context& context) + : isolate(context.isolate) { + this->memory = new Memory(*context.memory); + this->table = new Table(*context.table); +} +Context::~Context() { + delete this->memory; + delete this->table; +} + +Val::Val(ValKind kind, value value) : kind_(kind), value_(value) {} + +Val::Val() : kind_(ANYREF) { value_.ref = nullptr; } +Val::Val(Val&& val) : Val(val.kind_, val.value_) { +} + +Val::Val(int32_t i) : kind_(I32) { value_.i32 = i; } +Val::Val(int64_t i) : kind_(I64) { value_.i64 = i; } +Val::Val(float i) : kind_(F32) { value_.f32 = i; } +Val::Val(double i) : kind_(F64) { value_.f64 = i; } +Val::Val(void* r) : kind_(ANYREF) { value_.ref = r; } + +Val& Val::operator=(Val&& val) { + kind_ = val.kind_; + value_ = val.value_; + return *this; +} + +ValKind Val::kind() const { return kind_; } +int32_t Val::i32() const { assert(kind_ == I32); return value_.i32; } +int64_t Val::i64() const { assert(kind_ == I64); return value_.i64; } +float Val::f32() const { assert(kind_ == F32); return value_.f32; } +double Val::f64() const { assert(kind_ == F64); return value_.f64; } +void* Val::ref() const { + assert(kind_ == ANYREF || kind_ == FUNCREF); + return value_.ref; +} + +FuncType::FuncType( + std::vector params, std::vector results +) : params_(params), results_(results) {} + +std::vector FuncType::params() const { return params_; } +std::vector FuncType::results() const { return results_; } + +Func::Func(const FuncType funcType, callbackType cb) : + type_(funcType), + callback_(cb) {} + +const FuncType Func::type() { + return type_; +} + +Func::callbackType Func::callback() { + return callback_; +} + +i::wasm::ValueType valkind_to_v8(ValKind type) { + switch (type) { + case I32: + return i::wasm::kWasmI32; + case I64: + return i::wasm::kWasmI64; + case F32: + return i::wasm::kWasmF32; + case F64: + return i::wasm::kWasmF64; + default: + // TODO(wasm+): support new value types + UNREACHABLE(); + } +} + +// TODO(ohadrau): Clean up so that we're not maintaining 2 copies of this +// Use an invalid type as a marker separating params and results. +const i::wasm::ValueType kMarker = i::wasm::kWasmStmt; + +i::Handle> Serialize( + i::Isolate* isolate, const FuncType type) { + int sig_size = + static_cast(type.params().size() + type.results().size() + 1); + i::Handle> sig = + i::PodArray::New(isolate, sig_size, + i::AllocationType::kOld); + int index = 0; + // TODO(jkummerow): Consider making vec<> range-based for-iterable. + for (size_t i = 0; i < type.results().size(); i++) { + sig->set(index++, valkind_to_v8(type.results()[i])); + } + // {sig->set} needs to take the address of its second parameter, + // so we can't pass in the static const kMarker directly. + i::wasm::ValueType marker = kMarker; + sig->set(index++, marker); + for (size_t i = 0; i < type.params().size(); i++) { + sig->set(index++, valkind_to_v8(type.params()[i])); + } + return sig; +} + +FuncData::FuncData(i::Isolate* isolate, const FuncType type) + : isolate(isolate) { + param_count = type.params().size(); + result_count = type.results().size(); + serialized_sig = *Serialize(isolate, type); +} + +i::Address FuncData::v8_callback( + void* data, size_t memoryPages, uint8_t* memoryBase, + i::WasmTableObject table, i::Address argv +) { + FuncData* self = reinterpret_cast(data); + i::Isolate* isolate = self->isolate; + HandleScope scope(reinterpret_cast(isolate)); + + int num_param_types = self->param_count; + int num_result_types = self->result_count; + + std::unique_ptr params(new Val[num_param_types]); + std::unique_ptr results(new Val[num_result_types]); + i::Address p = argv; + for (int i = 0; i < num_param_types; ++i) { + switch (self->serialized_sig.get(i + num_result_types + 1)) { + case i::wasm::kWasmI32: + params[i] = Val(b::ReadUnalignedValue(p)); + p += 4; + break; + case i::wasm::kWasmI64: + params[i] = Val(b::ReadUnalignedValue(p)); + p += 8; + break; + case i::wasm::kWasmF32: + params[i] = Val(b::ReadUnalignedValue(p)); + p += 4; + break; + case i::wasm::kWasmF64: + params[i] = Val(b::ReadUnalignedValue(p)); + p += 8; + break; + case i::wasm::kWasmAnyRef: + case i::wasm::kWasmAnyFunc: { + i::Address raw = b::ReadUnalignedValue(p); + p += sizeof(raw); + if (raw == i::kNullAddress) { + params[i] = Val(nullptr); + } else { + i::JSReceiver raw_obj = i::JSReceiver::cast(i::Object(raw)); + i::Handle obj(raw_obj, raw_obj.GetIsolate()); + params[i] = Val(reinterpret_cast(obj->address())); + } + break; + } + } + } + + Memory* memory = new Memory(memoryPages, memoryBase); + Table* apiTable = new Table(&table); + const Context* context = new Context(memory, apiTable); + + self->callback(context, params.get(), results.get()); + + delete context; + + if (isolate->has_scheduled_exception()) { + isolate->PromoteScheduledException(); + } + if (isolate->has_pending_exception()) { + i::Object ex = isolate->pending_exception(); + isolate->clear_pending_exception(); + return ex.ptr(); + } + + p = argv; + for (int i = 0; i < num_result_types; ++i) { + switch (self->serialized_sig.get(i)) { + case i::wasm::kWasmI32: + b::WriteUnalignedValue(p, results[i].i32()); + p += 4; + break; + case i::wasm::kWasmI64: + b::WriteUnalignedValue(p, results[i].i64()); + p += 8; + break; + case i::wasm::kWasmF32: + b::WriteUnalignedValue(p, results[i].f32()); + p += 4; + break; + case i::wasm::kWasmF64: + b::WriteUnalignedValue(p, results[i].f64()); + p += 8; + break; + case i::wasm::kWasmAnyRef: + case i::wasm::kWasmAnyFunc: { + if (results[i].ref() == nullptr) { + b::WriteUnalignedValue(p, i::kNullAddress); + } else { + b::WriteUnalignedValue(p, results[i].ref()); + } + p += sizeof(i::Address); + break; + } + } + } + return i::kNullAddress; +} + +void RegisterEmbedderBuiltin(Isolate* isolate, + const char* module_name, + const char* name, + Func import) { + i::Isolate* i_isolate = reinterpret_cast(isolate); + i::HandleScope handle_scope(i_isolate); + + Eternal imports = i_isolate->wasm_native_imports(); + if (imports.IsEmpty()) { + i::Handle handle = + i_isolate->factory()->NewJSObject(i_isolate->object_function()); + Local local = + Utils::Convert(handle); + imports.Set(isolate, local); + } + + Local imports_local = imports.Get(isolate); + i::Handle imports_handle = + i::Handle(reinterpret_cast(*imports_local)); + + i::Handle module_str = + i_isolate->factory()->NewStringFromAsciiChecked(module_name); + i::Handle name_str = + i_isolate->factory()->NewStringFromAsciiChecked(name); + + i::Handle module_obj; + i::LookupIterator module_it(i_isolate, imports_handle, module_str, + i::LookupIterator::OWN_SKIP_INTERCEPTOR); + if (i::JSObject::HasProperty(&module_it).ToChecked()) { + module_obj = i::Handle::cast( + i::Object::GetProperty(&module_it).ToHandleChecked()); + } else { + module_obj = + i_isolate->factory()->NewJSObject(i_isolate->object_function()); + IGNORE(i::Object::SetProperty(i_isolate, imports_handle, + module_str, module_obj)); + } + + FuncData* data = new FuncData(i_isolate, import.type()); + data->callback = import.callback(); + i::Handle> serialized_sig( + data->serialized_sig, i_isolate); + i::Handle callback = + i::WasmCapiFunction::New( + i_isolate, reinterpret_cast(&FuncData::v8_callback), + data, serialized_sig); + IGNORE(i::Object::SetProperty(i_isolate, module_obj, name_str, callback)); + + i_isolate->set_wasm_native_imports(imports); +} + +} // namespace wasm +} // namespace v8 + +#undef IGNORE diff --git a/deps/v8/src/api/api-wasm.h b/deps/v8/src/api/api-wasm.h new file mode 100644 index 00000000000..a8708ff92ec --- /dev/null +++ b/deps/v8/src/api/api-wasm.h @@ -0,0 +1,32 @@ +// Copyright 2019 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef V8_API_API_WASM_H_ +#define V8_API_API_WASM_H_ + +#include "include/v8-wasm.h" +#include "src/objects/fixed-array.h" +#include "src/wasm/value-type.h" +#include "src/wasm/wasm-objects.h" + +namespace v8 { +namespace wasm { + +struct FuncData { + v8::internal::Isolate* isolate; + v8::internal::PodArray serialized_sig; + int param_count, result_count; + Func::callbackType callback; + + FuncData(v8::internal::Isolate* isolate, const FuncType type); + + static v8::internal::Address v8_callback( + void* data, size_t memoryPages, uint8_t* memoryBase, + i::WasmTableObject table, i::Address argv); +}; + +} // namespace wasm +} // namespace v8 + +#endif // V8_API_API_WASM_H_ diff --git a/deps/v8/src/compiler/wasm-compiler.cc b/deps/v8/src/compiler/wasm-compiler.cc index 0b212c9fb11..977d3a52c27 100644 --- a/deps/v8/src/compiler/wasm-compiler.cc +++ b/deps/v8/src/compiler/wasm-compiler.cc @@ -4827,7 +4827,6 @@ Node* WasmGraphBuilder::TableSize(uint32_t table_index) { table, wasm::ObjectAccess::ToTagged(WasmTableObject::kEntriesOffset), assert_size(storage_field_size, MachineType::TypeCompressedTaggedPointer())); - int length_field_size = FixedArray::kLengthOffsetEnd - FixedArray::kLengthOffset + 1; Node* table_size = @@ -5643,6 +5642,17 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { Control())); offset += wasm::ValueTypes::ElementSizeInBytes(type); } + + WasmInstanceCacheNodes instance_cache; + InitInstanceCache(&instance_cache); + + Node* memPages = instance_cache.mem_size; + Node* memBase = instance_cache.mem_start; + + Node* tables = + LOAD_INSTANCE_FIELD(Tables, MachineType::TypeCompressedTaggedPointer()); + Node* table = LOAD_FIXED_ARRAY_SLOT_ANY(tables, 0); + // The function is passed as the last parameter, after WASM arguments. Node* function_node = Param(param_count + 1); Node* shared = LOAD_RAW( @@ -5669,11 +5679,15 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { Node* function = graph()->NewNode(mcgraph()->common()->ExternalConstant(ref)); - // Parameters: void* data, Address arguments. + // Parameters: void* data, size_t memoryPages, uint8_t* memoryBase, + // i::WasmTableObject table, Address arguments. MachineType host_sig_types[] = { - MachineType::Pointer(), MachineType::Pointer(), MachineType::Pointer()}; - MachineSignature host_sig(1, 2, host_sig_types); - Node* return_value = BuildCCall(&host_sig, function, host_data, values); + MachineType::Pointer(), + MachineType::Pointer(), MachineType::Pointer(), MachineType::Pointer(), + MachineType::TypeCompressedTagged(), MachineType::Pointer()}; + MachineSignature host_sig(1, 5, host_sig_types); + Node* return_value = BuildCCall(&host_sig, function, host_data, + memPages, memBase, table, values); BuildModifyThreadInWasmFlag(true); diff --git a/deps/v8/src/compiler/wasm-compiler.h b/deps/v8/src/compiler/wasm-compiler.h index cf95596a021..14433e15b0d 100644 --- a/deps/v8/src/compiler/wasm-compiler.h +++ b/deps/v8/src/compiler/wasm-compiler.h @@ -122,7 +122,8 @@ V8_EXPORT_PRIVATE wasm::WasmCompilationResult CompileWasmImportCallWrapper( // Compiles a host call wrapper, which allows WASM to call host functions. wasm::WasmCode* CompileWasmCapiCallWrapper(wasm::WasmEngine*, wasm::NativeModule*, - wasm::FunctionSig*, Address address); + wasm::FunctionSig*, + Address address); // Returns an OptimizedCompilationJob object for a JS to Wasm wrapper. std::unique_ptr NewJSToWasmCompilationJob( diff --git a/deps/v8/src/execution/isolate.h b/deps/v8/src/execution/isolate.h index 92b82d0af3e..dcb834d010d 100644 --- a/deps/v8/src/execution/isolate.h +++ b/deps/v8/src/execution/isolate.h @@ -404,6 +404,7 @@ using DebugObjectCache = std::vector>; V(ExtensionCallback, wasm_instance_callback, &NoExtension) \ V(WasmStreamingCallback, wasm_streaming_callback, nullptr) \ V(WasmThreadsEnabledCallback, wasm_threads_enabled_callback, nullptr) \ + V(Eternal, wasm_native_imports, Eternal()) \ /* State for Relocatable. */ \ V(Relocatable*, relocatable_top, nullptr) \ V(DebugObjectCache*, string_stream_debug_object_cache, nullptr) \ diff --git a/deps/v8/src/wasm/c-api.cc b/deps/v8/src/wasm/c-api.cc index 83a4dc3e6a0..cf3c11380c7 100644 --- a/deps/v8/src/wasm/c-api.cc +++ b/deps/v8/src/wasm/c-api.cc @@ -1498,7 +1498,9 @@ struct FuncData { if (finalizer) (*finalizer)(env); } - static i::Address v8_callback(void* data, i::Address argv); + static i::Address v8_callback(void* data, size_t memoryPages, + uint8_t* memoryBase, i::WasmTableObject table, + i::Address argv); static void finalize_func_data(void* data); }; @@ -1801,7 +1803,9 @@ auto Func::call(const Val args[], Val results[]) const -> own { return nullptr; } -i::Address FuncData::v8_callback(void* data, i::Address argv) { +i::Address FuncData::v8_callback(void* data, size_t memoryPages, + uint8_t* memoryBase, i::WasmTableObject table, + i::Address argv) { FuncData* self = reinterpret_cast(data); const vec& param_types = self->type->params(); diff --git a/deps/v8/src/wasm/wasm-feature-flags.h b/deps/v8/src/wasm/wasm-feature-flags.h index 77d46fdc0d5..ab49ddebd5b 100644 --- a/deps/v8/src/wasm/wasm-feature-flags.h +++ b/deps/v8/src/wasm/wasm-feature-flags.h @@ -29,5 +29,7 @@ SEPARATOR \ V(type_reflection, "wasm type reflection in JS", false) \ SEPARATOR \ - V(compilation_hints, "compilation hints section", false) + V(compilation_hints, "compilation hints section", false) \ + SEPARATOR \ + V(embedderBuiltins, "wasm embedder builtin functions", true) #endif // V8_WASM_WASM_FEATURE_FLAGS_H_ diff --git a/deps/v8/src/wasm/wasm-js.cc b/deps/v8/src/wasm/wasm-js.cc index 7ab0ce558d2..ccda89d85b8 100644 --- a/deps/v8/src/wasm/wasm-js.cc +++ b/deps/v8/src/wasm/wasm-js.cc @@ -663,6 +663,29 @@ void WebAssemblyValidate(const v8::FunctionCallbackInfo& args) { return_value.Set(Boolean::New(isolate, validated)); } +// WebAssembly.embedderBuiltins() -> Object +void WebAssemblyEmbedderBuiltins( + const v8::FunctionCallbackInfo& args +) { + v8::Isolate* isolate = args.GetIsolate(); + i::Isolate* i_isolate = reinterpret_cast(isolate); + HandleScope scope(isolate); + + ScheduledErrorThrower thrower(i_isolate, "WebAssembly.embedderBuiltins()"); + /*v8::ReturnValue return_value = args.GetReturnValue(); + + Eternal imports = i_isolate->wasm_native_imports(); + Local result = imports.Get(isolate); + return_value.Set(Utils::ToLocal(result));*/ + + v8::ReturnValue return_value = args.GetReturnValue(); + Eternal imports = i_isolate->wasm_native_imports(); + Local result = imports.Get(isolate); + i::Handle real_result = + i::Handle(reinterpret_cast(*result)); + return_value.Set(Utils::ToLocal(real_result)); +} + // new WebAssembly.Module(bytes) -> WebAssembly.Module void WebAssemblyModule(const v8::FunctionCallbackInfo& args) { v8::Isolate* isolate = args.GetIsolate(); @@ -2268,6 +2291,12 @@ void WasmJs::Install(Isolate* isolate, bool exposed_on_global_object) { context->set_wasm_exported_function_map(*function_map); } + // Setup embedderBuiltins + if (enabled_features.embedderBuiltins) { + InstallFunc(isolate, webassembly, "embedderBuiltins", + WebAssemblyEmbedderBuiltins, 0); + } + // Setup errors Handle compile_error( isolate->native_context()->wasm_compile_error_function(), isolate); From a78983dfd1ac2b7616a8ab4e786037658641a78b Mon Sep 17 00:00:00 2001 From: Ohad Rau Date: Thu, 1 Aug 2019 09:58:00 -0700 Subject: [PATCH 2/2] WASM API cleanup --- deps/v8/include/v8-wasm.h | 3 +-- deps/v8/src/api/api-wasm.cc | 13 ++++++++----- deps/v8/src/wasm/wasm-js.cc | 5 ----- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/deps/v8/include/v8-wasm.h b/deps/v8/include/v8-wasm.h index e2112b6d05c..ae81232a178 100644 --- a/deps/v8/include/v8-wasm.h +++ b/deps/v8/include/v8-wasm.h @@ -13,13 +13,12 @@ namespace v8 { namespace wasm { -#define PAGE_SIZE 0x10000 - class V8_EXPORT Memory { private: size_t pages_; uint8_t* data_; public: + static const int PAGE_SIZE = 0x10000; Memory(size_t pages, uint8_t* data); Memory(const Memory& memory); size_t size(); diff --git a/deps/v8/src/api/api-wasm.cc b/deps/v8/src/api/api-wasm.cc index 9947920a4bc..729ed2e3d6e 100644 --- a/deps/v8/src/api/api-wasm.cc +++ b/deps/v8/src/api/api-wasm.cc @@ -26,14 +26,16 @@ size_t Memory::pages() { return pages_; } uint8_t* Memory::data() { return data_; } Table::Table(void* tableObject) { - tableObject_ = (void*) new i::WasmTableObject( - *(i::WasmTableObject*) tableObject); + i::WasmTableObject* actualTable = + reinterpret_cast(tableObject); + tableObject_ = (void*) new i::WasmTableObject(*actualTable); } Table::Table(const Table& table) { - tableObject_ = (void*) new i::WasmTableObject( - *(i::WasmTableObject*) table.tableObject_); + i::WasmTableObject* actualTable = + reinterpret_cast(table.tableObject_); + tableObject_ = (void*) new i::WasmTableObject(*actualTable); } -Table::~Table() { delete tableObject_; } +Table::~Table() { delete reinterpret_cast(tableObject_); } MaybeLocal Table::get(int index) const { i::Isolate* i_isolate = i::Isolate::TryGetCurrent(); i::WasmTableObject* table = (i::WasmTableObject*) tableObject_; @@ -129,6 +131,7 @@ i::wasm::ValueType valkind_to_v8(ValKind type) { } // TODO(ohadrau): Clean up so that we're not maintaining 2 copies of this +// Taken from c-api.cc -- SignatureHelper::Serialize // Use an invalid type as a marker separating params and results. const i::wasm::ValueType kMarker = i::wasm::kWasmStmt; diff --git a/deps/v8/src/wasm/wasm-js.cc b/deps/v8/src/wasm/wasm-js.cc index ccda89d85b8..5d199d3f6ac 100644 --- a/deps/v8/src/wasm/wasm-js.cc +++ b/deps/v8/src/wasm/wasm-js.cc @@ -672,11 +672,6 @@ void WebAssemblyEmbedderBuiltins( HandleScope scope(isolate); ScheduledErrorThrower thrower(i_isolate, "WebAssembly.embedderBuiltins()"); - /*v8::ReturnValue return_value = args.GetReturnValue(); - - Eternal imports = i_isolate->wasm_native_imports(); - Local result = imports.Get(isolate); - return_value.Set(Utils::ToLocal(result));*/ v8::ReturnValue return_value = args.GetReturnValue(); Eternal imports = i_isolate->wasm_native_imports();