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

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

Issue 1178893002: Introduce LookupIterator::PropertyOrElement which converts name to index if possible. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 6 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') | no next file » | 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/v8.h" 5 #include "src/v8.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.h" 9 #include "src/debug.h"
10 #include "src/messages.h" 10 #include "src/messages.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 if (key->ToArrayIndex(&index)) { 65 if (key->ToArrayIndex(&index)) {
66 return GetElementOrCharAt(isolate, object, index); 66 return GetElementOrCharAt(isolate, object, index);
67 } 67 }
68 68
69 // Convert the key to a name - possibly by calling back into JavaScript. 69 // Convert the key to a name - possibly by calling back into JavaScript.
70 Handle<Name> name; 70 Handle<Name> name;
71 ASSIGN_RETURN_ON_EXCEPTION(isolate, name, ToName(isolate, key), Object); 71 ASSIGN_RETURN_ON_EXCEPTION(isolate, name, ToName(isolate, key), Object);
72 72
73 // Check if the name is trivially convertible to an index and get 73 // Check if the name is trivially convertible to an index and get
74 // the element if so. 74 // the element if so.
75 // TODO(verwaest): Make sure GetProperty(LookupIterator*) can handle this, and
76 // remove the special casing here.
75 if (name->AsArrayIndex(&index)) { 77 if (name->AsArrayIndex(&index)) {
76 return GetElementOrCharAt(isolate, object, index); 78 return GetElementOrCharAt(isolate, object, index);
77 } else { 79 } else {
78 return Object::GetProperty(object, name); 80 return Object::GetProperty(object, name);
79 } 81 }
80 } 82 }
81 83
82 84
83 MaybeHandle<Object> Runtime::SetObjectProperty(Isolate* isolate, 85 MaybeHandle<Object> Runtime::SetObjectProperty(Isolate* isolate,
84 Handle<Object> object, 86 Handle<Object> object,
(...skipping 10 matching lines...) Expand all
95 // Check if the given key is an array index. 97 // Check if the given key is an array index.
96 uint32_t index = 0; 98 uint32_t index = 0;
97 if (key->ToArrayIndex(&index)) { 99 if (key->ToArrayIndex(&index)) {
98 // TODO(verwaest): Support other objects as well. 100 // TODO(verwaest): Support other objects as well.
99 if (!object->IsJSReceiver()) return value; 101 if (!object->IsJSReceiver()) return value;
100 return JSReceiver::SetElement(Handle<JSReceiver>::cast(object), index, 102 return JSReceiver::SetElement(Handle<JSReceiver>::cast(object), index,
101 value, language_mode); 103 value, language_mode);
102 } 104 }
103 105
104 Handle<Name> name; 106 Handle<Name> name;
105 if (key->IsName()) { 107 ASSIGN_RETURN_ON_EXCEPTION(isolate, name, ToName(isolate, key), Object);
106 name = Handle<Name>::cast(key);
107 } else {
108 // Call-back into JavaScript to convert the key to a string.
109 Handle<Object> converted;
110 ASSIGN_RETURN_ON_EXCEPTION(isolate, converted,
111 Execution::ToString(isolate, key), Object);
112 name = Handle<String>::cast(converted);
113 }
114 108
115 if (name->AsArrayIndex(&index)) { 109 LookupIterator it = LookupIterator::PropertyOrElement(isolate, object, name);
116 // TODO(verwaest): Support other objects as well. 110 // TODO(verwaest): Support other objects as well.
117 if (!object->IsJSReceiver()) return value; 111 if (it.IsElement() && !object->IsJSReceiver()) return value;
118 return JSReceiver::SetElement(Handle<JSReceiver>::cast(object), index, 112 return Object::SetProperty(&it, value, language_mode,
119 value, language_mode); 113 Object::MAY_BE_STORE_FROM_KEYED);
120 }
121 return Object::SetProperty(object, name, value, language_mode);
122 } 114 }
123 115
124 116
125 MaybeHandle<Object> Runtime::GetPrototype(Isolate* isolate, 117 MaybeHandle<Object> Runtime::GetPrototype(Isolate* isolate,
126 Handle<Object> obj) { 118 Handle<Object> obj) {
127 // We don't expect access checks to be needed on JSProxy objects. 119 // We don't expect access checks to be needed on JSProxy objects.
128 DCHECK(!obj->IsAccessCheckNeeded() || obj->IsJSObject()); 120 DCHECK(!obj->IsAccessCheckNeeded() || obj->IsJSObject());
129 PrototypeIterator iter(isolate, obj, PrototypeIterator::START_AT_RECEIVER); 121 PrototypeIterator iter(isolate, obj, PrototypeIterator::START_AT_RECEIVER);
130 do { 122 do {
131 if (PrototypeIterator::GetCurrent(iter)->IsAccessCheckNeeded() && 123 if (PrototypeIterator::GetCurrent(iter)->IsAccessCheckNeeded() &&
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 }; 224 };
233 225
234 226
235 MUST_USE_RESULT static MaybeHandle<Object> GetOwnProperty(Isolate* isolate, 227 MUST_USE_RESULT static MaybeHandle<Object> GetOwnProperty(Isolate* isolate,
236 Handle<JSObject> obj, 228 Handle<JSObject> obj,
237 Handle<Name> name) { 229 Handle<Name> name) {
238 Heap* heap = isolate->heap(); 230 Heap* heap = isolate->heap();
239 Factory* factory = isolate->factory(); 231 Factory* factory = isolate->factory();
240 232
241 PropertyAttributes attrs; 233 PropertyAttributes attrs;
242 uint32_t index;
243 // Get attributes. 234 // Get attributes.
244 LookupIterator it = 235 LookupIterator it = LookupIterator::PropertyOrElement(isolate, obj, name,
245 name->AsArrayIndex(&index) 236 LookupIterator::HIDDEN);
246 ? LookupIterator(isolate, obj, index, LookupIterator::HIDDEN)
247 : LookupIterator(obj, name, LookupIterator::HIDDEN);
248 Maybe<PropertyAttributes> maybe = JSObject::GetPropertyAttributes(&it); 237 Maybe<PropertyAttributes> maybe = JSObject::GetPropertyAttributes(&it);
249 238
250 if (!maybe.IsJust()) return MaybeHandle<Object>(); 239 if (!maybe.IsJust()) return MaybeHandle<Object>();
251 attrs = maybe.FromJust(); 240 attrs = maybe.FromJust();
252 if (attrs == ABSENT) return factory->undefined_value(); 241 if (attrs == ABSENT) return factory->undefined_value();
253 242
254 DCHECK(!isolate->has_pending_exception()); 243 DCHECK(!isolate->has_pending_exception());
255 Handle<FixedArray> elms = factory->NewFixedArray(DESCRIPTOR_SIZE); 244 Handle<FixedArray> elms = factory->NewFixedArray(DESCRIPTOR_SIZE);
256 elms->set(ENUMERABLE_INDEX, heap->ToBoolean((attrs & DONT_ENUM) == 0)); 245 elms->set(ENUMERABLE_INDEX, heap->ToBoolean((attrs & DONT_ENUM) == 0));
257 elms->set(CONFIGURABLE_INDEX, heap->ToBoolean((attrs & DONT_DELETE) == 0)); 246 elms->set(CONFIGURABLE_INDEX, heap->ToBoolean((attrs & DONT_DELETE) == 0));
(...skipping 1009 matching lines...) Expand 10 before | Expand all | Expand 10 after
1267 // Step 12 - update an existing data property with a data or generic 1256 // Step 12 - update an existing data property with a data or generic
1268 // descriptor. 1257 // descriptor.
1269 RUNTIME_FUNCTION(Runtime_DefineDataPropertyUnchecked) { 1258 RUNTIME_FUNCTION(Runtime_DefineDataPropertyUnchecked) {
1270 HandleScope scope(isolate); 1259 HandleScope scope(isolate);
1271 DCHECK(args.length() == 4); 1260 DCHECK(args.length() == 4);
1272 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); 1261 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0);
1273 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); 1262 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1);
1274 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); 1263 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
1275 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3); 1264 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3);
1276 1265
1277 uint32_t index = 0; 1266 LookupIterator it = LookupIterator::PropertyOrElement(isolate, object, name,
1278 LookupIterator::Configuration c = LookupIterator::OWN_SKIP_INTERCEPTOR; 1267 LookupIterator::OWN);
1279 LookupIterator it = name->AsArrayIndex(&index)
1280 ? LookupIterator(isolate, object, index, c)
1281 : LookupIterator(object, name, c);
1282 if (it.state() == LookupIterator::ACCESS_CHECK && !it.HasAccess()) { 1268 if (it.state() == LookupIterator::ACCESS_CHECK && !it.HasAccess()) {
1283 return isolate->heap()->undefined_value(); 1269 return isolate->heap()->undefined_value();
1284 } 1270 }
1285 1271
1286 Handle<Object> result; 1272 Handle<Object> result;
1287 MaybeHandle<Object> maybe_result = 1273 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1288 it.IsElement() 1274 isolate, result, JSObject::DefineOwnPropertyIgnoreAttributes(
1289 ? JSObject::SetOwnElementIgnoreAttributes(object, index, value, attrs, 1275 &it, value, attrs, JSObject::DONT_FORCE_FIELD));
1290 JSObject::DONT_FORCE_FIELD) 1276
1291 : JSObject::SetOwnPropertyIgnoreAttributes(
1292 object, name, value, attrs, JSObject::DONT_FORCE_FIELD);
1293 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, maybe_result);
1294 return *result; 1277 return *result;
1295 } 1278 }
1296 1279
1297 1280
1298 // Return property without being observable by accessors or interceptors. 1281 // Return property without being observable by accessors or interceptors.
1299 RUNTIME_FUNCTION(Runtime_GetDataProperty) { 1282 RUNTIME_FUNCTION(Runtime_GetDataProperty) {
1300 HandleScope scope(isolate); 1283 HandleScope scope(isolate);
1301 DCHECK(args.length() == 2); 1284 DCHECK(args.length() == 2);
1302 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, object, 0); 1285 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, object, 0);
1303 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); 1286 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1);
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1441 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3); 1424 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3);
1442 1425
1443 RETURN_FAILURE_ON_EXCEPTION( 1426 RETURN_FAILURE_ON_EXCEPTION(
1444 isolate, 1427 isolate,
1445 JSObject::DefineAccessor(object, name, isolate->factory()->null_value(), 1428 JSObject::DefineAccessor(object, name, isolate->factory()->null_value(),
1446 setter, attrs)); 1429 setter, attrs));
1447 return isolate->heap()->undefined_value(); 1430 return isolate->heap()->undefined_value();
1448 } 1431 }
1449 } // namespace internal 1432 } // namespace internal
1450 } // namespace v8 1433 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime-debug.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698