Rename NewFunction without prototype to NewFunctionWithoutPrototype
authorverwaest@chromium.org <verwaest@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Fri, 9 May 2014 17:39:54 +0000 (17:39 +0000)
committerverwaest@chromium.org <verwaest@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Fri, 9 May 2014 17:39:54 +0000 (17:39 +0000)
BUG=
R=ishell@chromium.org

Review URL: https://codereview.chromium.org/270573003

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21241 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/bootstrapper.cc
src/factory.cc
src/factory.h
src/runtime.cc

index f464bdb..c35120d 100644 (file)
@@ -358,9 +358,9 @@ static Handle<JSFunction> InstallFunction(Handle<JSObject> target,
   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 =
@@ -488,7 +488,8 @@ Handle<JSFunction> Genesis::CreateEmptyFunction(Isolate* isolate) {
   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("() {}");
@@ -569,7 +570,8 @@ Handle<JSFunction> Genesis::GetThrowTypeErrorFunction() {
         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();
 
@@ -708,7 +710,7 @@ Handle<JSGlobalProxy> Genesis::CreateNewGlobals(
     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 =
@@ -741,7 +743,7 @@ Handle<JSGlobalProxy> Genesis::CreateNewGlobals(
     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);
@@ -1084,7 +1086,8 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global,
         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);
@@ -1224,8 +1227,8 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global,
     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"));
@@ -1240,7 +1243,7 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global,
         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();
   }
@@ -1251,7 +1254,7 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global,
         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();
   }
@@ -1611,8 +1614,8 @@ bool Genesis::InstallNatives() {
   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"));
index 8ecbdbf..cfcb2f1 100644 (file)
@@ -1202,38 +1202,47 @@ Handle<JSFunction> Factory::NewFunction(Handle<Map> map,
 }
 
 
-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);
 
@@ -1251,10 +1260,10 @@ Handle<JSFunction> Factory::NewFunction(Handle<Object> 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);
 }
 
 
@@ -1753,7 +1762,7 @@ void Factory::ReinitializeJSReceiver(Handle<JSReceiver> object,
     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
@@ -1848,8 +1857,7 @@ Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo(
     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;
@@ -1890,15 +1898,20 @@ Handle<JSMessageObject> Factory::NewJSMessageObject(
 }
 
 
-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 =
@@ -2054,7 +2067,7 @@ Handle<JSFunction> Factory::CreateApiFunction(
 
   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()) {
@@ -2088,7 +2101,7 @@ Handle<JSFunction> Factory::CreateApiFunction(
         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());
index 02d0044..45d5401 100644 (file)
@@ -452,25 +452,26 @@ class Factory V8_FINAL {
   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);
@@ -597,7 +598,8 @@ class Factory V8_FINAL {
       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);
@@ -659,20 +661,6 @@ class Factory V8_FINAL {
   // 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);
 
@@ -687,6 +675,24 @@ class Factory V8_FINAL {
 
   // 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
index ed6ce93..4982606 100644 (file)
@@ -2806,7 +2806,8 @@ static Handle<JSFunction> InstallBuiltin(Isolate* isolate,
                                          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;