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

Side by Side Diff: src/bootstrapper.cc

Issue 1577703005: [runtime] Refactor Function object setup into a single place. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 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
« no previous file with comments | « no previous file | src/js/v8natives.js » ('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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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/bootstrapper.h" 5 #include "src/bootstrapper.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/api-natives.h" 8 #include "src/api-natives.h"
9 #include "src/code-stubs.h" 9 #include "src/code-stubs.h"
10 #include "src/extensions/externalize-string-extension.h" 10 #include "src/extensions/externalize-string-extension.h"
(...skipping 1099 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 native_context()->set_object_keys(*object_keys); 1110 native_context()->set_object_keys(*object_keys);
1111 SimpleInstallFunction(object_function, "preventExtensions", 1111 SimpleInstallFunction(object_function, "preventExtensions",
1112 Builtins::kObjectPreventExtensions, 1, false); 1112 Builtins::kObjectPreventExtensions, 1, false);
1113 SimpleInstallFunction(object_function, "seal", Builtins::kObjectSeal, 1, 1113 SimpleInstallFunction(object_function, "seal", Builtins::kObjectSeal, 1,
1114 false); 1114 false);
1115 } 1115 }
1116 1116
1117 Handle<JSObject> global(native_context()->global_object()); 1117 Handle<JSObject> global(native_context()->global_object());
1118 1118
1119 { // --- F u n c t i o n --- 1119 { // --- F u n c t i o n ---
1120 Handle<JSFunction> function_function = 1120 Handle<JSFunction> prototype = empty_function;
1121 Handle<JSFunction> function_fun =
1121 InstallFunction(global, "Function", JS_FUNCTION_TYPE, JSFunction::kSize, 1122 InstallFunction(global, "Function", JS_FUNCTION_TYPE, JSFunction::kSize,
1122 empty_function, Builtins::kFunctionConstructor); 1123 prototype, Builtins::kFunctionConstructor);
1123 function_function->set_prototype_or_initial_map( 1124 function_fun->set_prototype_or_initial_map(
1124 *sloppy_function_map_writable_prototype_); 1125 *sloppy_function_map_writable_prototype_);
1125 function_function->shared()->DontAdaptArguments(); 1126 function_fun->shared()->DontAdaptArguments();
1126 function_function->shared()->set_construct_stub( 1127 function_fun->shared()->set_construct_stub(
1127 *isolate->builtins()->FunctionConstructor()); 1128 *isolate->builtins()->FunctionConstructor());
1128 function_function->shared()->set_length(1); 1129 function_fun->shared()->set_length(1);
1129 InstallWithIntrinsicDefaultProto(isolate, function_function, 1130 InstallWithIntrinsicDefaultProto(isolate, function_fun,
1130 Context::FUNCTION_FUNCTION_INDEX); 1131 Context::FUNCTION_FUNCTION_INDEX);
1131 1132
1132 sloppy_function_map_writable_prototype_->SetConstructor(*function_function); 1133 // Setup the methods on the %FunctionPrototype%.
1133 strict_function_map_writable_prototype_->SetConstructor(*function_function); 1134 SimpleInstallFunction(prototype, factory->apply_string(),
1134 native_context()->strong_function_map()->SetConstructor(*function_function); 1135 Builtins::kFunctionPrototypeApply, 2, false);
1136 SimpleInstallFunction(prototype, factory->bind_string(),
1137 Builtins::kFunctionPrototypeBind, 1, false);
1138 SimpleInstallFunction(prototype, factory->call_string(),
1139 Builtins::kFunctionPrototypeCall, 1, false);
1140 SimpleInstallFunction(prototype, factory->toString_string(),
1141 Builtins::kFunctionPrototypeToString, 0, false);
1142
1143 // Install the "constructor" property on the %FunctionPrototype%.
1144 JSObject::AddProperty(prototype, factory->constructor_string(),
1145 function_fun, DONT_ENUM);
1146
1147 sloppy_function_map_writable_prototype_->SetConstructor(*function_fun);
1148 strict_function_map_writable_prototype_->SetConstructor(*function_fun);
1149 native_context()->strong_function_map()->SetConstructor(*function_fun);
1135 } 1150 }
1136 1151
1137 { // --- A r r a y --- 1152 { // --- A r r a y ---
1138 Handle<JSFunction> array_function = 1153 Handle<JSFunction> array_function =
1139 InstallFunction(global, "Array", JS_ARRAY_TYPE, JSArray::kSize, 1154 InstallFunction(global, "Array", JS_ARRAY_TYPE, JSArray::kSize,
1140 isolate->initial_object_prototype(), 1155 isolate->initial_object_prototype(),
1141 Builtins::kArrayCode); 1156 Builtins::kArrayCode);
1142 array_function->shared()->DontAdaptArguments(); 1157 array_function->shared()->DontAdaptArguments();
1143 array_function->shared()->set_function_data(Smi::FromInt(kArrayCode)); 1158 array_function->shared()->set_function_data(Smi::FromInt(kArrayCode));
1144 1159
(...skipping 1532 matching lines...) Expand 10 before | Expand all | Expand 10 after
2677 2692
2678 // Make sure that InternalArray.prototype.concat appears to be compiled. 2693 // Make sure that InternalArray.prototype.concat appears to be compiled.
2679 // The code will never be called, but inline caching for call will 2694 // The code will never be called, but inline caching for call will
2680 // only work if it appears to be compiled. 2695 // only work if it appears to be compiled.
2681 concat->shared()->DontAdaptArguments(); 2696 concat->shared()->DontAdaptArguments();
2682 DCHECK(concat->is_compiled()); 2697 DCHECK(concat->is_compiled());
2683 // Set the lengths for the functions to satisfy ECMA-262. 2698 // Set the lengths for the functions to satisfy ECMA-262.
2684 concat->shared()->set_length(1); 2699 concat->shared()->set_length(1);
2685 } 2700 }
2686 2701
2687 // Install Function.prototype.apply, bind, call, and toString.
2688 {
2689 Handle<String> key = factory()->Function_string();
2690 Handle<JSFunction> function =
2691 Handle<JSFunction>::cast(Object::GetProperty(
2692 handle(native_context()->global_object()), key).ToHandleChecked());
2693 Handle<JSObject> proto =
2694 Handle<JSObject>(JSObject::cast(function->instance_prototype()));
2695
2696 // Install the apply, bind, call and toString functions.
2697 SimpleInstallFunction(proto, factory()->apply_string(),
2698 Builtins::kFunctionPrototypeApply, 2, false);
2699 SimpleInstallFunction(proto, factory()->bind_string(),
2700 Builtins::kFunctionPrototypeBind, 1, false);
2701 SimpleInstallFunction(proto, factory()->call_string(),
2702 Builtins::kFunctionPrototypeCall, 1, false);
2703 SimpleInstallFunction(proto, factory()->toString_string(),
2704 Builtins::kFunctionPrototypeToString, 0, false);
2705 }
2706
2707 // Set up the Promise constructor. 2702 // Set up the Promise constructor.
2708 { 2703 {
2709 Handle<String> key = factory()->Promise_string(); 2704 Handle<String> key = factory()->Promise_string();
2710 Handle<JSFunction> function = Handle<JSFunction>::cast( 2705 Handle<JSFunction> function = Handle<JSFunction>::cast(
2711 Object::GetProperty(handle(native_context()->global_object()), key) 2706 Object::GetProperty(handle(native_context()->global_object()), key)
2712 .ToHandleChecked()); 2707 .ToHandleChecked());
2713 JSFunction::EnsureHasInitialMap(function); 2708 JSFunction::EnsureHasInitialMap(function);
2714 function->initial_map()->set_instance_type(JS_PROMISE_TYPE); 2709 function->initial_map()->set_instance_type(JS_PROMISE_TYPE);
2715 function->shared()->set_construct_stub( 2710 function->shared()->set_construct_stub(
2716 *isolate()->builtins()->JSBuiltinsConstructStub()); 2711 *isolate()->builtins()->JSBuiltinsConstructStub());
(...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after
3515 } 3510 }
3516 3511
3517 3512
3518 // Called when the top-level V8 mutex is destroyed. 3513 // Called when the top-level V8 mutex is destroyed.
3519 void Bootstrapper::FreeThreadResources() { 3514 void Bootstrapper::FreeThreadResources() {
3520 DCHECK(!IsActive()); 3515 DCHECK(!IsActive());
3521 } 3516 }
3522 3517
3523 } // namespace internal 3518 } // namespace internal
3524 } // namespace v8 3519 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/js/v8natives.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698