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

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

Issue 1675223002: Mark maps having a hidden prototype rather than maps of hidden prototypes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressed comment Created 4 years, 10 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 | « src/runtime/runtime-debug.cc ('k') | src/string-stream.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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 151
152 MAYBE_RETURN_NULL(Object::SetProperty(&it, value, language_mode, 152 MAYBE_RETURN_NULL(Object::SetProperty(&it, value, language_mode,
153 Object::MAY_BE_STORE_FROM_KEYED)); 153 Object::MAY_BE_STORE_FROM_KEYED));
154 return value; 154 return value;
155 } 155 }
156 156
157 157
158 RUNTIME_FUNCTION(Runtime_GetPrototype) { 158 RUNTIME_FUNCTION(Runtime_GetPrototype) {
159 HandleScope scope(isolate); 159 HandleScope scope(isolate);
160 DCHECK(args.length() == 1); 160 DCHECK(args.length() == 1);
161 CONVERT_ARG_HANDLE_CHECKED(Object, obj, 0); 161 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, obj, 0);
162 Handle<Object> prototype; 162 Handle<Object> prototype;
163 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, prototype, 163 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, prototype,
164 Object::GetPrototype(isolate, obj)); 164 JSReceiver::GetPrototype(isolate, obj));
165 return *prototype; 165 return *prototype;
166 } 166 }
167 167
168 168
169 RUNTIME_FUNCTION(Runtime_InternalSetPrototype) { 169 RUNTIME_FUNCTION(Runtime_InternalSetPrototype) {
170 HandleScope scope(isolate); 170 HandleScope scope(isolate);
171 DCHECK(args.length() == 2); 171 DCHECK(args.length() == 2);
172 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, obj, 0); 172 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, obj, 0);
173 CONVERT_ARG_HANDLE_CHECKED(Object, prototype, 1); 173 CONVERT_ARG_HANDLE_CHECKED(Object, prototype, 1);
174 MAYBE_RETURN( 174 MAYBE_RETURN(
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 569
570 static Object* HasOwnPropertyImplementation(Isolate* isolate, 570 static Object* HasOwnPropertyImplementation(Isolate* isolate,
571 Handle<JSObject> object, 571 Handle<JSObject> object,
572 Handle<Name> key) { 572 Handle<Name> key) {
573 Maybe<bool> maybe = JSReceiver::HasOwnProperty(object, key); 573 Maybe<bool> maybe = JSReceiver::HasOwnProperty(object, key);
574 if (!maybe.IsJust()) return isolate->heap()->exception(); 574 if (!maybe.IsJust()) return isolate->heap()->exception();
575 if (maybe.FromJust()) return isolate->heap()->true_value(); 575 if (maybe.FromJust()) return isolate->heap()->true_value();
576 // Handle hidden prototypes. If there's a hidden prototype above this thing 576 // Handle hidden prototypes. If there's a hidden prototype above this thing
577 // then we have to check it for properties, because they are supposed to 577 // then we have to check it for properties, because they are supposed to
578 // look like they are on this object. 578 // look like they are on this object.
579 PrototypeIterator iter(isolate, object); 579 if (object->map()->has_hidden_prototype()) {
580 if (!iter.IsAtEnd() && 580 PrototypeIterator iter(isolate, object);
581 PrototypeIterator::GetCurrent<HeapObject>(iter) 581 DCHECK(!iter.IsAtEnd());
582 ->map() 582
583 ->is_hidden_prototype()) {
584 // TODO(verwaest): The recursion is not necessary for keys that are array 583 // TODO(verwaest): The recursion is not necessary for keys that are array
585 // indices. Removing this. 584 // indices. Removing this.
586 // Casting to JSObject is fine because JSProxies are never used as 585 // Casting to JSObject is fine because JSProxies are never used as
587 // hidden prototypes. 586 // hidden prototypes.
588 return HasOwnPropertyImplementation( 587 return HasOwnPropertyImplementation(
589 isolate, PrototypeIterator::GetCurrent<JSObject>(iter), key); 588 isolate, PrototypeIterator::GetCurrent<JSObject>(iter), key);
590 } 589 }
591 RETURN_FAILURE_IF_SCHEDULED_EXCEPTION(isolate); 590 RETURN_FAILURE_IF_SCHEDULED_EXCEPTION(isolate);
592 return isolate->heap()->false_value(); 591 return isolate->heap()->false_value();
593 } 592 }
(...skipping 24 matching lines...) Expand all
618 } else { 617 } else {
619 maybe = JSObject::HasRealNamedProperty(js_obj, key); 618 maybe = JSObject::HasRealNamedProperty(js_obj, key);
620 } 619 }
621 if (!maybe.IsJust()) return isolate->heap()->exception(); 620 if (!maybe.IsJust()) return isolate->heap()->exception();
622 DCHECK(!isolate->has_pending_exception()); 621 DCHECK(!isolate->has_pending_exception());
623 if (maybe.FromJust()) { 622 if (maybe.FromJust()) {
624 return isolate->heap()->true_value(); 623 return isolate->heap()->true_value();
625 } 624 }
626 Map* map = js_obj->map(); 625 Map* map = js_obj->map();
627 if (!key_is_array_index && !map->has_named_interceptor() && 626 if (!key_is_array_index && !map->has_named_interceptor() &&
628 !HeapObject::cast(map->prototype())->map()->is_hidden_prototype()) { 627 !map->has_hidden_prototype()) {
629 return isolate->heap()->false_value(); 628 return isolate->heap()->false_value();
630 } 629 }
631 // Slow case. 630 // Slow case.
632 return HasOwnPropertyImplementation(isolate, Handle<JSObject>(js_obj), 631 return HasOwnPropertyImplementation(isolate, Handle<JSObject>(js_obj),
633 Handle<Name>(key)); 632 Handle<Name>(key));
634 } else if (object->IsString() && key_is_array_index) { 633 } else if (object->IsString() && key_is_array_index) {
635 // Well, there is one exception: Handle [] on strings. 634 // Well, there is one exception: Handle [] on strings.
636 Handle<String> string = Handle<String>::cast(object); 635 Handle<String> string = Handle<String>::cast(object);
637 if (index < static_cast<uint32_t>(string->length())) { 636 if (index < static_cast<uint32_t>(string->length())) {
638 return isolate->heap()->true_value(); 637 return isolate->heap()->true_value();
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after
1240 Handle<Object> prototype; 1239 Handle<Object> prototype;
1241 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 1240 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1242 isolate, prototype, 1241 isolate, prototype,
1243 Object::GetProperty(callable, isolate->factory()->prototype_string())); 1242 Object::GetProperty(callable, isolate->factory()->prototype_string()));
1244 if (!prototype->IsJSReceiver()) { 1243 if (!prototype->IsJSReceiver()) {
1245 THROW_NEW_ERROR_RETURN_FAILURE( 1244 THROW_NEW_ERROR_RETURN_FAILURE(
1246 isolate, 1245 isolate,
1247 NewTypeError(MessageTemplate::kInstanceofNonobjectProto, prototype)); 1246 NewTypeError(MessageTemplate::kInstanceofNonobjectProto, prototype));
1248 } 1247 }
1249 // Return whether or not {prototype} is in the prototype chain of {object}. 1248 // Return whether or not {prototype} is in the prototype chain of {object}.
1250 Maybe<bool> result = Object::HasInPrototypeChain(isolate, object, prototype); 1249 Handle<JSReceiver> receiver = Handle<JSReceiver>::cast(object);
1250 Maybe<bool> result =
1251 JSReceiver::HasInPrototypeChain(isolate, receiver, prototype);
1251 MAYBE_RETURN(result, isolate->heap()->exception()); 1252 MAYBE_RETURN(result, isolate->heap()->exception());
1252 return isolate->heap()->ToBoolean(result.FromJust()); 1253 return isolate->heap()->ToBoolean(result.FromJust());
1253 } 1254 }
1254 1255
1255 1256
1256 RUNTIME_FUNCTION(Runtime_HasInPrototypeChain) { 1257 RUNTIME_FUNCTION(Runtime_HasInPrototypeChain) {
1257 HandleScope scope(isolate); 1258 HandleScope scope(isolate);
1258 DCHECK_EQ(2, args.length()); 1259 DCHECK_EQ(2, args.length());
1259 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); 1260 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, object, 0);
1260 CONVERT_ARG_HANDLE_CHECKED(Object, prototype, 1); 1261 CONVERT_ARG_HANDLE_CHECKED(Object, prototype, 1);
1261 Maybe<bool> result = Object::HasInPrototypeChain(isolate, object, prototype); 1262 Maybe<bool> result =
1263 JSReceiver::HasInPrototypeChain(isolate, object, prototype);
1262 MAYBE_RETURN(result, isolate->heap()->exception()); 1264 MAYBE_RETURN(result, isolate->heap()->exception());
1263 return isolate->heap()->ToBoolean(result.FromJust()); 1265 return isolate->heap()->ToBoolean(result.FromJust());
1264 } 1266 }
1265 1267
1266 1268
1267 // ES6 section 7.4.7 CreateIterResultObject ( value, done ) 1269 // ES6 section 7.4.7 CreateIterResultObject ( value, done )
1268 RUNTIME_FUNCTION(Runtime_CreateIterResultObject) { 1270 RUNTIME_FUNCTION(Runtime_CreateIterResultObject) {
1269 HandleScope scope(isolate); 1271 HandleScope scope(isolate);
1270 DCHECK_EQ(2, args.length()); 1272 DCHECK_EQ(2, args.length());
1271 CONVERT_ARG_HANDLE_CHECKED(Object, value, 0); 1273 CONVERT_ARG_HANDLE_CHECKED(Object, value, 0);
(...skipping 29 matching lines...) Expand all
1301 DCHECK(args.length() == 2); 1303 DCHECK(args.length() == 2);
1302 CONVERT_ARG_HANDLE_CHECKED(Object, o, 0); 1304 CONVERT_ARG_HANDLE_CHECKED(Object, o, 0);
1303 CONVERT_ARG_HANDLE_CHECKED(Object, properties, 1); 1305 CONVERT_ARG_HANDLE_CHECKED(Object, properties, 1);
1304 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 1306 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1305 isolate, o, JSReceiver::DefineProperties(isolate, o, properties)); 1307 isolate, o, JSReceiver::DefineProperties(isolate, o, properties));
1306 return *o; 1308 return *o;
1307 } 1309 }
1308 1310
1309 } // namespace internal 1311 } // namespace internal
1310 } // namespace v8 1312 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime-debug.cc ('k') | src/string-stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698