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

Side by Side Diff: src/builtins/builtins.cc

Issue 2151843002: Revert of Reland "Don't compile functions in a context the caller doesn't have access to" (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 5 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 | « include/v8.h ('k') | src/flag-definitions.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/builtins.h" 5 #include "src/builtins/builtins.h"
6 6
7 #include "src/api-arguments.h" 7 #include "src/api-arguments.h"
8 #include "src/api-natives.h" 8 #include "src/api-natives.h"
9 #include "src/api.h" 9 #include "src/api.h"
10 #include "src/base/ieee754.h" 10 #include "src/base/ieee754.h"
(...skipping 4597 matching lines...) Expand 10 before | Expand all | Expand 10 after
4608 } 4608 }
4609 4609
4610 // static 4610 // static
4611 void Builtins::Generate_DatePrototypeGetUTCSeconds(MacroAssembler* masm) { 4611 void Builtins::Generate_DatePrototypeGetUTCSeconds(MacroAssembler* masm) {
4612 Generate_DatePrototype_GetField(masm, JSDate::kSecondUTC); 4612 Generate_DatePrototype_GetField(masm, JSDate::kSecondUTC);
4613 } 4613 }
4614 4614
4615 namespace { 4615 namespace {
4616 4616
4617 // ES6 section 19.2.1.1.1 CreateDynamicFunction 4617 // ES6 section 19.2.1.1.1 CreateDynamicFunction
4618 MaybeHandle<Object> CreateDynamicFunction(Isolate* isolate, 4618 MaybeHandle<JSFunction> CreateDynamicFunction(Isolate* isolate,
4619 BuiltinArguments args, 4619 BuiltinArguments args,
4620 const char* token) { 4620 const char* token) {
4621 // Compute number of arguments, ignoring the receiver. 4621 // Compute number of arguments, ignoring the receiver.
4622 DCHECK_LE(1, args.length()); 4622 DCHECK_LE(1, args.length());
4623 int const argc = args.length() - 1; 4623 int const argc = args.length() - 1;
4624 4624
4625 Handle<JSFunction> target = args.target<JSFunction>();
4626 Handle<JSObject> target_global_proxy(target->global_proxy(), isolate);
4627
4628 HandleScopeImplementer* impl = isolate->handle_scope_implementer();
4629 if (!FLAG_allow_unsafe_function_constructor &&
4630 !impl->LastEnteredContext().is_null() &&
4631 *impl->LastEnteredContext() != target->context() &&
4632 !isolate->MayAccess(impl->LastEnteredContext(), target_global_proxy)) {
4633 isolate->CountUsage(v8::Isolate::kFunctionConstructorReturnedUndefined);
4634 return isolate->factory()->undefined_value();
4635 }
4636
4637 // Build the source string. 4625 // Build the source string.
4638 Handle<String> source; 4626 Handle<String> source;
4639 { 4627 {
4640 IncrementalStringBuilder builder(isolate); 4628 IncrementalStringBuilder builder(isolate);
4641 builder.AppendCharacter('('); 4629 builder.AppendCharacter('(');
4642 builder.AppendCString(token); 4630 builder.AppendCString(token);
4643 builder.AppendCharacter('('); 4631 builder.AppendCharacter('(');
4644 bool parenthesis_in_arg_string = false; 4632 bool parenthesis_in_arg_string = false;
4645 if (argc > 1) { 4633 if (argc > 1) {
4646 for (int i = 1; i < argc; ++i) { 4634 for (int i = 1; i < argc; ++i) {
4647 if (i > 1) builder.AppendCharacter(','); 4635 if (i > 1) builder.AppendCharacter(',');
4648 Handle<String> param; 4636 Handle<String> param;
4649 ASSIGN_RETURN_ON_EXCEPTION( 4637 ASSIGN_RETURN_ON_EXCEPTION(
4650 isolate, param, Object::ToString(isolate, args.at<Object>(i)), 4638 isolate, param, Object::ToString(isolate, args.at<Object>(i)),
4651 Object); 4639 JSFunction);
4652 param = String::Flatten(param); 4640 param = String::Flatten(param);
4653 builder.AppendString(param); 4641 builder.AppendString(param);
4654 // If the formal parameters string include ) - an illegal 4642 // If the formal parameters string include ) - an illegal
4655 // character - it may make the combined function expression 4643 // character - it may make the combined function expression
4656 // compile. We avoid this problem by checking for this early on. 4644 // compile. We avoid this problem by checking for this early on.
4657 DisallowHeapAllocation no_gc; // Ensure vectors stay valid. 4645 DisallowHeapAllocation no_gc; // Ensure vectors stay valid.
4658 String::FlatContent param_content = param->GetFlatContent(); 4646 String::FlatContent param_content = param->GetFlatContent();
4659 for (int i = 0, length = param->length(); i < length; ++i) { 4647 for (int i = 0, length = param->length(); i < length; ++i) {
4660 if (param_content.Get(i) == ')') { 4648 if (param_content.Get(i) == ')') {
4661 parenthesis_in_arg_string = true; 4649 parenthesis_in_arg_string = true;
4662 break; 4650 break;
4663 } 4651 }
4664 } 4652 }
4665 } 4653 }
4666 // If the formal parameters include an unbalanced block comment, the 4654 // If the formal parameters include an unbalanced block comment, the
4667 // function must be rejected. Since JavaScript does not allow nested 4655 // function must be rejected. Since JavaScript does not allow nested
4668 // comments we can include a trailing block comment to catch this. 4656 // comments we can include a trailing block comment to catch this.
4669 builder.AppendCString("\n/**/"); 4657 builder.AppendCString("\n/**/");
4670 } 4658 }
4671 builder.AppendCString(") {\n"); 4659 builder.AppendCString(") {\n");
4672 if (argc > 0) { 4660 if (argc > 0) {
4673 Handle<String> body; 4661 Handle<String> body;
4674 ASSIGN_RETURN_ON_EXCEPTION( 4662 ASSIGN_RETURN_ON_EXCEPTION(
4675 isolate, body, Object::ToString(isolate, args.at<Object>(argc)), 4663 isolate, body, Object::ToString(isolate, args.at<Object>(argc)),
4676 Object); 4664 JSFunction);
4677 builder.AppendString(body); 4665 builder.AppendString(body);
4678 } 4666 }
4679 builder.AppendCString("\n})"); 4667 builder.AppendCString("\n})");
4680 ASSIGN_RETURN_ON_EXCEPTION(isolate, source, builder.Finish(), Object); 4668 ASSIGN_RETURN_ON_EXCEPTION(isolate, source, builder.Finish(), JSFunction);
4681 4669
4682 // The SyntaxError must be thrown after all the (observable) ToString 4670 // The SyntaxError must be thrown after all the (observable) ToString
4683 // conversions are done. 4671 // conversions are done.
4684 if (parenthesis_in_arg_string) { 4672 if (parenthesis_in_arg_string) {
4685 THROW_NEW_ERROR(isolate, 4673 THROW_NEW_ERROR(isolate,
4686 NewSyntaxError(MessageTemplate::kParenthesisInArgString), 4674 NewSyntaxError(MessageTemplate::kParenthesisInArgString),
4687 Object); 4675 JSFunction);
4688 } 4676 }
4689 } 4677 }
4690 4678
4691 // Compile the string in the constructor and not a helper so that errors to 4679 // Compile the string in the constructor and not a helper so that errors to
4692 // come from here. 4680 // come from here.
4681 Handle<JSFunction> target = args.target<JSFunction>();
4682 Handle<JSObject> target_global_proxy(target->global_proxy(), isolate);
4693 Handle<JSFunction> function; 4683 Handle<JSFunction> function;
4694 { 4684 {
4695 ASSIGN_RETURN_ON_EXCEPTION( 4685 ASSIGN_RETURN_ON_EXCEPTION(
4696 isolate, function, 4686 isolate, function,
4697 CompileString(handle(target->native_context(), isolate), source, 4687 CompileString(handle(target->native_context(), isolate), source,
4698 ONLY_SINGLE_FUNCTION_LITERAL), 4688 ONLY_SINGLE_FUNCTION_LITERAL),
4699 Object); 4689 JSFunction);
4700 Handle<Object> result; 4690 Handle<Object> result;
4701 ASSIGN_RETURN_ON_EXCEPTION( 4691 ASSIGN_RETURN_ON_EXCEPTION(
4702 isolate, result, 4692 isolate, result,
4703 Execution::Call(isolate, function, target_global_proxy, 0, nullptr), 4693 Execution::Call(isolate, function, target_global_proxy, 0, nullptr),
4704 Object); 4694 JSFunction);
4705 function = Handle<JSFunction>::cast(result); 4695 function = Handle<JSFunction>::cast(result);
4706 function->shared()->set_name_should_print_as_anonymous(true); 4696 function->shared()->set_name_should_print_as_anonymous(true);
4707 } 4697 }
4708 4698
4709 // If new.target is equal to target then the function created 4699 // If new.target is equal to target then the function created
4710 // is already correctly setup and nothing else should be done 4700 // is already correctly setup and nothing else should be done
4711 // here. But if new.target is not equal to target then we are 4701 // here. But if new.target is not equal to target then we are
4712 // have a Function builtin subclassing case and therefore the 4702 // have a Function builtin subclassing case and therefore the
4713 // function has wrong initial map. To fix that we create a new 4703 // function has wrong initial map. To fix that we create a new
4714 // function object with correct initial map. 4704 // function object with correct initial map.
4715 Handle<Object> unchecked_new_target = args.new_target(); 4705 Handle<Object> unchecked_new_target = args.new_target();
4716 if (!unchecked_new_target->IsUndefined(isolate) && 4706 if (!unchecked_new_target->IsUndefined(isolate) &&
4717 !unchecked_new_target.is_identical_to(target)) { 4707 !unchecked_new_target.is_identical_to(target)) {
4718 Handle<JSReceiver> new_target = 4708 Handle<JSReceiver> new_target =
4719 Handle<JSReceiver>::cast(unchecked_new_target); 4709 Handle<JSReceiver>::cast(unchecked_new_target);
4720 Handle<Map> initial_map; 4710 Handle<Map> initial_map;
4721 ASSIGN_RETURN_ON_EXCEPTION( 4711 ASSIGN_RETURN_ON_EXCEPTION(
4722 isolate, initial_map, 4712 isolate, initial_map,
4723 JSFunction::GetDerivedMap(isolate, target, new_target), Object); 4713 JSFunction::GetDerivedMap(isolate, target, new_target), JSFunction);
4724 4714
4725 Handle<SharedFunctionInfo> shared_info(function->shared(), isolate); 4715 Handle<SharedFunctionInfo> shared_info(function->shared(), isolate);
4726 Handle<Map> map = Map::AsLanguageMode( 4716 Handle<Map> map = Map::AsLanguageMode(
4727 initial_map, shared_info->language_mode(), shared_info->kind()); 4717 initial_map, shared_info->language_mode(), shared_info->kind());
4728 4718
4729 Handle<Context> context(function->context(), isolate); 4719 Handle<Context> context(function->context(), isolate);
4730 function = isolate->factory()->NewFunctionFromSharedFunctionInfo( 4720 function = isolate->factory()->NewFunctionFromSharedFunctionInfo(
4731 map, shared_info, context, NOT_TENURED); 4721 map, shared_info, context, NOT_TENURED);
4732 } 4722 }
4733 return function; 4723 return function;
4734 } 4724 }
4735 4725
4736 } // namespace 4726 } // namespace
4737 4727
4738 // ES6 section 19.2.1.1 Function ( p1, p2, ... , pn, body ) 4728 // ES6 section 19.2.1.1 Function ( p1, p2, ... , pn, body )
4739 BUILTIN(FunctionConstructor) { 4729 BUILTIN(FunctionConstructor) {
4740 HandleScope scope(isolate); 4730 HandleScope scope(isolate);
4741 Handle<Object> result; 4731 Handle<JSFunction> result;
4742 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 4732 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
4743 isolate, result, CreateDynamicFunction(isolate, args, "function")); 4733 isolate, result, CreateDynamicFunction(isolate, args, "function"));
4744 return *result; 4734 return *result;
4745 } 4735 }
4746 4736
4747 namespace { 4737 namespace {
4748 4738
4749 Object* DoFunctionBind(Isolate* isolate, BuiltinArguments args) { 4739 Object* DoFunctionBind(Isolate* isolate, BuiltinArguments args) {
4750 HandleScope scope(isolate); 4740 HandleScope scope(isolate);
4751 DCHECK_LE(1, args.length()); 4741 DCHECK_LE(1, args.length());
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
4863 4853
4864 // ES6 section 25.2.1.1 GeneratorFunction (p1, p2, ... , pn, body) 4854 // ES6 section 25.2.1.1 GeneratorFunction (p1, p2, ... , pn, body)
4865 BUILTIN(GeneratorFunctionConstructor) { 4855 BUILTIN(GeneratorFunctionConstructor) {
4866 HandleScope scope(isolate); 4856 HandleScope scope(isolate);
4867 RETURN_RESULT_OR_FAILURE(isolate, 4857 RETURN_RESULT_OR_FAILURE(isolate,
4868 CreateDynamicFunction(isolate, args, "function*")); 4858 CreateDynamicFunction(isolate, args, "function*"));
4869 } 4859 }
4870 4860
4871 BUILTIN(AsyncFunctionConstructor) { 4861 BUILTIN(AsyncFunctionConstructor) {
4872 HandleScope scope(isolate); 4862 HandleScope scope(isolate);
4873 Handle<Object> maybe_func; 4863 Handle<JSFunction> func;
4874 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 4864 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
4875 isolate, maybe_func, 4865 isolate, func, CreateDynamicFunction(isolate, args, "async function"));
4876 CreateDynamicFunction(isolate, args, "async function"));
4877 if (!maybe_func->IsJSFunction()) return *maybe_func;
4878 4866
4879 // Do not lazily compute eval position for AsyncFunction, as they may not be 4867 // Do not lazily compute eval position for AsyncFunction, as they may not be
4880 // determined after the function is resumed. 4868 // determined after the function is resumed.
4881 Handle<JSFunction> func = Handle<JSFunction>::cast(maybe_func);
4882 Handle<Script> script = handle(Script::cast(func->shared()->script())); 4869 Handle<Script> script = handle(Script::cast(func->shared()->script()));
4883 int position = script->GetEvalPosition(); 4870 int position = script->GetEvalPosition();
4884 USE(position); 4871 USE(position);
4885 4872
4886 return *func; 4873 return *func;
4887 } 4874 }
4888 4875
4889 // ----------------------------------------------------------------------------- 4876 // -----------------------------------------------------------------------------
4890 // ES6 section 19.1 Object Objects 4877 // ES6 section 19.1 Object Objects
4891 4878
(...skipping 1783 matching lines...) Expand 10 before | Expand all | Expand 10 after
6675 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) 6662 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H)
6676 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) 6663 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A)
6677 #undef DEFINE_BUILTIN_ACCESSOR_C 6664 #undef DEFINE_BUILTIN_ACCESSOR_C
6678 #undef DEFINE_BUILTIN_ACCESSOR_A 6665 #undef DEFINE_BUILTIN_ACCESSOR_A
6679 #undef DEFINE_BUILTIN_ACCESSOR_T 6666 #undef DEFINE_BUILTIN_ACCESSOR_T
6680 #undef DEFINE_BUILTIN_ACCESSOR_S 6667 #undef DEFINE_BUILTIN_ACCESSOR_S
6681 #undef DEFINE_BUILTIN_ACCESSOR_H 6668 #undef DEFINE_BUILTIN_ACCESSOR_H
6682 6669
6683 } // namespace internal 6670 } // namespace internal
6684 } // namespace v8 6671 } // namespace v8
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/flag-definitions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698