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

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

Issue 1375943002: Add LookupIterator constructor for arbitrary Object keys (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: addressed comments Created 5 years, 2 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/lookup.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/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"
11 #include "src/messages.h" 11 #include "src/messages.h"
12 #include "src/runtime/runtime.h" 12 #include "src/runtime/runtime.h"
13 13
14 namespace v8 { 14 namespace v8 {
15 namespace internal { 15 namespace internal {
16 16
17 17
18 MaybeHandle<Object> Runtime::GetObjectProperty(Isolate* isolate, 18 MaybeHandle<Object> Runtime::GetObjectProperty(Isolate* isolate,
19 Handle<Object> object, 19 Handle<Object> object,
20 Handle<Object> key, 20 Handle<Object> key,
21 LanguageMode language_mode) { 21 LanguageMode language_mode) {
22 if (object->IsUndefined() || object->IsNull()) { 22 if (object->IsUndefined() || object->IsNull()) {
23 THROW_NEW_ERROR( 23 THROW_NEW_ERROR(
24 isolate, 24 isolate,
25 NewTypeError(MessageTemplate::kNonObjectPropertyLoad, key, object), 25 NewTypeError(MessageTemplate::kNonObjectPropertyLoad, key, object),
26 Object); 26 Object);
27 } 27 }
28 28
29 // Check if the given key is an array index. 29 bool success = false;
30 uint32_t index = 0; 30 LookupIterator it =
31 if (key->ToArrayIndex(&index)) { 31 LookupIterator::PropertyOrElement(isolate, object, key, &success);
32 return Object::GetElement(isolate, object, index, language_mode); 32 if (!success) return MaybeHandle<Object>();
33 }
34 33
35 // Convert the key to a name - possibly by calling back into JavaScript. 34 return Object::GetProperty(&it, language_mode);
36 Handle<Name> name;
37 ASSIGN_RETURN_ON_EXCEPTION(isolate, name, Object::ToName(isolate, key),
38 Object);
39
40 // Check if the name is trivially convertible to an index and get
41 // the element if so.
42 // TODO(verwaest): Make sure GetProperty(LookupIterator*) can handle this, and
43 // remove the special casing here.
44 if (name->AsArrayIndex(&index)) {
45 return Object::GetElement(isolate, object, index);
46 } else {
47 return Object::GetProperty(object, name, language_mode);
48 }
49 } 35 }
50 36
51 37
52 static MaybeHandle<Object> KeyedGetObjectProperty(Isolate* isolate, 38 static MaybeHandle<Object> KeyedGetObjectProperty(Isolate* isolate,
53 Handle<Object> receiver_obj, 39 Handle<Object> receiver_obj,
54 Handle<Object> key_obj, 40 Handle<Object> key_obj,
55 LanguageMode language_mode) { 41 LanguageMode language_mode) {
56 // Fast cases for getting named properties of the receiver JSObject 42 // Fast cases for getting named properties of the receiver JSObject
57 // itself. 43 // itself.
58 // 44 //
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 // Fall back to GetObjectProperty. 114 // Fall back to GetObjectProperty.
129 return Runtime::GetObjectProperty(isolate, receiver_obj, key_obj, 115 return Runtime::GetObjectProperty(isolate, receiver_obj, key_obj,
130 language_mode); 116 language_mode);
131 } 117 }
132 118
133 119
134 MaybeHandle<Object> Runtime::DeleteObjectProperty(Isolate* isolate, 120 MaybeHandle<Object> Runtime::DeleteObjectProperty(Isolate* isolate,
135 Handle<JSReceiver> receiver, 121 Handle<JSReceiver> receiver,
136 Handle<Object> key, 122 Handle<Object> key,
137 LanguageMode language_mode) { 123 LanguageMode language_mode) {
138 // Check if the given key is an array index. 124 bool success = false;
139 uint32_t index = 0; 125 LookupIterator it = LookupIterator::PropertyOrElement(
140 if (key->ToArrayIndex(&index)) { 126 isolate, receiver, key, &success, LookupIterator::HIDDEN);
141 return JSReceiver::DeleteElement(receiver, index, language_mode); 127 if (!success) return MaybeHandle<Object>();
142 }
143 128
144 Handle<Name> name; 129 return JSReceiver::DeleteProperty(&it, language_mode);
145 ASSIGN_RETURN_ON_EXCEPTION(isolate, name, Object::ToName(isolate, key),
146 Object);
147
148 return JSReceiver::DeletePropertyOrElement(receiver, name, language_mode);
149 } 130 }
150 131
151 132
152 MaybeHandle<Object> Runtime::SetObjectProperty(Isolate* isolate, 133 MaybeHandle<Object> Runtime::SetObjectProperty(Isolate* isolate,
153 Handle<Object> object, 134 Handle<Object> object,
154 Handle<Object> key, 135 Handle<Object> key,
155 Handle<Object> value, 136 Handle<Object> value,
156 LanguageMode language_mode) { 137 LanguageMode language_mode) {
157 if (object->IsUndefined() || object->IsNull()) { 138 if (object->IsUndefined() || object->IsNull()) {
158 THROW_NEW_ERROR( 139 THROW_NEW_ERROR(
159 isolate, 140 isolate,
160 NewTypeError(MessageTemplate::kNonObjectPropertyStore, key, object), 141 NewTypeError(MessageTemplate::kNonObjectPropertyStore, key, object),
161 Object); 142 Object);
162 } 143 }
163 144
164 // Check if the given key is an array index. 145 // Check if the given key is an array index.
165 uint32_t index = 0; 146 bool success = false;
166 if (key->ToArrayIndex(&index)) { 147 LookupIterator it =
167 return Object::SetElement(isolate, object, index, value, language_mode); 148 LookupIterator::PropertyOrElement(isolate, object, key, &success);
168 } 149 if (!success) return MaybeHandle<Object>();
169 150
170 Handle<Name> name;
171 ASSIGN_RETURN_ON_EXCEPTION(isolate, name, Object::ToName(isolate, key),
172 Object);
173
174 LookupIterator it = LookupIterator::PropertyOrElement(isolate, object, name);
175 return Object::SetProperty(&it, value, language_mode, 151 return Object::SetProperty(&it, value, language_mode,
176 Object::MAY_BE_STORE_FROM_KEYED); 152 Object::MAY_BE_STORE_FROM_KEYED);
177 } 153 }
178 154
179 155
180 RUNTIME_FUNCTION(Runtime_GetPrototype) { 156 RUNTIME_FUNCTION(Runtime_GetPrototype) {
181 HandleScope scope(isolate); 157 HandleScope scope(isolate);
182 DCHECK(args.length() == 1); 158 DCHECK(args.length() == 1);
183 CONVERT_ARG_HANDLE_CHECKED(Object, obj, 0); 159 CONVERT_ARG_HANDLE_CHECKED(Object, obj, 0);
184 // We don't expect access checks to be needed on JSProxy objects. 160 // We don't expect access checks to be needed on JSProxy objects.
(...skipping 1446 matching lines...) Expand 10 before | Expand all | Expand 10 after
1631 RUNTIME_FUNCTION(Runtime_IsAccessCheckNeeded) { 1607 RUNTIME_FUNCTION(Runtime_IsAccessCheckNeeded) {
1632 SealHandleScope shs(isolate); 1608 SealHandleScope shs(isolate);
1633 DCHECK_EQ(1, args.length()); 1609 DCHECK_EQ(1, args.length());
1634 CONVERT_ARG_CHECKED(Object, object, 0); 1610 CONVERT_ARG_CHECKED(Object, object, 0);
1635 return isolate->heap()->ToBoolean(object->IsAccessCheckNeeded()); 1611 return isolate->heap()->ToBoolean(object->IsAccessCheckNeeded());
1636 } 1612 }
1637 1613
1638 1614
1639 } // namespace internal 1615 } // namespace internal
1640 } // namespace v8 1616 } // namespace v8
OLDNEW
« no previous file with comments | « src/lookup.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698