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

Side by Side Diff: src/runtime/runtime-object.cc

Issue 1427483002: [es6] Better support for built-ins subclassing. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Avoid crashes in case of Function subclassing Created 5 years, 1 month 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/objects-printer.cc ('k') | src/runtime/runtime-typedarray.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 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/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/bootstrapper.h" 8 #include "src/bootstrapper.h"
9 #include "src/debug/debug.h" 9 #include "src/debug/debug.h"
10 #include "src/isolate-inl.h" 10 #include "src/isolate-inl.h"
(...skipping 974 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 // Check that function is a constructor. 985 // Check that function is a constructor.
986 if (!function->IsConstructor()) { 986 if (!function->IsConstructor()) {
987 THROW_NEW_ERROR_RETURN_FAILURE( 987 THROW_NEW_ERROR_RETURN_FAILURE(
988 isolate, NewTypeError(MessageTemplate::kNotConstructor, constructor)); 988 isolate, NewTypeError(MessageTemplate::kNotConstructor, constructor));
989 } 989 }
990 990
991 Debug* debug = isolate->debug(); 991 Debug* debug = isolate->debug();
992 // Handle stepping into constructors if step into is active. 992 // Handle stepping into constructors if step into is active.
993 if (debug->StepInActive()) debug->HandleStepIn(function, true); 993 if (debug->StepInActive()) debug->HandleStepIn(function, true);
994 994
995 if (function->has_initial_map()) { 995 if (function->has_initial_map() && original_function->has_initial_map()) {
Toon Verwaest 2015/10/29 12:54:46 Do we still need this additional special case now
Igor Sheludko 2015/10/29 15:26:22 Done.
996 if (function->initial_map()->instance_type() == JS_FUNCTION_TYPE) { 996 if (function->initial_map()->instance_type() == JS_FUNCTION_TYPE) {
997 // The 'Function' function ignores the receiver object when 997 // The 'Function' function ignores the receiver object when
998 // called using 'new' and creates a new JSFunction object that 998 // called using 'new' and creates a new JSFunction object that
999 // is returned. The receiver object is only used for error 999 // is returned. The receiver object is only used for error
1000 // reporting if an error occurs when constructing the new 1000 // reporting if an error occurs when constructing the new
1001 // JSFunction. Factory::NewJSObject() should not be used to 1001 // JSFunction. Factory::NewJSObject() should not be used to
1002 // allocate JSFunctions since it does not properly initialize 1002 // allocate JSFunctions since it does not properly initialize
1003 // the shared part of the function. Since the receiver is 1003 // the shared part of the function. Since the receiver is
1004 // ignored anyway, we use the global object as the receiver 1004 // ignored anyway, we use the global object as the receiver
1005 // instead of a new JSFunction object. This way, errors are 1005 // instead of a new JSFunction object. This way, errors are
1006 // reported the same way whether or not 'Function' is called 1006 // reported the same way whether or not 'Function' is called
1007 // using 'new'. 1007 // using 'new'.
1008 return isolate->global_proxy(); 1008 return isolate->global_proxy();
1009 } 1009 }
1010 } 1010 }
1011 1011
1012 // The function should be compiled for the optimization hints to be 1012 // The function should be compiled for the optimization hints to be
1013 // available. 1013 // available.
1014 Compiler::Compile(function, CLEAR_EXCEPTION); 1014 Compiler::Compile(function, CLEAR_EXCEPTION);
1015 1015
1016 Handle<JSObject> result; 1016 JSFunction::EnsureHasInitialMap(function);
1017 if (site.is_null()) { 1017 Handle<Map> initial_map =
1018 result = isolate->factory()->NewJSObject(function); 1018 JSFunction::EnsureDerivedHasInitialMap(original_function, function);
1019 } else { 1019
1020 result = isolate->factory()->NewJSObjectWithMemento(function, site); 1020 if (initial_map->instance_type() == JS_FUNCTION_TYPE) {
1021 return isolate->global_proxy();
1021 } 1022 }
1022 1023
1023 // Set up the prototoype using original function. 1024 Handle<JSObject> result =
1024 // TODO(dslomov): instead of setting the __proto__, 1025 isolate->factory()->NewJSObjectFromMap(initial_map, NOT_TENURED, site);
1025 // use and cache the correct map.
1026 if (*original_function != *function) {
1027 if (original_function->has_instance_prototype()) {
1028 Handle<Object> prototype =
1029 handle(original_function->instance_prototype(), isolate);
1030 MAYBE_RETURN(JSObject::SetPrototype(result, prototype, false,
1031 Object::THROW_ON_ERROR),
1032 isolate->heap()->exception());
1033 }
1034 }
1035 1026
1036 isolate->counters()->constructed_objects()->Increment(); 1027 isolate->counters()->constructed_objects()->Increment();
1037 isolate->counters()->constructed_objects_runtime()->Increment(); 1028 isolate->counters()->constructed_objects_runtime()->Increment();
1038 1029
1039 return *result; 1030 return *result;
1040 } 1031 }
1041 1032
1042 1033
1043 RUNTIME_FUNCTION(Runtime_NewObject) { 1034 RUNTIME_FUNCTION(Runtime_NewObject) {
1044 HandleScope scope(isolate); 1035 HandleScope scope(isolate);
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
1574 1565
1575 RUNTIME_FUNCTION(Runtime_ObjectDefineProperties) { 1566 RUNTIME_FUNCTION(Runtime_ObjectDefineProperties) {
1576 HandleScope scope(isolate); 1567 HandleScope scope(isolate);
1577 DCHECK(args.length() == 2); 1568 DCHECK(args.length() == 2);
1578 CONVERT_ARG_HANDLE_CHECKED(Object, o, 0); 1569 CONVERT_ARG_HANDLE_CHECKED(Object, o, 0);
1579 CONVERT_ARG_HANDLE_CHECKED(Object, properties, 1); 1570 CONVERT_ARG_HANDLE_CHECKED(Object, properties, 1);
1580 return JSReceiver::DefineProperties(isolate, o, properties); 1571 return JSReceiver::DefineProperties(isolate, o, properties);
1581 } 1572 }
1582 } // namespace internal 1573 } // namespace internal
1583 } // namespace v8 1574 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects-printer.cc ('k') | src/runtime/runtime-typedarray.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698