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

Side by Side Diff: src/bootstrapper.cc

Issue 2852833002: [builtins] De-duplicate specification of array builtin parameter count (Closed)
Patch Set: Created 3 years, 7 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/builtins/builtins.h » ('j') | src/builtins/builtins.cc » ('J')
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/base/ieee754.h" 9 #include "src/base/ieee754.h"
10 #include "src/code-stubs.h" 10 #include "src/code-stubs.h"
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 170
171 #define DECLARE_FEATURE_INITIALIZATION(id, descr) \ 171 #define DECLARE_FEATURE_INITIALIZATION(id, descr) \
172 void InitializeGlobal_##id(); 172 void InitializeGlobal_##id();
173 173
174 HARMONY_INPROGRESS(DECLARE_FEATURE_INITIALIZATION) 174 HARMONY_INPROGRESS(DECLARE_FEATURE_INITIALIZATION)
175 HARMONY_STAGED(DECLARE_FEATURE_INITIALIZATION) 175 HARMONY_STAGED(DECLARE_FEATURE_INITIALIZATION)
176 HARMONY_SHIPPING(DECLARE_FEATURE_INITIALIZATION) 176 HARMONY_SHIPPING(DECLARE_FEATURE_INITIALIZATION)
177 #undef DECLARE_FEATURE_INITIALIZATION 177 #undef DECLARE_FEATURE_INITIALIZATION
178 178
179 void InstallOneBuiltinFunction(Handle<Object> prototype, const char* method, 179 void InstallOneBuiltinFunction(Handle<Object> prototype, const char* method,
180 Builtins::Name name, 180 Builtins::Name name);
181 int internal_formal_parameter_count);
182 void InitializeGlobal_experimental_fast_array_builtins(); 181 void InitializeGlobal_experimental_fast_array_builtins();
183 182
184 Handle<JSFunction> InstallArrayBuffer(Handle<JSObject> target, 183 Handle<JSFunction> InstallArrayBuffer(Handle<JSObject> target,
185 const char* name, 184 const char* name,
186 Builtins::Name call_byteLength, 185 Builtins::Name call_byteLength,
187 BuiltinFunctionId byteLength_id, 186 BuiltinFunctionId byteLength_id,
188 Builtins::Name call_slice); 187 Builtins::Name call_slice);
189 Handle<JSFunction> InstallInternalArray(Handle<JSObject> target, 188 Handle<JSFunction> InstallInternalArray(Handle<JSObject> target,
190 const char* name, 189 const char* name,
191 ElementsKind elements_kind); 190 ElementsKind elements_kind);
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 fun->shared()->set_internal_formal_parameter_count(len); 389 fun->shared()->set_internal_formal_parameter_count(len);
391 } else { 390 } else {
392 fun->shared()->DontAdaptArguments(); 391 fun->shared()->DontAdaptArguments();
393 } 392 }
394 fun->shared()->set_length(len); 393 fun->shared()->set_length(len);
395 return fun; 394 return fun;
396 } 395 }
397 396
398 Handle<JSFunction> InstallArrayBuiltinFunction(Handle<JSObject> base, 397 Handle<JSFunction> InstallArrayBuiltinFunction(Handle<JSObject> base,
399 const char* name, 398 const char* name,
400 Builtins::Name call, 399 Builtins::Name call) {
401 int argument_count) {
402 Isolate* isolate = base->GetIsolate(); 400 Isolate* isolate = base->GetIsolate();
403 Handle<String> str_name = isolate->factory()->InternalizeUtf8String(name); 401 Handle<String> str_name = isolate->factory()->InternalizeUtf8String(name);
404 Handle<JSFunction> fun = 402 Handle<JSFunction> fun =
405 CreateFunction(isolate, str_name, JS_OBJECT_TYPE, JSObject::kHeaderSize, 403 CreateFunction(isolate, str_name, JS_OBJECT_TYPE, JSObject::kHeaderSize,
406 MaybeHandle<JSObject>(), call, true); 404 MaybeHandle<JSObject>(), call, true);
407 fun->shared()->set_internal_formal_parameter_count(argument_count); 405 fun->shared()->set_internal_formal_parameter_count(
406 Builtins::GetBuiltinParameterCount(isolate, call));
408 407
409 // Set the length to 1 to satisfy ECMA-262. 408 // Set the length to 1 to satisfy ECMA-262.
410 fun->shared()->set_length(1); 409 fun->shared()->set_length(1);
411 fun->shared()->set_language_mode(STRICT); 410 fun->shared()->set_language_mode(STRICT);
412 InstallFunction(base, fun, str_name); 411 InstallFunction(base, fun, str_name);
413 return fun; 412 return fun;
414 } 413 }
415 414
416 Handle<JSFunction> SimpleInstallFunction(Handle<JSObject> base, 415 Handle<JSFunction> SimpleInstallFunction(Handle<JSObject> base,
417 Handle<String> name, 416 Handle<String> name,
(...skipping 3438 matching lines...) Expand 10 before | Expand all | Expand 10 after
3856 Handle<JSObject> symbol = Handle<JSObject>::cast( 3855 Handle<JSObject> symbol = Handle<JSObject>::cast(
3857 JSObject::GetProperty(global, symbol_string).ToHandleChecked()); 3856 JSObject::GetProperty(global, symbol_string).ToHandleChecked());
3858 Handle<String> name_string = factory->InternalizeUtf8String(name); 3857 Handle<String> name_string = factory->InternalizeUtf8String(name);
3859 PropertyAttributes attributes = 3858 PropertyAttributes attributes =
3860 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); 3859 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);
3861 JSObject::AddProperty(symbol, name_string, value, attributes); 3860 JSObject::AddProperty(symbol, name_string, value, attributes);
3862 } 3861 }
3863 3862
3864 void Genesis::InstallOneBuiltinFunction(Handle<Object> prototype, 3863 void Genesis::InstallOneBuiltinFunction(Handle<Object> prototype,
3865 const char* method_name, 3864 const char* method_name,
3866 Builtins::Name builtin_name, 3865 Builtins::Name builtin_name) {
3867 int internal_formal_parameter_count) {
3868 LookupIterator it( 3866 LookupIterator it(
3869 prototype, isolate()->factory()->NewStringFromAsciiChecked(method_name), 3867 prototype, isolate()->factory()->NewStringFromAsciiChecked(method_name),
3870 LookupIterator::OWN_SKIP_INTERCEPTOR); 3868 LookupIterator::OWN_SKIP_INTERCEPTOR);
3871 Handle<Object> function = Object::GetProperty(&it).ToHandleChecked(); 3869 Handle<Object> function = Object::GetProperty(&it).ToHandleChecked();
3872 Handle<JSFunction>::cast(function)->set_code( 3870 Handle<JSFunction>::cast(function)->set_code(
3873 isolate()->builtins()->builtin(builtin_name)); 3871 isolate()->builtins()->builtin(builtin_name));
3874 SharedFunctionInfo* info = Handle<JSFunction>::cast(function)->shared(); 3872 SharedFunctionInfo* info = Handle<JSFunction>::cast(function)->shared();
3875 info->set_code(isolate()->builtins()->builtin(builtin_name)); 3873 info->set_code(isolate()->builtins()->builtin(builtin_name));
3876 info->set_internal_formal_parameter_count(internal_formal_parameter_count); 3874 info->set_internal_formal_parameter_count(
3875 Builtins::GetBuiltinParameterCount(isolate(), builtin_name));
3877 } 3876 }
3878 3877
3879 void Genesis::InitializeGlobal_experimental_fast_array_builtins() { 3878 void Genesis::InitializeGlobal_experimental_fast_array_builtins() {
3880 if (!FLAG_experimental_fast_array_builtins) return; 3879 if (!FLAG_experimental_fast_array_builtins) return;
3881 { 3880 {
3882 Handle<Object> typed_array_prototype( 3881 Handle<Object> typed_array_prototype(
3883 native_context()->typed_array_prototype(), isolate()); 3882 native_context()->typed_array_prototype(), isolate());
3884 // Insert experimental fast TypedArray builtins here. 3883 // Insert experimental fast TypedArray builtins here.
3885 InstallOneBuiltinFunction(typed_array_prototype, "every", 3884 InstallOneBuiltinFunction(typed_array_prototype, "every",
3886 Builtins::kTypedArrayPrototypeEvery, 3885 Builtins::kTypedArrayPrototypeEvery);
3887 SharedFunctionInfo::kDontAdaptArgumentsSentinel);
3888 InstallOneBuiltinFunction(typed_array_prototype, "some", 3886 InstallOneBuiltinFunction(typed_array_prototype, "some",
3889 Builtins::kTypedArrayPrototypeSome, 3887 Builtins::kTypedArrayPrototypeSome);
3890 SharedFunctionInfo::kDontAdaptArgumentsSentinel);
3891 InstallOneBuiltinFunction(typed_array_prototype, "reduce", 3888 InstallOneBuiltinFunction(typed_array_prototype, "reduce",
3892 Builtins::kTypedArrayPrototypeReduce, 3889 Builtins::kTypedArrayPrototypeReduce);
3893 SharedFunctionInfo::kDontAdaptArgumentsSentinel);
3894 InstallOneBuiltinFunction(typed_array_prototype, "reduceRight", 3890 InstallOneBuiltinFunction(typed_array_prototype, "reduceRight",
3895 Builtins::kTypedArrayPrototypeReduceRight, 3891 Builtins::kTypedArrayPrototypeReduceRight);
3896 SharedFunctionInfo::kDontAdaptArgumentsSentinel);
3897 } 3892 }
3898 } 3893 }
3899 3894
3900 void Genesis::InitializeGlobal_harmony_sharedarraybuffer() { 3895 void Genesis::InitializeGlobal_harmony_sharedarraybuffer() {
3901 if (!FLAG_harmony_sharedarraybuffer) return; 3896 if (!FLAG_harmony_sharedarraybuffer) return;
3902 3897
3903 Handle<JSGlobalObject> global(native_context()->global_object()); 3898 Handle<JSGlobalObject> global(native_context()->global_object());
3904 Isolate* isolate = global->GetIsolate(); 3899 Isolate* isolate = global->GetIsolate();
3905 Factory* factory = isolate->factory(); 3900 Factory* factory = isolate->factory();
3906 3901
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
4351 4346
4352 // Make sure that Array.prototype.concat appears to be compiled. 4347 // Make sure that Array.prototype.concat appears to be compiled.
4353 // The code will never be called, but inline caching for call will 4348 // The code will never be called, but inline caching for call will
4354 // only work if it appears to be compiled. 4349 // only work if it appears to be compiled.
4355 concat->shared()->DontAdaptArguments(); 4350 concat->shared()->DontAdaptArguments();
4356 DCHECK(concat->is_compiled()); 4351 DCHECK(concat->is_compiled());
4357 // Set the lengths for the functions to satisfy ECMA-262. 4352 // Set the lengths for the functions to satisfy ECMA-262.
4358 concat->shared()->set_length(1); 4353 concat->shared()->set_length(1);
4359 4354
4360 // Install Array.prototype.forEach 4355 // Install Array.prototype.forEach
4361 Handle<JSFunction> forEach = InstallArrayBuiltinFunction( 4356 Handle<JSFunction> forEach =
4362 proto, "forEach", Builtins::kArrayForEach, 4357 InstallArrayBuiltinFunction(proto, "forEach", Builtins::kArrayForEach);
4363 SharedFunctionInfo::kDontAdaptArgumentsSentinel);
4364 // Add forEach to the context. 4358 // Add forEach to the context.
4365 native_context()->set_array_for_each_iterator(*forEach); 4359 native_context()->set_array_for_each_iterator(*forEach);
4366 4360
4367 // Install Array.prototype.filter 4361 // Install Array.prototype.filter
4368 InstallArrayBuiltinFunction( 4362 InstallArrayBuiltinFunction(proto, "filter", Builtins::kArrayFilter);
4369 proto, "filter", Builtins::kArrayFilter,
4370 SharedFunctionInfo::kDontAdaptArgumentsSentinel);
4371 4363
4372 // Install Array.prototype.map 4364 // Install Array.prototype.map
4373 InstallArrayBuiltinFunction( 4365 InstallArrayBuiltinFunction(proto, "map", Builtins::kArrayMap);
4374 proto, "map", Builtins::kArrayMap,
4375 SharedFunctionInfo::kDontAdaptArgumentsSentinel);
4376 4366
4377 // Install Array.prototype.every 4367 // Install Array.prototype.every
4378 InstallArrayBuiltinFunction( 4368 InstallArrayBuiltinFunction(proto, "every", Builtins::kArrayEvery);
4379 proto, "every", Builtins::kArrayEvery,
4380 SharedFunctionInfo::kDontAdaptArgumentsSentinel);
4381 4369
4382 // Install Array.prototype.some 4370 // Install Array.prototype.some
4383 InstallArrayBuiltinFunction( 4371 InstallArrayBuiltinFunction(proto, "some", Builtins::kArraySome);
4384 proto, "some", Builtins::kArraySome,
4385 SharedFunctionInfo::kDontAdaptArgumentsSentinel);
4386 4372
4387 // Install Array.prototype.reduce 4373 // Install Array.prototype.reduce
4388 InstallArrayBuiltinFunction( 4374 InstallArrayBuiltinFunction(proto, "reduce", Builtins::kArrayReduce);
4389 proto, "reduce", Builtins::kArrayReduce,
4390 SharedFunctionInfo::kDontAdaptArgumentsSentinel);
4391 4375
4392 // Install Array.prototype.reduceRight 4376 // Install Array.prototype.reduceRight
4393 InstallArrayBuiltinFunction( 4377 InstallArrayBuiltinFunction(proto, "reduceRight",
4394 proto, "reduceRight", Builtins::kArrayReduceRight, 4378 Builtins::kArrayReduceRight);
4395 SharedFunctionInfo::kDontAdaptArgumentsSentinel);
4396 } 4379 }
4397 4380
4398 // Install InternalArray.prototype.concat 4381 // Install InternalArray.prototype.concat
4399 { 4382 {
4400 Handle<JSFunction> array_constructor( 4383 Handle<JSFunction> array_constructor(
4401 native_context()->internal_array_function()); 4384 native_context()->internal_array_function());
4402 Handle<JSObject> proto(JSObject::cast(array_constructor->prototype())); 4385 Handle<JSObject> proto(JSObject::cast(array_constructor->prototype()));
4403 Handle<JSFunction> concat = 4386 Handle<JSFunction> concat =
4404 InstallFunction(proto, "concat", JS_OBJECT_TYPE, JSObject::kHeaderSize, 4387 InstallFunction(proto, "concat", JS_OBJECT_TYPE, JSObject::kHeaderSize,
4405 MaybeHandle<JSObject>(), Builtins::kArrayConcat); 4388 MaybeHandle<JSObject>(), Builtins::kArrayConcat);
(...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after
5290 } 5273 }
5291 5274
5292 5275
5293 // Called when the top-level V8 mutex is destroyed. 5276 // Called when the top-level V8 mutex is destroyed.
5294 void Bootstrapper::FreeThreadResources() { 5277 void Bootstrapper::FreeThreadResources() {
5295 DCHECK(!IsActive()); 5278 DCHECK(!IsActive());
5296 } 5279 }
5297 5280
5298 } // namespace internal 5281 } // namespace internal
5299 } // namespace v8 5282 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/builtins/builtins.h » ('j') | src/builtins/builtins.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698