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

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

Issue 1413033006: Reland "[es6] Better support for built-ins subclassing." (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: We don't need TypedArray map smashing anymore 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 973 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 // Check that function is a constructor. 984 // Check that function is a constructor.
985 if (!function->IsConstructor()) { 985 if (!function->IsConstructor()) {
986 THROW_NEW_ERROR_RETURN_FAILURE( 986 THROW_NEW_ERROR_RETURN_FAILURE(
987 isolate, NewTypeError(MessageTemplate::kNotConstructor, constructor)); 987 isolate, NewTypeError(MessageTemplate::kNotConstructor, constructor));
988 } 988 }
989 989
990 Debug* debug = isolate->debug(); 990 Debug* debug = isolate->debug();
991 // Handle stepping into constructors if step into is active. 991 // Handle stepping into constructors if step into is active.
992 if (debug->StepInActive()) debug->HandleStepIn(function, true); 992 if (debug->StepInActive()) debug->HandleStepIn(function, true);
993 993
994 if (function->has_initial_map()) {
995 if (function->initial_map()->instance_type() == JS_FUNCTION_TYPE) {
996 // The 'Function' function ignores the receiver object when
997 // called using 'new' and creates a new JSFunction object that
998 // is returned. The receiver object is only used for error
999 // reporting if an error occurs when constructing the new
1000 // JSFunction. Factory::NewJSObject() should not be used to
1001 // allocate JSFunctions since it does not properly initialize
1002 // the shared part of the function. Since the receiver is
1003 // ignored anyway, we use the global object as the receiver
1004 // instead of a new JSFunction object. This way, errors are
1005 // reported the same way whether or not 'Function' is called
1006 // using 'new'.
1007 return isolate->global_proxy();
1008 }
1009 }
1010
1011 // The function should be compiled for the optimization hints to be 994 // The function should be compiled for the optimization hints to be
1012 // available. 995 // available.
1013 Compiler::Compile(function, CLEAR_EXCEPTION); 996 Compiler::Compile(function, CLEAR_EXCEPTION);
1014 997
1015 Handle<JSObject> result; 998 JSFunction::EnsureHasInitialMap(function);
1016 if (site.is_null()) { 999 Handle<Map> initial_map =
1017 result = isolate->factory()->NewJSObject(function); 1000 JSFunction::EnsureDerivedHasInitialMap(original_function, function);
1018 } else { 1001
1019 result = isolate->factory()->NewJSObjectWithMemento(function, site); 1002 if (initial_map->instance_type() == JS_FUNCTION_TYPE) {
1003 // The 'Function' function ignores the receiver object when
1004 // called using 'new' and creates a new JSFunction object that
1005 // is returned. The receiver object is only used for error
1006 // reporting if an error occurs when constructing the new
1007 // JSFunction. Factory::NewJSObject() should not be used to
1008 // allocate JSFunctions since it does not properly initialize
1009 // the shared part of the function. Since the receiver is
1010 // ignored anyway, we use the global object as the receiver
1011 // instead of a new JSFunction object. This way, errors are
1012 // reported the same way whether or not 'Function' is called
1013 // using 'new'.
1014 return isolate->global_proxy();
1020 } 1015 }
1021 1016
1022 // Set up the prototoype using original function. 1017 Handle<JSObject> result =
1023 // TODO(dslomov): instead of setting the __proto__, 1018 isolate->factory()->NewJSObjectFromMap(initial_map, NOT_TENURED, site);
1024 // use and cache the correct map.
1025 if (*original_function != *function) {
1026 if (original_function->has_instance_prototype()) {
1027 Handle<Object> prototype =
1028 handle(original_function->instance_prototype(), isolate);
1029 MAYBE_RETURN(JSObject::SetPrototype(result, prototype, false,
1030 Object::THROW_ON_ERROR),
1031 isolate->heap()->exception());
1032 }
1033 }
1034 1019
1035 isolate->counters()->constructed_objects()->Increment(); 1020 isolate->counters()->constructed_objects()->Increment();
1036 isolate->counters()->constructed_objects_runtime()->Increment(); 1021 isolate->counters()->constructed_objects_runtime()->Increment();
1037 1022
1038 return *result; 1023 return *result;
1039 } 1024 }
1040 1025
1041 1026
1042 RUNTIME_FUNCTION(Runtime_NewObject) { 1027 RUNTIME_FUNCTION(Runtime_NewObject) {
1043 HandleScope scope(isolate); 1028 HandleScope scope(isolate);
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
1573 1558
1574 RUNTIME_FUNCTION(Runtime_ObjectDefineProperties) { 1559 RUNTIME_FUNCTION(Runtime_ObjectDefineProperties) {
1575 HandleScope scope(isolate); 1560 HandleScope scope(isolate);
1576 DCHECK(args.length() == 2); 1561 DCHECK(args.length() == 2);
1577 CONVERT_ARG_HANDLE_CHECKED(Object, o, 0); 1562 CONVERT_ARG_HANDLE_CHECKED(Object, o, 0);
1578 CONVERT_ARG_HANDLE_CHECKED(Object, properties, 1); 1563 CONVERT_ARG_HANDLE_CHECKED(Object, properties, 1);
1579 return JSReceiver::DefineProperties(isolate, o, properties); 1564 return JSReceiver::DefineProperties(isolate, o, properties);
1580 } 1565 }
1581 } // namespace internal 1566 } // namespace internal
1582 } // namespace v8 1567 } // 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