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

Side by Side Diff: src/wasm/wasm-js.cc

Issue 2629523007: [wasm] JS-API: enable WebAssembly.instantiate tests; fix LinkError (Closed)
Patch Set: initialize module_ upfront Created 3 years, 11 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/api-natives.h" 5 #include "src/api-natives.h"
6 #include "src/api.h" 6 #include "src/api.h"
7 #include "src/asmjs/asm-js.h" 7 #include "src/asmjs/asm-js.h"
8 #include "src/asmjs/asm-typer.h" 8 #include "src/asmjs/asm-typer.h"
9 #include "src/asmjs/asm-wasm-builder.h" 9 #include "src/asmjs/asm-wasm-builder.h"
10 #include "src/assert-scope.h" 10 #include "src/assert-scope.h"
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 } 185 }
186 i::MaybeHandle<i::JSObject> module_obj = 186 i::MaybeHandle<i::JSObject> module_obj =
187 CreateModuleObject(isolate, args[0], &thrower); 187 CreateModuleObject(isolate, args[0], &thrower);
188 if (module_obj.is_null()) return; 188 if (module_obj.is_null()) return;
189 189
190 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); 190 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
191 return_value.Set(Utils::ToLocal(module_obj.ToHandleChecked())); 191 return_value.Set(Utils::ToLocal(module_obj.ToHandleChecked()));
192 } 192 }
193 193
194 MaybeLocal<Value> InstantiateModuleImpl( 194 MaybeLocal<Value> InstantiateModuleImpl(
195 i::Isolate* i_isolate, i::Handle<i::JSObject> i_module_obj, 195 i::Isolate* i_isolate, i::Handle<i::WasmModuleObject> i_module_obj,
196 const v8::FunctionCallbackInfo<v8::Value>& args, ErrorThrower* thrower) { 196 const v8::FunctionCallbackInfo<v8::Value>& args, ErrorThrower* thrower) {
197 // It so happens that in both the WebAssembly.instantiate, as well as 197 // It so happens that in both the WebAssembly.instantiate, as well as
198 // WebAssembly.Instance ctor, the positions of the ffi object and memory 198 // WebAssembly.Instance ctor, the positions of the ffi object and memory
199 // are the same. If that changes later, we refactor the consts into 199 // are the same. If that changes later, we refactor the consts into
200 // parameters. 200 // parameters.
201 static const int kFfiOffset = 1; 201 static const int kFfiOffset = 1;
202 static const int kMemOffset = 2; 202 static const int kMemOffset = 2;
203 203
204 MaybeLocal<Value> nothing; 204 MaybeLocal<Value> nothing;
205 i::Handle<i::JSReceiver> ffi = i::Handle<i::JSObject>::null(); 205 i::Handle<i::JSReceiver> ffi = i::Handle<i::JSObject>::null();
206 // This is a first - level validation of the argument. If present, we only
207 // check its type. {Instantiate} will further check that if the module
208 // has imports, the argument must be present, as well as piecemeal
209 // import satisfaction.
206 if (args.Length() > kFfiOffset && !args[kFfiOffset]->IsUndefined()) { 210 if (args.Length() > kFfiOffset && !args[kFfiOffset]->IsUndefined()) {
207 if (!args[kFfiOffset]->IsObject()) { 211 if (!args[kFfiOffset]->IsObject()) {
208 thrower->TypeError("Argument %d must be an object", kFfiOffset); 212 thrower->TypeError("Argument %d must be an object", kFfiOffset);
209 return nothing; 213 return nothing;
210 } 214 }
211 Local<Object> obj = Local<Object>::Cast(args[kFfiOffset]); 215 Local<Object> obj = Local<Object>::Cast(args[kFfiOffset]);
212 ffi = i::Handle<i::JSReceiver>::cast(v8::Utils::OpenHandle(*obj)); 216 ffi = i::Handle<i::JSReceiver>::cast(v8::Utils::OpenHandle(*obj));
213 } 217 }
214 218
219 // The memory argument is a legacy, not spec - compliant artifact.
215 i::Handle<i::JSArrayBuffer> memory = i::Handle<i::JSArrayBuffer>::null(); 220 i::Handle<i::JSArrayBuffer> memory = i::Handle<i::JSArrayBuffer>::null();
216 if (args.Length() > kMemOffset && !args[kMemOffset]->IsUndefined()) { 221 if (args.Length() > kMemOffset && !args[kMemOffset]->IsUndefined()) {
217 if (!args[kMemOffset]->IsObject()) { 222 if (!args[kMemOffset]->IsObject()) {
218 thrower->TypeError("Argument %d must be a WebAssembly.Memory", 223 thrower->TypeError("Argument %d must be a WebAssembly.Memory",
219 kMemOffset); 224 kMemOffset);
220 return nothing; 225 return nothing;
221 } 226 }
222 Local<Object> obj = Local<Object>::Cast(args[kMemOffset]); 227 Local<Object> obj = Local<Object>::Cast(args[kMemOffset]);
223 i::Handle<i::Object> mem_obj = v8::Utils::OpenHandle(*obj); 228 i::Handle<i::Object> mem_obj = v8::Utils::OpenHandle(*obj);
224 if (!i::WasmJs::IsWasmMemoryObject(i_isolate, mem_obj)) { 229 if (!i::WasmJs::IsWasmMemoryObject(i_isolate, mem_obj)) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 319
315 Local<Context> context = isolate->GetCurrentContext(); 320 Local<Context> context = isolate->GetCurrentContext();
316 i::Handle<i::Context> i_context = Utils::OpenHandle(*context); 321 i::Handle<i::Context> i_context = Utils::OpenHandle(*context);
317 if (!BrandCheck(isolate, Utils::OpenHandle(*args[0]), 322 if (!BrandCheck(isolate, Utils::OpenHandle(*args[0]),
318 i::Handle<i::Symbol>(i_context->wasm_module_sym()), 323 i::Handle<i::Symbol>(i_context->wasm_module_sym()),
319 "Argument 0 must be a WebAssembly.Module")) { 324 "Argument 0 must be a WebAssembly.Module")) {
320 return; 325 return;
321 } 326 }
322 327
323 Local<Object> module_obj = Local<Object>::Cast(args[0]); 328 Local<Object> module_obj = Local<Object>::Cast(args[0]);
324 i::Handle<i::JSObject> i_module_obj = 329 i::Handle<i::WasmModuleObject> i_module_obj =
325 i::Handle<i::JSObject>::cast(v8::Utils::OpenHandle(*module_obj)); 330 i::Handle<i::WasmModuleObject>::cast(v8::Utils::OpenHandle(*module_obj));
326 331
327 MaybeLocal<Value> instance = 332 MaybeLocal<Value> instance =
328 InstantiateModuleImpl(i_isolate, i_module_obj, args, &thrower); 333 InstantiateModuleImpl(i_isolate, i_module_obj, args, &thrower);
329 if (instance.IsEmpty()) return; 334 if (instance.IsEmpty()) return;
330 335
331 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); 336 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
332 return_value.Set(instance.ToLocalChecked()); 337 return_value.Set(instance.ToLocalChecked());
333 } 338 }
334 339
335 void WebAssemblyInstantiate(const v8::FunctionCallbackInfo<v8::Value>& args) { 340 void WebAssemblyInstantiate(const v8::FunctionCallbackInfo<v8::Value>& args) {
336 v8::Isolate* isolate = args.GetIsolate(); 341 v8::Isolate* isolate = args.GetIsolate();
337 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 342 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
338 343
339 HandleScope scope(isolate); 344 HandleScope scope(isolate);
340 ErrorThrower thrower(i_isolate, "WebAssembly.compile()"); 345 ErrorThrower thrower(i_isolate, "WebAssembly.compile()");
341 346
342 if (args.Length() < 1) { 347 if (args.Length() < 1) {
343 thrower.TypeError("Argument 0 must be a buffer source"); 348 thrower.TypeError("Argument 0 must be a buffer source");
344 return; 349 return;
345 } 350 }
346 i::MaybeHandle<i::JSObject> module_obj = 351 i::MaybeHandle<i::WasmModuleObject> module_obj =
347 CreateModuleObject(isolate, args[0], &thrower); 352 CreateModuleObject(isolate, args[0], &thrower);
348 353
349 Local<Context> context = isolate->GetCurrentContext(); 354 Local<Context> context = isolate->GetCurrentContext();
350 v8::Local<v8::Promise::Resolver> resolver; 355 v8::Local<v8::Promise::Resolver> resolver;
351 if (!v8::Promise::Resolver::New(context).ToLocal(&resolver)) return; 356 if (!v8::Promise::Resolver::New(context).ToLocal(&resolver)) return;
352 if (module_obj.is_null()) { 357 if (module_obj.is_null()) {
353 DCHECK(thrower.error()); 358 DCHECK(thrower.error());
354 resolver->Reject(context, Utils::ToLocal(thrower.Reify())); 359 resolver->Reject(context, Utils::ToLocal(thrower.Reify()));
355 } else { 360 } else {
356 MaybeLocal<Value> instance = InstantiateModuleImpl( 361 MaybeLocal<Value> instance = InstantiateModuleImpl(
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 i::Handle<i::Symbol> symbol(isolate->context()->wasm_memory_sym(), isolate); 896 i::Handle<i::Symbol> symbol(isolate->context()->wasm_memory_sym(), isolate);
892 return HasBrand(value, symbol); 897 return HasBrand(value, symbol);
893 } 898 }
894 899
895 bool WasmJs::IsWasmTableObject(Isolate* isolate, Handle<Object> value) { 900 bool WasmJs::IsWasmTableObject(Isolate* isolate, Handle<Object> value) {
896 i::Handle<i::Symbol> symbol(isolate->context()->wasm_table_sym(), isolate); 901 i::Handle<i::Symbol> symbol(isolate->context()->wasm_table_sym(), isolate);
897 return HasBrand(value, symbol); 902 return HasBrand(value, symbol);
898 } 903 }
899 } // namespace internal 904 } // namespace internal
900 } // namespace v8 905 } // namespace v8
OLDNEW
« no previous file with comments | « src/asmjs/asm-js.cc ('k') | src/wasm/wasm-module.h » ('j') | test/mjsunit/wasm/js-api.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698