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

Side by Side Diff: src/builtins.cc

Issue 1856123005: Convert receiver when calling an Api accessor. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 8 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/execution.cc » ('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-arguments.h" 8 #include "src/api-arguments.h"
9 #include "src/api-natives.h" 9 #include "src/api-natives.h"
10 #include "src/base/once.h" 10 #include "src/base/once.h"
(...skipping 4344 matching lines...) Expand 10 before | Expand all | Expand 10 after
4355 private: 4355 private:
4356 DISALLOW_COPY_AND_ASSIGN(RelocatableArguments); 4356 DISALLOW_COPY_AND_ASSIGN(RelocatableArguments);
4357 }; 4357 };
4358 4358
4359 } // namespace 4359 } // namespace
4360 4360
4361 MaybeHandle<Object> Builtins::InvokeApiFunction(Handle<HeapObject> function, 4361 MaybeHandle<Object> Builtins::InvokeApiFunction(Handle<HeapObject> function,
4362 Handle<Object> receiver, 4362 Handle<Object> receiver,
4363 int argc, 4363 int argc,
4364 Handle<Object> args[]) { 4364 Handle<Object> args[]) {
4365 Isolate* isolate = function->GetIsolate();
4366 // Do proper receiver conversion for non-strict mode api functions.
4367 if (!receiver->IsJSReceiver()) {
4368 DCHECK(function->IsFunctionTemplateInfo() || function->IsJSFunction());
4369 if (function->IsFunctionTemplateInfo() ||
4370 is_sloppy(JSFunction::cast(*function)->shared()->language_mode())) {
4371 if (receiver->IsUndefined() || receiver->IsNull()) {
4372 receiver = handle(isolate->global_proxy(), isolate);
4373 } else {
4374 ASSIGN_RETURN_ON_EXCEPTION(isolate, receiver,
4375 Object::ToObject(isolate, receiver), Object);
4376 }
4377 }
4378 }
4365 // Construct BuiltinArguments object: function, arguments reversed, receiver. 4379 // Construct BuiltinArguments object: function, arguments reversed, receiver.
4366 const int kBufferSize = 32; 4380 const int kBufferSize = 32;
4367 Object* small_argv[kBufferSize]; 4381 Object* small_argv[kBufferSize];
4368 Object** argv; 4382 Object** argv;
4369 if (argc + 2 <= kBufferSize) { 4383 if (argc + 2 <= kBufferSize) {
4370 argv = small_argv; 4384 argv = small_argv;
4371 } else { 4385 } else {
4372 argv = new Object* [argc + 2]; 4386 argv = new Object* [argc + 2];
4373 } 4387 }
4374 argv[argc + 1] = *receiver; 4388 argv[argc + 1] = *receiver;
4375 for (int i = 0; i < argc; ++i) { 4389 for (int i = 0; i < argc; ++i) {
4376 argv[argc - i] = *args[i]; 4390 argv[argc - i] = *args[i];
4377 } 4391 }
4378 argv[0] = *function; 4392 argv[0] = *function;
4379 MaybeHandle<Object> result; 4393 MaybeHandle<Object> result;
4380 { 4394 {
4381 auto isolate = function->GetIsolate();
4382 RelocatableArguments arguments(isolate, argc + 2, &argv[argc + 1]); 4395 RelocatableArguments arguments(isolate, argc + 2, &argv[argc + 1]);
4383 result = HandleApiCallHelper<false>(isolate, arguments); 4396 result = HandleApiCallHelper<false>(isolate, arguments);
4384 } 4397 }
4385 if (argv != small_argv) { 4398 if (argv != small_argv) {
4386 delete[] argv; 4399 delete[] argv;
4387 } 4400 }
4388 return result; 4401 return result;
4389 } 4402 }
4390 4403
4391 4404
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
4841 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) 4854 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T)
4842 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) 4855 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H)
4843 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) 4856 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A)
4844 #undef DEFINE_BUILTIN_ACCESSOR_C 4857 #undef DEFINE_BUILTIN_ACCESSOR_C
4845 #undef DEFINE_BUILTIN_ACCESSOR_A 4858 #undef DEFINE_BUILTIN_ACCESSOR_A
4846 #undef DEFINE_BUILTIN_ACCESSOR_T 4859 #undef DEFINE_BUILTIN_ACCESSOR_T
4847 #undef DEFINE_BUILTIN_ACCESSOR_H 4860 #undef DEFINE_BUILTIN_ACCESSOR_H
4848 4861
4849 } // namespace internal 4862 } // namespace internal
4850 } // namespace v8 4863 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/execution.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698