[wasm] Create a proper map for functions created from WASM.
R=verwaest@chromium.org BUG= Review URL: https://codereview.chromium.org/1778863002 Cr-Commit-Position: refs/heads/master@{#34617}
This commit is contained in:
parent
457bbdc4b3
commit
0974bf278c
@ -13638,14 +13638,11 @@ int SharedFunctionInfo::SourceSize() {
|
||||
return end_position() - start_position();
|
||||
}
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
void CalculateInstanceSizeHelper(InstanceType instance_type,
|
||||
int requested_internal_fields,
|
||||
int requested_in_object_properties,
|
||||
int* instance_size,
|
||||
int* in_object_properties) {
|
||||
void JSFunction::CalculateInstanceSizeHelper(InstanceType instance_type,
|
||||
int requested_internal_fields,
|
||||
int requested_in_object_properties,
|
||||
int* instance_size,
|
||||
int* in_object_properties) {
|
||||
int header_size = JSObject::GetHeaderSize(instance_type);
|
||||
DCHECK_LE(requested_internal_fields,
|
||||
(JSObject::kMaxInstanceSize - header_size) >> kPointerSizeLog2);
|
||||
@ -13658,8 +13655,6 @@ void CalculateInstanceSizeHelper(InstanceType instance_type,
|
||||
requested_internal_fields;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
void JSFunction::CalculateInstanceSize(InstanceType instance_type,
|
||||
int requested_internal_fields,
|
||||
|
@ -7562,7 +7562,11 @@ class JSFunction: public JSObject {
|
||||
int requested_internal_fields,
|
||||
int* instance_size,
|
||||
int* in_object_properties);
|
||||
|
||||
static void CalculateInstanceSizeHelper(InstanceType instance_type,
|
||||
int requested_internal_fields,
|
||||
int requested_in_object_properties,
|
||||
int* instance_size,
|
||||
int* in_object_properties);
|
||||
// Visiting policy flags define whether the code entry or next function
|
||||
// should be visited or not.
|
||||
enum BodyVisitingPolicy {
|
||||
|
@ -307,10 +307,26 @@ void WasmJs::Install(Isolate* isolate, Handle<JSGlobalObject> global) {
|
||||
|
||||
void WasmJs::InstallWasmFunctionMap(Isolate* isolate, Handle<Context> context) {
|
||||
if (!context->get(Context::WASM_FUNCTION_MAP_INDEX)->IsMap()) {
|
||||
Handle<Map> wasm_function_map = isolate->factory()->NewMap(
|
||||
JS_FUNCTION_TYPE, JSFunction::kSize + kPointerSize);
|
||||
wasm_function_map->set_is_callable();
|
||||
context->set_wasm_function_map(*wasm_function_map);
|
||||
// TODO(titzer): Move this to bootstrapper.cc??
|
||||
// TODO(titzer): Also make one for strict mode functions?
|
||||
Handle<Map> prev_map = Handle<Map>(context->sloppy_function_map(), isolate);
|
||||
|
||||
InstanceType instance_type = prev_map->instance_type();
|
||||
int internal_fields = JSObject::GetInternalFieldCount(*prev_map);
|
||||
CHECK_EQ(0, internal_fields);
|
||||
int pre_allocated =
|
||||
prev_map->GetInObjectProperties() - prev_map->unused_property_fields();
|
||||
int instance_size;
|
||||
int in_object_properties;
|
||||
JSFunction::CalculateInstanceSizeHelper(instance_type, internal_fields + 1,
|
||||
0, &instance_size,
|
||||
&in_object_properties);
|
||||
|
||||
int unused_property_fields = in_object_properties - pre_allocated;
|
||||
Handle<Map> map = Map::CopyInitialMap(
|
||||
prev_map, instance_size, in_object_properties, unused_property_fields);
|
||||
|
||||
context->set_wasm_function_map(*map);
|
||||
}
|
||||
}
|
||||
|
||||
|
35
test/mjsunit/wasm/function-prototype.js
Normal file
35
test/mjsunit/wasm/function-prototype.js
Normal file
@ -0,0 +1,35 @@
|
||||
// Copyright 2016 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.
|
||||
|
||||
// Flags: --expose-wasm
|
||||
|
||||
load("test/mjsunit/wasm/wasm-constants.js");
|
||||
load("test/mjsunit/wasm/wasm-module-builder.js");
|
||||
|
||||
(function TestFunctionPrototype() {
|
||||
var builder = new WasmModuleBuilder();
|
||||
|
||||
builder.addFunction("nine", [kAstI32])
|
||||
.addBody([kExprI8Const, 9])
|
||||
.exportFunc();
|
||||
|
||||
var func = builder.instantiate().exports.nine;
|
||||
|
||||
// Check type and existence of prototype
|
||||
assertEquals("function", typeof func.apply);
|
||||
assertTrue(func.prototype != undefined);
|
||||
assertEquals("nine", func.name);
|
||||
assertEquals(undefined, func.displayName);
|
||||
|
||||
// Check that .apply() works.
|
||||
assertEquals(9, func.apply([]));
|
||||
assertEquals(9, func.apply([1]));
|
||||
assertEquals(9, func.apply([2, 3]));
|
||||
assertEquals(9, func.apply([6, 7, 9, 9]));
|
||||
|
||||
// TODO(titzer): assertEquals(1, func.length);
|
||||
|
||||
// Check we don't crash when converting to a string.
|
||||
print(func.toString());
|
||||
})();
|
Loading…
Reference in New Issue
Block a user