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

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

Issue 2342263002: [wasm] Fix test-run-wasm-module tests in debug mode. (Closed)
Patch Set: Rename Install functions Created 4 years, 3 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
« no previous file with comments | « src/wasm/wasm-js.h ('k') | test/cctest/wasm/test-run-wasm-module.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 Handle<String> name = v8_str(isolate, str); 309 Handle<String> name = v8_str(isolate, str);
310 Handle<FunctionTemplateInfo> temp = NewTemplate(isolate, func); 310 Handle<FunctionTemplateInfo> temp = NewTemplate(isolate, func);
311 Handle<JSFunction> function = 311 Handle<JSFunction> function =
312 ApiNatives::InstantiateFunction(temp).ToHandleChecked(); 312 ApiNatives::InstantiateFunction(temp).ToHandleChecked();
313 PropertyAttributes attributes = 313 PropertyAttributes attributes =
314 static_cast<PropertyAttributes>(DONT_DELETE | READ_ONLY); 314 static_cast<PropertyAttributes>(DONT_DELETE | READ_ONLY);
315 JSObject::AddProperty(object, name, function, attributes); 315 JSObject::AddProperty(object, name, function, attributes);
316 return function; 316 return function;
317 } 317 }
318 318
319 void WasmJs::SetupIsolateForWasm(Isolate* isolate) { 319 void WasmJs::InstallWasmModuleSymbolIfNeeded(Isolate* isolate,
320 InstallWasmFunctionMap(isolate, isolate->native_context()); 320 Handle<JSGlobalObject> global,
321 InstallWasmModuleSymbol(isolate, isolate->global_object(), 321 Handle<Context> context) {
322 isolate->native_context()); 322 if (!context->get(Context::WASM_MODULE_SYM_INDEX)->IsSymbol() ||
323 } 323 !context->get(Context::WASM_INSTANCE_SYM_INDEX)->IsSymbol()) {
324 Factory* factory = isolate->factory();
325 // Create private symbols.
326 Handle<Symbol> module_sym = factory->NewPrivateSymbol();
327 Handle<Symbol> instance_sym = factory->NewPrivateSymbol();
328 context->set_wasm_module_sym(*module_sym);
329 context->set_wasm_instance_sym(*instance_sym);
324 330
325 void WasmJs::InstallWasmModuleSymbol(Isolate* isolate, 331 // Bind the WebAssembly object.
326 Handle<JSGlobalObject> global, 332 Handle<String> name = v8_str(isolate, "WebAssembly");
327 Handle<Context> context) { 333 Handle<JSFunction> cons = factory->NewFunction(name);
328 Factory* factory = isolate->factory(); 334 JSFunction::SetInstancePrototype(
329 // Create private symbols. 335 cons, Handle<Object>(context->initial_object_prototype(), isolate));
330 Handle<Symbol> module_sym = factory->NewPrivateSymbol(); 336 cons->shared()->set_instance_class_name(*name);
331 Handle<Symbol> instance_sym = factory->NewPrivateSymbol(); 337 Handle<JSObject> wasm_object = factory->NewJSObject(cons, TENURED);
332 context->set_wasm_module_sym(*module_sym); 338 PropertyAttributes attributes = static_cast<PropertyAttributes>(DONT_ENUM);
333 context->set_wasm_instance_sym(*instance_sym); 339 JSObject::AddProperty(global, name, wasm_object, attributes);
334 340
335 // Bind the WebAssembly object. 341 // Install static methods on WebAssembly object.
336 Handle<String> name = v8_str(isolate, "WebAssembly"); 342 InstallFunc(isolate, wasm_object, "compile", WebAssemblyCompile);
337 Handle<JSFunction> cons = factory->NewFunction(name); 343 Handle<JSFunction> module_constructor =
338 JSFunction::SetInstancePrototype( 344 InstallFunc(isolate, wasm_object, "Module", WebAssemblyModule);
339 cons, Handle<Object>(context->initial_object_prototype(), isolate)); 345 Handle<JSFunction> instance_constructor =
340 cons->shared()->set_instance_class_name(*name); 346 InstallFunc(isolate, wasm_object, "Instance", WebAssemblyInstance);
341 Handle<JSObject> wasm_object = factory->NewJSObject(cons, TENURED); 347 i::Handle<i::Map> map = isolate->factory()->NewMap(
342 PropertyAttributes attributes = static_cast<PropertyAttributes>(DONT_ENUM); 348 i::JS_OBJECT_TYPE, i::JSObject::kHeaderSize + i::kPointerSize);
343 JSObject::AddProperty(global, name, wasm_object, attributes); 349 module_constructor->set_prototype_or_initial_map(*map);
350 map->SetConstructor(*module_constructor);
344 351
345 // Install static methods on WebAssembly object. 352 context->set_wasm_module_constructor(*module_constructor);
346 InstallFunc(isolate, wasm_object, "compile", WebAssemblyCompile); 353 context->set_wasm_instance_constructor(*instance_constructor);
347 Handle<JSFunction> module_constructor = 354 }
348 InstallFunc(isolate, wasm_object, "Module", WebAssemblyModule);
349 Handle<JSFunction> instance_constructor =
350 InstallFunc(isolate, wasm_object, "Instance", WebAssemblyInstance);
351 i::Handle<i::Map> map = isolate->factory()->NewMap(
352 i::JS_OBJECT_TYPE, i::JSObject::kHeaderSize + i::kPointerSize);
353 module_constructor->set_prototype_or_initial_map(*map);
354 map->SetConstructor(*module_constructor);
355
356 context->set_wasm_module_constructor(*module_constructor);
357 context->set_wasm_instance_constructor(*instance_constructor);
358 } 355 }
359 356
360 void WasmJs::Install(Isolate* isolate, Handle<JSGlobalObject> global) { 357 void WasmJs::Install(Isolate* isolate, Handle<JSGlobalObject> global) {
361 if (!FLAG_expose_wasm && !FLAG_validate_asm) { 358 if (!FLAG_expose_wasm && !FLAG_validate_asm) {
362 return; 359 return;
363 } 360 }
364 361
365 Factory* factory = isolate->factory(); 362 Factory* factory = isolate->factory();
366 363
367 // Setup wasm function map. 364 // Setup wasm function map.
368 Handle<Context> context(global->native_context(), isolate); 365 Handle<Context> context(global->native_context(), isolate);
369 InstallWasmFunctionMap(isolate, context); 366 InstallWasmFunctionMapIfNeeded(isolate, context);
370 367
371 if (!FLAG_expose_wasm) { 368 if (!FLAG_expose_wasm) {
372 return; 369 return;
373 } 370 }
374 371
375 // Bind the experimental WASM object. 372 // Bind the experimental WASM object.
376 // TODO(rossberg, titzer): remove once it's no longer needed. 373 // TODO(rossberg, titzer): remove once it's no longer needed.
377 { 374 {
378 Handle<String> name = v8_str(isolate, "Wasm"); 375 Handle<String> name = v8_str(isolate, "Wasm");
379 Handle<JSFunction> cons = factory->NewFunction(name); 376 Handle<JSFunction> cons = factory->NewFunction(name);
(...skipping 12 matching lines...) Expand all
392 { 389 {
393 // Add the Wasm.experimentalVersion property. 390 // Add the Wasm.experimentalVersion property.
394 Handle<String> name = v8_str(isolate, "experimentalVersion"); 391 Handle<String> name = v8_str(isolate, "experimentalVersion");
395 PropertyAttributes attributes = 392 PropertyAttributes attributes =
396 static_cast<PropertyAttributes>(DONT_DELETE | READ_ONLY); 393 static_cast<PropertyAttributes>(DONT_DELETE | READ_ONLY);
397 Handle<Smi> value = 394 Handle<Smi> value =
398 Handle<Smi>(Smi::FromInt(wasm::kWasmVersion), isolate); 395 Handle<Smi>(Smi::FromInt(wasm::kWasmVersion), isolate);
399 JSObject::AddProperty(wasm_object, name, value, attributes); 396 JSObject::AddProperty(wasm_object, name, value, attributes);
400 } 397 }
401 } 398 }
402 InstallWasmModuleSymbol(isolate, global, context); 399 InstallWasmModuleSymbolIfNeeded(isolate, global, context);
403 } 400 }
404 401
405 void WasmJs::InstallWasmFunctionMap(Isolate* isolate, Handle<Context> context) { 402 void WasmJs::InstallWasmFunctionMapIfNeeded(Isolate* isolate,
403 Handle<Context> context) {
406 if (!context->get(Context::WASM_FUNCTION_MAP_INDEX)->IsMap()) { 404 if (!context->get(Context::WASM_FUNCTION_MAP_INDEX)->IsMap()) {
407 // TODO(titzer): Move this to bootstrapper.cc?? 405 // TODO(titzer): Move this to bootstrapper.cc??
408 // TODO(titzer): Also make one for strict mode functions? 406 // TODO(titzer): Also make one for strict mode functions?
409 Handle<Map> prev_map = Handle<Map>(context->sloppy_function_map(), isolate); 407 Handle<Map> prev_map = Handle<Map>(context->sloppy_function_map(), isolate);
410 408
411 InstanceType instance_type = prev_map->instance_type(); 409 InstanceType instance_type = prev_map->instance_type();
412 int internal_fields = JSObject::GetInternalFieldCount(*prev_map); 410 int internal_fields = JSObject::GetInternalFieldCount(*prev_map);
413 CHECK_EQ(0, internal_fields); 411 CHECK_EQ(0, internal_fields);
414 int pre_allocated = 412 int pre_allocated =
415 prev_map->GetInObjectProperties() - prev_map->unused_property_fields(); 413 prev_map->GetInObjectProperties() - prev_map->unused_property_fields();
416 int instance_size = 0; 414 int instance_size = 0;
417 int in_object_properties = 0; 415 int in_object_properties = 0;
418 int wasm_internal_fields = internal_fields + 1 // module instance object 416 int wasm_internal_fields = internal_fields + 1 // module instance object
419 + 1 // function arity 417 + 1 // function arity
420 + 1; // function signature 418 + 1; // function signature
421 JSFunction::CalculateInstanceSizeHelper(instance_type, wasm_internal_fields, 419 JSFunction::CalculateInstanceSizeHelper(instance_type, wasm_internal_fields,
422 0, &instance_size, 420 0, &instance_size,
423 &in_object_properties); 421 &in_object_properties);
424 422
425 int unused_property_fields = in_object_properties - pre_allocated; 423 int unused_property_fields = in_object_properties - pre_allocated;
426 Handle<Map> map = Map::CopyInitialMap( 424 Handle<Map> map = Map::CopyInitialMap(
427 prev_map, instance_size, in_object_properties, unused_property_fields); 425 prev_map, instance_size, in_object_properties, unused_property_fields);
428 426
429 context->set_wasm_function_map(*map); 427 context->set_wasm_function_map(*map);
430 } 428 }
431 } 429 }
432 430
433 } // namespace internal 431 } // namespace internal
434 } // namespace v8 432 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/wasm-js.h ('k') | test/cctest/wasm/test-run-wasm-module.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698