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

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

Issue 1416943005: Revert of [es6] Better support for built-ins subclassing. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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()) {
996 if (function->initial_map()->instance_type() == JS_FUNCTION_TYPE) {
997 // The 'Function' function ignores the receiver object when
998 // called using 'new' and creates a new JSFunction object that
999 // is returned. The receiver object is only used for error
1000 // reporting if an error occurs when constructing the new
1001 // JSFunction. Factory::NewJSObject() should not be used to
1002 // allocate JSFunctions since it does not properly initialize
1003 // the shared part of the function. Since the receiver is
1004 // ignored anyway, we use the global object as the receiver
1005 // instead of a new JSFunction object. This way, errors are
1006 // reported the same way whether or not 'Function' is called
1007 // using 'new'.
1008 return isolate->global_proxy();
1009 }
1010 }
1011
995 // The function should be compiled for the optimization hints to be 1012 // The function should be compiled for the optimization hints to be
996 // available. 1013 // available.
997 Compiler::Compile(function, CLEAR_EXCEPTION); 1014 Compiler::Compile(function, CLEAR_EXCEPTION);
998 1015
999 JSFunction::EnsureHasInitialMap(function); 1016 Handle<JSObject> result;
1000 Handle<Map> initial_map = 1017 if (site.is_null()) {
1001 JSFunction::EnsureDerivedHasInitialMap(original_function, function); 1018 result = isolate->factory()->NewJSObject(function);
1002 1019 } else {
1003 if (initial_map->instance_type() == JS_FUNCTION_TYPE) { 1020 result = isolate->factory()->NewJSObjectWithMemento(function, site);
1004 // The 'Function' function ignores the receiver object when
1005 // called using 'new' and creates a new JSFunction object that
1006 // is returned. The receiver object is only used for error
1007 // reporting if an error occurs when constructing the new
1008 // JSFunction. Factory::NewJSObject() should not be used to
1009 // allocate JSFunctions since it does not properly initialize
1010 // the shared part of the function. Since the receiver is
1011 // ignored anyway, we use the global object as the receiver
1012 // instead of a new JSFunction object. This way, errors are
1013 // reported the same way whether or not 'Function' is called
1014 // using 'new'.
1015 return isolate->global_proxy();
1016 } 1021 }
1017 1022
1018 Handle<JSObject> result = 1023 // Set up the prototoype using original function.
1019 isolate->factory()->NewJSObjectFromMap(initial_map, NOT_TENURED, site); 1024 // TODO(dslomov): instead of setting the __proto__,
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 }
1020 1035
1021 isolate->counters()->constructed_objects()->Increment(); 1036 isolate->counters()->constructed_objects()->Increment();
1022 isolate->counters()->constructed_objects_runtime()->Increment(); 1037 isolate->counters()->constructed_objects_runtime()->Increment();
1023 1038
1024 return *result; 1039 return *result;
1025 } 1040 }
1026 1041
1027 1042
1028 RUNTIME_FUNCTION(Runtime_NewObject) { 1043 RUNTIME_FUNCTION(Runtime_NewObject) {
1029 HandleScope scope(isolate); 1044 HandleScope scope(isolate);
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
1559 1574
1560 RUNTIME_FUNCTION(Runtime_ObjectDefineProperties) { 1575 RUNTIME_FUNCTION(Runtime_ObjectDefineProperties) {
1561 HandleScope scope(isolate); 1576 HandleScope scope(isolate);
1562 DCHECK(args.length() == 2); 1577 DCHECK(args.length() == 2);
1563 CONVERT_ARG_HANDLE_CHECKED(Object, o, 0); 1578 CONVERT_ARG_HANDLE_CHECKED(Object, o, 0);
1564 CONVERT_ARG_HANDLE_CHECKED(Object, properties, 1); 1579 CONVERT_ARG_HANDLE_CHECKED(Object, properties, 1);
1565 return JSReceiver::DefineProperties(isolate, o, properties); 1580 return JSReceiver::DefineProperties(isolate, o, properties);
1566 } 1581 }
1567 } // namespace internal 1582 } // namespace internal
1568 } // namespace v8 1583 } // 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