Handle<Code> call_code = Handle<Code>(isolate->builtins()->builtin(call));
Handle<JSObject> prototype;
Handle<JSFunction> function = maybe_prototype.ToHandle(&prototype)
- ? factory->NewFunction(prototype, internalized_name, type,
- instance_size, call_code)
- : factory->NewFunction(internalized_name, call_code);
+ ? factory->NewFunction(internalized_name, call_code, prototype,
+ type, instance_size)
+ : factory->NewFunctionWithoutPrototype(internalized_name, call_code);
PropertyAttributes attributes;
if (target->IsJSBuiltinsObject()) {
attributes =
Handle<String> empty_string =
factory->InternalizeOneByteString(STATIC_ASCII_VECTOR("Empty"));
Handle<Code> code(isolate->builtins()->builtin(Builtins::kEmptyFunction));
- Handle<JSFunction> empty_function = factory->NewFunction(empty_string, code);
+ Handle<JSFunction> empty_function = factory->NewFunctionWithoutPrototype(
+ empty_string, code);
// --- E m p t y ---
Handle<String> source = factory->NewStringFromStaticAscii("() {}");
STATIC_ASCII_VECTOR("ThrowTypeError"));
Handle<Code> code(isolate()->builtins()->builtin(
Builtins::kStrictModePoisonPill));
- throw_type_error_function = factory()->NewFunction(name, code);
+ throw_type_error_function = factory()->NewFunctionWithoutPrototype(
+ name, code);
throw_type_error_function->set_map(native_context()->sloppy_function_map());
throw_type_error_function->shared()->DontAdaptArguments();
Handle<Code> code = Handle<Code>(isolate()->builtins()->builtin(
Builtins::kIllegal));
js_global_function = factory()->NewFunction(
- name, JS_GLOBAL_OBJECT_TYPE, JSGlobalObject::kSize, code);
+ name, code, JS_GLOBAL_OBJECT_TYPE, JSGlobalObject::kSize);
// Change the constructor property of the prototype of the
// hidden global function to refer to the Object function.
Handle<JSObject> prototype =
Handle<Code> code = Handle<Code>(isolate()->builtins()->builtin(
Builtins::kIllegal));
global_proxy_function = factory()->NewFunction(
- name, JS_GLOBAL_PROXY_TYPE, JSGlobalProxy::kSize, code);
+ name, code, JS_GLOBAL_PROXY_TYPE, JSGlobalProxy::kSize);
} else {
Handle<ObjectTemplateInfo> data =
v8::Utils::OpenHandle(*global_template);
STATIC_ASCII_VECTOR("Arguments"));
Handle<Code> code(isolate->builtins()->builtin(Builtins::kIllegal));
- Handle<JSFunction> function = factory->NewFunction(arguments_string, code);
+ Handle<JSFunction> function = factory->NewFunctionWithoutPrototype(
+ arguments_string, code);
ASSERT(!function->has_initial_map());
function->shared()->set_instance_class_name(*arguments_string);
function->shared()->set_expected_nof_properties(2);
Handle<Code> code = Handle<Code>(
isolate->builtins()->builtin(Builtins::kIllegal));
Handle<JSFunction> context_extension_fun = factory->NewFunction(
- factory->empty_string(), JS_CONTEXT_EXTENSION_OBJECT_TYPE,
- JSObject::kHeaderSize, code);
+ factory->empty_string(), code, JS_CONTEXT_EXTENSION_OBJECT_TYPE,
+ JSObject::kHeaderSize);
Handle<String> name = factory->InternalizeOneByteString(
STATIC_ASCII_VECTOR("context_extension"));
Handle<Code>(isolate->builtins()->builtin(
Builtins::kHandleApiCallAsFunction));
Handle<JSFunction> delegate = factory->NewFunction(
- factory->empty_string(), JS_OBJECT_TYPE, JSObject::kHeaderSize, code);
+ factory->empty_string(), code, JS_OBJECT_TYPE, JSObject::kHeaderSize);
native_context()->set_call_as_function_delegate(*delegate);
delegate->shared()->DontAdaptArguments();
}
Handle<Code>(isolate->builtins()->builtin(
Builtins::kHandleApiCallAsConstructor));
Handle<JSFunction> delegate = factory->NewFunction(
- factory->empty_string(), JS_OBJECT_TYPE, JSObject::kHeaderSize, code);
+ factory->empty_string(), code, JS_OBJECT_TYPE, JSObject::kHeaderSize);
native_context()->set_call_as_constructor_delegate(*delegate);
delegate->shared()->DontAdaptArguments();
}
Handle<Code> code = Handle<Code>(
isolate()->builtins()->builtin(Builtins::kIllegal));
Handle<JSFunction> builtins_fun = factory()->NewFunction(
- factory()->empty_string(), JS_BUILTINS_OBJECT_TYPE,
- JSBuiltinsObject::kSize, code);
+ factory()->empty_string(), code, JS_BUILTINS_OBJECT_TYPE,
+ JSBuiltinsObject::kSize);
Handle<String> name =
factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("builtins"));
}
-Handle<JSFunction> Factory::NewFunction(Handle<String> name,
- MaybeHandle<Code> maybe_code,
- MaybeHandle<Object> maybe_prototype) {
- Handle<SharedFunctionInfo> info = NewSharedFunctionInfo(name);
- ASSERT(info->strict_mode() == SLOPPY);
- Handle<Code> code;
- if (maybe_code.ToHandle(&code)) {
- info->set_code(*code);
- }
+Handle<JSFunction> Factory::NewFunction(Handle<Map> map,
+ Handle<String> name,
+ MaybeHandle<Code> code) {
Handle<Context> context(isolate()->context()->native_context());
- Handle<Map> map = maybe_prototype.is_null()
- ? isolate()->sloppy_function_without_prototype_map()
- : isolate()->sloppy_function_map();
- Handle<JSFunction> result = NewFunction(map, info, context);
- Handle<Object> prototype;
- if (maybe_prototype.ToHandle(&prototype)) {
- result->set_prototype_or_initial_map(*prototype);
- }
- return result;
+ Handle<SharedFunctionInfo> info = NewSharedFunctionInfo(name, code);
+ ASSERT((info->strict_mode() == SLOPPY) &&
+ (map.is_identical_to(isolate()->sloppy_function_map()) ||
+ map.is_identical_to(
+ isolate()->sloppy_function_without_prototype_map())));
+ return NewFunction(map, info, context);
}
Handle<JSFunction> Factory::NewFunction(Handle<String> name) {
- return NewFunction(name, MaybeHandle<Code>(), the_hole_value());
+ return NewFunction(
+ isolate()->sloppy_function_map(), name, MaybeHandle<Code>());
}
-Handle<JSFunction> Factory::NewFunction(Handle<Object> prototype,
- Handle<String> name,
+Handle<JSFunction> Factory::NewFunctionWithoutPrototype(Handle<String> name,
+ Handle<Code> code) {
+ return NewFunction(
+ isolate()->sloppy_function_without_prototype_map(), name, code);
+}
+
+
+Handle<JSFunction> Factory::NewFunction(Handle<String> name,
+ Handle<Code> code,
+ Handle<Object> prototype) {
+ Handle<JSFunction> result = NewFunction(
+ isolate()->sloppy_function_map(), name, code);
+ result->set_prototype_or_initial_map(*prototype);
+ return result;
+}
+
+
+Handle<JSFunction> Factory::NewFunction(Handle<String> name,
+ Handle<Code> code,
+ Handle<Object> prototype,
InstanceType type,
- int instance_size,
- Handle<Code> code) {
+ int instance_size) {
// Allocate the function
Handle<JSFunction> function = NewFunction(name, code, prototype);
Handle<JSFunction> Factory::NewFunction(Handle<String> name,
+ Handle<Code> code,
InstanceType type,
- int instance_size,
- Handle<Code> code) {
- return NewFunction(the_hole_value(), name, type, instance_size, code);
+ int instance_size) {
+ return NewFunction(name, code, the_hole_value(), type, instance_size);
}
OneByteStringKey key(STATIC_ASCII_VECTOR("<freezing call trap>"),
heap->HashSeed());
Handle<String> name = InternalizeStringWithKey(&key);
- shared = NewSharedFunctionInfo(name);
+ shared = NewSharedFunctionInfo(name, MaybeHandle<Code>());
}
// In order to keep heap in consistent state there must be no allocations
Handle<Code> code,
Handle<ScopeInfo> scope_info,
Handle<FixedArray> feedback_vector) {
- Handle<SharedFunctionInfo> shared = NewSharedFunctionInfo(name);
- shared->set_code(*code);
+ Handle<SharedFunctionInfo> shared = NewSharedFunctionInfo(name, code);
shared->set_scope_info(*scope_info);
shared->set_feedback_vector(*feedback_vector);
int literals_array_size = number_of_literals;
}
-Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo(Handle<String> name) {
+Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo(
+ Handle<String> name,
+ MaybeHandle<Code> maybe_code) {
Handle<Map> map = shared_function_info_map();
Handle<SharedFunctionInfo> share = New<SharedFunctionInfo>(map,
OLD_POINTER_SPACE);
// Set pointer fields.
share->set_name(*name);
- Code* illegal = isolate()->builtins()->builtin(Builtins::kIllegal);
- share->set_code(illegal);
+ Handle<Code> code;
+ if (!maybe_code.ToHandle(&code)) {
+ code = handle(isolate()->builtins()->builtin(Builtins::kIllegal));
+ }
+ share->set_code(*code);
share->set_optimized_code_map(Smi::FromInt(0));
share->set_scope_info(ScopeInfo::Empty(isolate()));
Code* construct_stub =
Handle<JSFunction> result;
if (obj->remove_prototype()) {
- result = NewFunction(empty_string(), code);
+ result = NewFunctionWithoutPrototype(empty_string(), code);
} else {
int internal_field_count = 0;
if (!obj->instance_template()->IsUndefined()) {
break;
}
- result = NewFunction(prototype, empty_string(), type, instance_size, code);
+ result = NewFunction(empty_string(), code, prototype, type, instance_size);
}
result->shared()->set_length(obj->length());
void BecomeJSFunction(Handle<JSReceiver> object);
Handle<JSFunction> NewFunction(Handle<String> name,
- MaybeHandle<Code> maybe_code,
- MaybeHandle<Object> maybe_prototype =
- MaybeHandle<Object>());
+ Handle<Code> code,
+ Handle<Object> prototype);
Handle<JSFunction> NewFunction(Handle<String> name);
+ Handle<JSFunction> NewFunctionWithoutPrototype(Handle<String> name,
+ Handle<Code> code);
Handle<JSFunction> NewFunctionFromSharedFunctionInfo(
Handle<SharedFunctionInfo> function_info,
Handle<Context> context,
PretenureFlag pretenure = TENURED);
- Handle<JSFunction> NewFunction(Handle<Object> maybe_prototype,
- Handle<String> name,
+ Handle<JSFunction> NewFunction(Handle<String> name,
+ Handle<Code> code,
+ Handle<Object> prototype,
InstanceType type,
- int instance_size,
- Handle<Code> code);
+ int instance_size);
Handle<JSFunction> NewFunction(Handle<String> name,
+ Handle<Code> code,
InstanceType type,
- int instance_size,
- Handle<Code> code);
+ int instance_size);
// Create a serialized scope info.
Handle<ScopeInfo> NewScopeInfo(int length);
Handle<Code> code,
Handle<ScopeInfo> scope_info,
Handle<FixedArray> feedback_vector);
- Handle<SharedFunctionInfo> NewSharedFunctionInfo(Handle<String> name);
+ Handle<SharedFunctionInfo> NewSharedFunctionInfo(Handle<String> name,
+ MaybeHandle<Code> code);
// Allocate a new type feedback vector
Handle<FixedArray> NewTypeFeedbackVector(int slot_count);
// Creates a code object that is not yet fully initialized yet.
inline Handle<Code> NewCodeRaw(int object_size, bool immovable);
- // Initializes a function with a shared part and prototype.
- // Note: this code was factored out of NewFunction such that other parts of
- // the VM could use it. Specifically, a function that creates instances of
- // type JS_FUNCTION_TYPE benefit from the use of this function.
- inline void InitializeFunction(Handle<JSFunction> function,
- Handle<SharedFunctionInfo> info,
- Handle<Context> context);
-
- // Creates a function initialized with a shared part.
- inline Handle<JSFunction> NewFunction(Handle<Map> map,
- Handle<SharedFunctionInfo> info,
- Handle<Context> context,
- PretenureFlag pretenure = TENURED);
-
// Create a new map cache.
Handle<MapCache> NewMapCache(int at_least_space_for);
// Update the cache with a new number-string pair.
void SetNumberStringCache(Handle<Object> number, Handle<String> string);
+
+ // Initializes a function with a shared part and prototype.
+ // Note: this code was factored out of NewFunction such that other parts of
+ // the VM could use it. Specifically, a function that creates instances of
+ // type JS_FUNCTION_TYPE benefit from the use of this function.
+ inline void InitializeFunction(Handle<JSFunction> function,
+ Handle<SharedFunctionInfo> info,
+ Handle<Context> context);
+
+ // Creates a function initialized with a shared part.
+ Handle<JSFunction> NewFunction(Handle<Map> map,
+ Handle<SharedFunctionInfo> info,
+ Handle<Context> context,
+ PretenureFlag pretenure = TENURED);
+
+ Handle<JSFunction> NewFunction(Handle<Map> map,
+ Handle<String> name,
+ MaybeHandle<Code> maybe_code);
};
} } // namespace v8::internal
Builtins::Name builtin_name) {
Handle<String> key = isolate->factory()->InternalizeUtf8String(name);
Handle<Code> code(isolate->builtins()->builtin(builtin_name));
- Handle<JSFunction> optimized = isolate->factory()->NewFunction(key, code);
+ Handle<JSFunction> optimized =
+ isolate->factory()->NewFunctionWithoutPrototype(key, code);
optimized->shared()->DontAdaptArguments();
JSReceiver::SetProperty(holder, key, optimized, NONE, STRICT).Assert();
return optimized;