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

Side by Side Diff: src/builtins.cc

Issue 1679683004: Revert of Do not eagerly instantiate accessors' JSFunction. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 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 | « src/builtins.h ('k') | src/code-stubs.h » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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/builtins.h" 5 #include "src/builtins.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/api-natives.h" 8 #include "src/api-natives.h"
9 #include "src/arguments.h" 9 #include "src/arguments.h"
10 #include "src/base/once.h" 10 #include "src/base/once.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 if (index >= length()) { 52 if (index >= length()) {
53 return isolate->factory()->undefined_value(); 53 return isolate->factory()->undefined_value();
54 } 54 }
55 return at<Object>(index); 55 return at<Object>(index);
56 } 56 }
57 57
58 Handle<Object> receiver() { 58 Handle<Object> receiver() {
59 return Arguments::at<Object>(0); 59 return Arguments::at<Object>(0);
60 } 60 }
61 61
62 template <class S> 62 Handle<JSFunction> target();
63 Handle<S> target();
64 Handle<HeapObject> new_target(); 63 Handle<HeapObject> new_target();
65 64
66 // Gets the total number of arguments including the receiver (but 65 // Gets the total number of arguments including the receiver (but
67 // excluding extra arguments). 66 // excluding extra arguments).
68 int length() const; 67 int length() const;
69 }; 68 };
70 69
71 70
72 // Specialize BuiltinArguments for the extra arguments. 71 // Specialize BuiltinArguments for the extra arguments.
73 72
74 template <> 73 template <>
75 int BuiltinArguments<BuiltinExtraArguments::kNone>::length() const { 74 int BuiltinArguments<BuiltinExtraArguments::kNone>::length() const {
76 return Arguments::length(); 75 return Arguments::length();
77 } 76 }
78 77
79 template <> 78 template <>
80 int BuiltinArguments<BuiltinExtraArguments::kTarget>::length() const { 79 int BuiltinArguments<BuiltinExtraArguments::kTarget>::length() const {
81 return Arguments::length() - 1; 80 return Arguments::length() - 1;
82 } 81 }
83 82
84 template <> 83 template <>
85 template <class S> 84 Handle<JSFunction> BuiltinArguments<BuiltinExtraArguments::kTarget>::target() {
86 Handle<S> BuiltinArguments<BuiltinExtraArguments::kTarget>::target() { 85 return Arguments::at<JSFunction>(Arguments::length() - 1);
87 return Arguments::at<S>(Arguments::length() - 1);
88 } 86 }
89 87
90 template <> 88 template <>
91 int BuiltinArguments<BuiltinExtraArguments::kNewTarget>::length() const { 89 int BuiltinArguments<BuiltinExtraArguments::kNewTarget>::length() const {
92 return Arguments::length() - 1; 90 return Arguments::length() - 1;
93 } 91 }
94 92
95 template <> 93 template <>
96 Handle<HeapObject> 94 Handle<HeapObject>
97 BuiltinArguments<BuiltinExtraArguments::kNewTarget>::new_target() { 95 BuiltinArguments<BuiltinExtraArguments::kNewTarget>::new_target() {
98 return Arguments::at<HeapObject>(Arguments::length() - 1); 96 return Arguments::at<HeapObject>(Arguments::length() - 1);
99 } 97 }
100 98
101 template <> 99 template <>
102 int BuiltinArguments<BuiltinExtraArguments::kTargetAndNewTarget>::length() 100 int BuiltinArguments<BuiltinExtraArguments::kTargetAndNewTarget>::length()
103 const { 101 const {
104 return Arguments::length() - 2; 102 return Arguments::length() - 2;
105 } 103 }
106 104
107 template <> 105 template <>
108 template <class S> 106 Handle<JSFunction>
109 Handle<S>
110 BuiltinArguments<BuiltinExtraArguments::kTargetAndNewTarget>::target() { 107 BuiltinArguments<BuiltinExtraArguments::kTargetAndNewTarget>::target() {
111 return Arguments::at<S>(Arguments::length() - 2); 108 return Arguments::at<JSFunction>(Arguments::length() - 2);
112 } 109 }
113 110
114 template <> 111 template <>
115 Handle<HeapObject> 112 Handle<HeapObject>
116 BuiltinArguments<BuiltinExtraArguments::kTargetAndNewTarget>::new_target() { 113 BuiltinArguments<BuiltinExtraArguments::kTargetAndNewTarget>::new_target() {
117 return Arguments::at<HeapObject>(Arguments::length() - 1); 114 return Arguments::at<HeapObject>(Arguments::length() - 1);
118 } 115 }
119 116
120 117
121 #define DEF_ARG_TYPE(name, spec) \ 118 #define DEF_ARG_TYPE(name, spec) \
(...skipping 1813 matching lines...) Expand 10 before | Expand all | Expand 10 after
1935 RelocInfo::kNoPosition); 1932 RelocInfo::kNoPosition);
1936 } 1933 }
1937 1934
1938 } // namespace 1935 } // namespace
1939 1936
1940 1937
1941 // ES6 section 18.2.1 eval (x) 1938 // ES6 section 18.2.1 eval (x)
1942 BUILTIN(GlobalEval) { 1939 BUILTIN(GlobalEval) {
1943 HandleScope scope(isolate); 1940 HandleScope scope(isolate);
1944 Handle<Object> x = args.atOrUndefined(isolate, 1); 1941 Handle<Object> x = args.atOrUndefined(isolate, 1);
1945 Handle<JSFunction> target = args.target<JSFunction>(); 1942 Handle<JSFunction> target = args.target();
1946 Handle<JSObject> target_global_proxy(target->global_proxy(), isolate); 1943 Handle<JSObject> target_global_proxy(target->global_proxy(), isolate);
1947 if (!x->IsString()) return *x; 1944 if (!x->IsString()) return *x;
1948 Handle<JSFunction> function; 1945 Handle<JSFunction> function;
1949 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 1946 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1950 isolate, function, 1947 isolate, function,
1951 CompileString(handle(target->native_context(), isolate), 1948 CompileString(handle(target->native_context(), isolate),
1952 Handle<String>::cast(x), NO_PARSE_RESTRICTION)); 1949 Handle<String>::cast(x), NO_PARSE_RESTRICTION));
1953 Handle<Object> result; 1950 Handle<Object> result;
1954 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 1951 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1955 isolate, result, 1952 isolate, result,
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
2431 Vector<char> str(buffer, arraysize(buffer)); 2428 Vector<char> str(buffer, arraysize(buffer));
2432 ToDateString(time_val, str, isolate->date_cache()); 2429 ToDateString(time_val, str, isolate->date_cache());
2433 return *isolate->factory()->NewStringFromAsciiChecked(str.start()); 2430 return *isolate->factory()->NewStringFromAsciiChecked(str.start());
2434 } 2431 }
2435 2432
2436 2433
2437 // ES6 section 20.3.2 The Date Constructor for the [[Construct]] case. 2434 // ES6 section 20.3.2 The Date Constructor for the [[Construct]] case.
2438 BUILTIN(DateConstructor_ConstructStub) { 2435 BUILTIN(DateConstructor_ConstructStub) {
2439 HandleScope scope(isolate); 2436 HandleScope scope(isolate);
2440 int const argc = args.length() - 1; 2437 int const argc = args.length() - 1;
2441 Handle<JSFunction> target = args.target<JSFunction>(); 2438 Handle<JSFunction> target = args.target();
2442 Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target()); 2439 Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target());
2443 double time_val; 2440 double time_val;
2444 if (argc == 0) { 2441 if (argc == 0) {
2445 time_val = JSDate::CurrentTimeValue(isolate); 2442 time_val = JSDate::CurrentTimeValue(isolate);
2446 } else if (argc == 1) { 2443 } else if (argc == 1) {
2447 Handle<Object> value = args.at<Object>(1); 2444 Handle<Object> value = args.at<Object>(1);
2448 if (value->IsJSDate()) { 2445 if (value->IsJSDate()) {
2449 time_val = Handle<JSDate>::cast(value)->value()->Number(); 2446 time_val = Handle<JSDate>::cast(value)->value()->Number();
2450 } else { 2447 } else {
2451 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, 2448 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value,
(...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after
3315 // conversions are done. 3312 // conversions are done.
3316 if (parenthesis_in_arg_string) { 3313 if (parenthesis_in_arg_string) {
3317 THROW_NEW_ERROR(isolate, 3314 THROW_NEW_ERROR(isolate,
3318 NewSyntaxError(MessageTemplate::kParenthesisInArgString), 3315 NewSyntaxError(MessageTemplate::kParenthesisInArgString),
3319 JSFunction); 3316 JSFunction);
3320 } 3317 }
3321 } 3318 }
3322 3319
3323 // Compile the string in the constructor and not a helper so that errors to 3320 // Compile the string in the constructor and not a helper so that errors to
3324 // come from here. 3321 // come from here.
3325 Handle<JSFunction> target = args.target<JSFunction>(); 3322 Handle<JSFunction> target = args.target();
3326 Handle<JSObject> target_global_proxy(target->global_proxy(), isolate); 3323 Handle<JSObject> target_global_proxy(target->global_proxy(), isolate);
3327 Handle<JSFunction> function; 3324 Handle<JSFunction> function;
3328 { 3325 {
3329 ASSIGN_RETURN_ON_EXCEPTION( 3326 ASSIGN_RETURN_ON_EXCEPTION(
3330 isolate, function, 3327 isolate, function,
3331 CompileString(handle(target->native_context(), isolate), source, 3328 CompileString(handle(target->native_context(), isolate), source,
3332 ONLY_SINGLE_FUNCTION_LITERAL), 3329 ONLY_SINGLE_FUNCTION_LITERAL),
3333 JSFunction); 3330 JSFunction);
3334 Handle<Object> result; 3331 Handle<Object> result;
3335 ASSIGN_RETURN_ON_EXCEPTION( 3332 ASSIGN_RETURN_ON_EXCEPTION(
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
3500 Handle<String> result; 3497 Handle<String> result;
3501 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 3498 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
3502 isolate, result, JSObject::ObjectProtoToString(isolate, object)); 3499 isolate, result, JSObject::ObjectProtoToString(isolate, object));
3503 return *result; 3500 return *result;
3504 } 3501 }
3505 3502
3506 3503
3507 // ES6 section 24.1.2.1 ArrayBuffer ( length ) for the [[Call]] case. 3504 // ES6 section 24.1.2.1 ArrayBuffer ( length ) for the [[Call]] case.
3508 BUILTIN(ArrayBufferConstructor) { 3505 BUILTIN(ArrayBufferConstructor) {
3509 HandleScope scope(isolate); 3506 HandleScope scope(isolate);
3510 Handle<JSFunction> target = args.target<JSFunction>(); 3507 Handle<JSFunction> target = args.target();
3511 DCHECK(*target == target->native_context()->array_buffer_fun() || 3508 DCHECK(*target == target->native_context()->array_buffer_fun() ||
3512 *target == target->native_context()->shared_array_buffer_fun()); 3509 *target == target->native_context()->shared_array_buffer_fun());
3513 THROW_NEW_ERROR_RETURN_FAILURE( 3510 THROW_NEW_ERROR_RETURN_FAILURE(
3514 isolate, NewTypeError(MessageTemplate::kConstructorNotFunction, 3511 isolate, NewTypeError(MessageTemplate::kConstructorNotFunction,
3515 handle(target->shared()->name(), isolate))); 3512 handle(target->shared()->name(), isolate)));
3516 } 3513 }
3517 3514
3518 3515
3519 // ES6 section 24.1.2.1 ArrayBuffer ( length ) for the [[Construct]] case. 3516 // ES6 section 24.1.2.1 ArrayBuffer ( length ) for the [[Construct]] case.
3520 BUILTIN(ArrayBufferConstructor_ConstructStub) { 3517 BUILTIN(ArrayBufferConstructor_ConstructStub) {
3521 HandleScope scope(isolate); 3518 HandleScope scope(isolate);
3522 Handle<JSFunction> target = args.target<JSFunction>(); 3519 Handle<JSFunction> target = args.target();
3523 Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target()); 3520 Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target());
3524 Handle<Object> length = args.atOrUndefined(isolate, 1); 3521 Handle<Object> length = args.atOrUndefined(isolate, 1);
3525 DCHECK(*target == target->native_context()->array_buffer_fun() || 3522 DCHECK(*target == target->native_context()->array_buffer_fun() ||
3526 *target == target->native_context()->shared_array_buffer_fun()); 3523 *target == target->native_context()->shared_array_buffer_fun());
3527 Handle<Object> number_length; 3524 Handle<Object> number_length;
3528 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, number_length, 3525 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, number_length,
3529 Object::ToInteger(isolate, length)); 3526 Object::ToInteger(isolate, length));
3530 if (number_length->Number() < 0.0) { 3527 if (number_length->Number() < 0.0) {
3531 THROW_NEW_ERROR_RETURN_FAILURE( 3528 THROW_NEW_ERROR_RETURN_FAILURE(
3532 isolate, NewRangeError(MessageTemplate::kInvalidArrayBufferLength)); 3529 isolate, NewRangeError(MessageTemplate::kInvalidArrayBufferLength));
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
3609 // ----------------------------------------------------------------------------- 3606 // -----------------------------------------------------------------------------
3610 // 3607 //
3611 3608
3612 3609
3613 namespace { 3610 namespace {
3614 3611
3615 template <bool is_construct> 3612 template <bool is_construct>
3616 MUST_USE_RESULT MaybeHandle<Object> HandleApiCallHelper( 3613 MUST_USE_RESULT MaybeHandle<Object> HandleApiCallHelper(
3617 Isolate* isolate, BuiltinArguments<BuiltinExtraArguments::kTarget> args) { 3614 Isolate* isolate, BuiltinArguments<BuiltinExtraArguments::kTarget> args) {
3618 HandleScope scope(isolate); 3615 HandleScope scope(isolate);
3619 Handle<HeapObject> function = args.target<HeapObject>(); 3616 Handle<JSFunction> function = args.target();
3620 Handle<JSReceiver> receiver; 3617 Handle<JSReceiver> receiver;
3621 // TODO(ishell): turn this back to a DCHECK. 3618 // TODO(ishell): turn this back to a DCHECK.
3622 CHECK(function->IsFunctionTemplateInfo() || 3619 CHECK(function->shared()->IsApiFunction());
3623 Handle<JSFunction>::cast(function)->shared()->IsApiFunction());
3624 3620
3625 Handle<FunctionTemplateInfo> fun_data = 3621 Handle<FunctionTemplateInfo> fun_data(
3626 function->IsFunctionTemplateInfo() 3622 function->shared()->get_api_func_data(), isolate);
3627 ? Handle<FunctionTemplateInfo>::cast(function)
3628 : handle(JSFunction::cast(*function)->shared()->get_api_func_data());
3629 if (is_construct) { 3623 if (is_construct) {
3630 DCHECK(args.receiver()->IsTheHole()); 3624 DCHECK(args.receiver()->IsTheHole());
3631 if (fun_data->instance_template()->IsUndefined()) { 3625 if (fun_data->instance_template()->IsUndefined()) {
3632 v8::Local<ObjectTemplate> templ = 3626 v8::Local<ObjectTemplate> templ =
3633 ObjectTemplate::New(reinterpret_cast<v8::Isolate*>(isolate), 3627 ObjectTemplate::New(reinterpret_cast<v8::Isolate*>(isolate),
3634 ToApiHandle<v8::FunctionTemplate>(fun_data)); 3628 ToApiHandle<v8::FunctionTemplate>(fun_data));
3635 fun_data->set_instance_template(*Utils::OpenHandle(*templ)); 3629 fun_data->set_instance_template(*Utils::OpenHandle(*templ));
3636 } 3630 }
3637 Handle<ObjectTemplateInfo> instance_template( 3631 Handle<ObjectTemplateInfo> instance_template(
3638 ObjectTemplateInfo::cast(fun_data->instance_template()), isolate); 3632 ObjectTemplateInfo::cast(fun_data->instance_template()), isolate);
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
3805 if (length() == 0) return; 3799 if (length() == 0) return;
3806 v->VisitPointers(lowest_address(), highest_address() + 1); 3800 v->VisitPointers(lowest_address(), highest_address() + 1);
3807 } 3801 }
3808 3802
3809 private: 3803 private:
3810 DISALLOW_COPY_AND_ASSIGN(RelocatableArguments); 3804 DISALLOW_COPY_AND_ASSIGN(RelocatableArguments);
3811 }; 3805 };
3812 3806
3813 } // namespace 3807 } // namespace
3814 3808
3815 MaybeHandle<Object> Builtins::InvokeApiFunction(Handle<HeapObject> function, 3809
3810 MaybeHandle<Object> Builtins::InvokeApiFunction(Handle<JSFunction> function,
3816 Handle<Object> receiver, 3811 Handle<Object> receiver,
3817 int argc, 3812 int argc,
3818 Handle<Object> args[]) { 3813 Handle<Object> args[]) {
3819 // Construct BuiltinArguments object: function, arguments reversed, receiver. 3814 // Construct BuiltinArguments object: function, arguments reversed, receiver.
3820 const int kBufferSize = 32; 3815 const int kBufferSize = 32;
3821 Object* small_argv[kBufferSize]; 3816 Object* small_argv[kBufferSize];
3822 Object** argv; 3817 Object** argv;
3823 if (argc + 2 <= kBufferSize) { 3818 if (argc + 2 <= kBufferSize) {
3824 argv = small_argv; 3819 argv = small_argv;
3825 } else { 3820 } else {
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
4262 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) 4257 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C)
4263 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) 4258 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A)
4264 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) 4259 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H)
4265 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) 4260 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A)
4266 #undef DEFINE_BUILTIN_ACCESSOR_C 4261 #undef DEFINE_BUILTIN_ACCESSOR_C
4267 #undef DEFINE_BUILTIN_ACCESSOR_A 4262 #undef DEFINE_BUILTIN_ACCESSOR_A
4268 4263
4269 4264
4270 } // namespace internal 4265 } // namespace internal
4271 } // namespace v8 4266 } // namespace v8
OLDNEW
« no previous file with comments | « src/builtins.h ('k') | src/code-stubs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698