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

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

Issue 1843613002: Add initial code-stub version of Object.prototype.hasOwnProperty (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 4 years, 8 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
« src/builtins.cc ('K') | « src/runtime/runtime.h ('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"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 Handle<Object> key, 118 Handle<Object> key,
119 LanguageMode language_mode) { 119 LanguageMode language_mode) {
120 bool success = false; 120 bool success = false;
121 LookupIterator it = LookupIterator::PropertyOrElement( 121 LookupIterator it = LookupIterator::PropertyOrElement(
122 isolate, receiver, key, &success, LookupIterator::HIDDEN); 122 isolate, receiver, key, &success, LookupIterator::HIDDEN);
123 if (!success) return Nothing<bool>(); 123 if (!success) return Nothing<bool>();
124 124
125 return JSReceiver::DeleteProperty(&it, language_mode); 125 return JSReceiver::DeleteProperty(&it, language_mode);
126 } 126 }
127 127
128 // ES6 19.1.3.2
129 RUNTIME_FUNCTION(Runtime_ObjectHasOwnProperty) {
130 HandleScope scope(isolate);
131 Handle<Object> property = args.at<Object>(1);
132
133 Handle<Name> key;
134 uint32_t index;
135 bool key_is_array_index = property->ToArrayIndex(&index);
136
137 if (!key_is_array_index) {
138 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, key,
139 Object::ToName(isolate, property));
140 key_is_array_index = key->AsArrayIndex(&index);
141 }
142
143 Handle<Object> object = args.at<Object>(0);
144
145 if (object->IsJSObject()) {
146 Handle<JSObject> js_obj = Handle<JSObject>::cast(object);
147 // Fast case: either the key is a real named property or it is not
148 // an array index and there are no interceptors or hidden
149 // prototypes.
150 // TODO(jkummerow): Make JSReceiver::HasOwnProperty fast enough to
151 // handle all cases directly (without this custom fast path).
152 {
153 LookupIterator::Configuration c = LookupIterator::OWN_SKIP_INTERCEPTOR;
154 LookupIterator it =
155 key_is_array_index ? LookupIterator(isolate, js_obj, index, js_obj, c)
156 : LookupIterator(js_obj, key, js_obj, c);
157 Maybe<bool> maybe = JSReceiver::HasProperty(&it);
158 if (maybe.IsNothing()) return isolate->heap()->exception();
159 DCHECK(!isolate->has_pending_exception());
160 if (maybe.FromJust()) return isolate->heap()->true_value();
161 }
162
163 Map* map = js_obj->map();
164 if (!map->has_hidden_prototype() &&
165 (key_is_array_index ? !map->has_indexed_interceptor()
166 : !map->has_named_interceptor())) {
167 return isolate->heap()->false_value();
168 }
169
170 // Slow case.
171 LookupIterator::Configuration c = LookupIterator::HIDDEN;
172 LookupIterator it = key_is_array_index
173 ? LookupIterator(isolate, js_obj, index, js_obj, c)
174 : LookupIterator(js_obj, key, js_obj, c);
175
176 Maybe<bool> maybe = JSReceiver::HasProperty(&it);
177 if (maybe.IsNothing()) return isolate->heap()->exception();
178 DCHECK(!isolate->has_pending_exception());
179 return isolate->heap()->ToBoolean(maybe.FromJust());
180
181 } else if (object->IsJSProxy()) {
182 if (key.is_null()) {
183 DCHECK(key_is_array_index);
184 key = isolate->factory()->Uint32ToString(index);
185 }
186
187 Maybe<bool> result =
188 JSReceiver::HasOwnProperty(Handle<JSProxy>::cast(object), key);
189 if (!result.IsJust()) return isolate->heap()->exception();
190 return isolate->heap()->ToBoolean(result.FromJust());
191
192 } else if (object->IsString()) {
193 return isolate->heap()->ToBoolean(
194 key_is_array_index
195 ? index < static_cast<uint32_t>(String::cast(*object)->length())
196 : key->Equals(isolate->heap()->length_string()));
197 } else if (object->IsNull() || object->IsUndefined()) {
198 THROW_NEW_ERROR_RETURN_FAILURE(
199 isolate, NewTypeError(MessageTemplate::kUndefinedOrNullToObject));
200 }
201
202 return isolate->heap()->false_value();
203 }
128 204
129 MaybeHandle<Object> Runtime::SetObjectProperty(Isolate* isolate, 205 MaybeHandle<Object> Runtime::SetObjectProperty(Isolate* isolate,
130 Handle<Object> object, 206 Handle<Object> object,
131 Handle<Object> key, 207 Handle<Object> key,
132 Handle<Object> value, 208 Handle<Object> value,
133 LanguageMode language_mode) { 209 LanguageMode language_mode) {
134 if (object->IsUndefined() || object->IsNull()) { 210 if (object->IsUndefined() || object->IsNull()) {
135 THROW_NEW_ERROR( 211 THROW_NEW_ERROR(
136 isolate, 212 isolate,
137 NewTypeError(MessageTemplate::kNonObjectPropertyStore, key, object), 213 NewTypeError(MessageTemplate::kNonObjectPropertyStore, key, object),
(...skipping 1030 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 DCHECK(args.length() == 2); 1244 DCHECK(args.length() == 2);
1169 CONVERT_ARG_HANDLE_CHECKED(Object, o, 0); 1245 CONVERT_ARG_HANDLE_CHECKED(Object, o, 0);
1170 CONVERT_ARG_HANDLE_CHECKED(Object, properties, 1); 1246 CONVERT_ARG_HANDLE_CHECKED(Object, properties, 1);
1171 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 1247 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1172 isolate, o, JSReceiver::DefineProperties(isolate, o, properties)); 1248 isolate, o, JSReceiver::DefineProperties(isolate, o, properties));
1173 return *o; 1249 return *o;
1174 } 1250 }
1175 1251
1176 } // namespace internal 1252 } // namespace internal
1177 } // namespace v8 1253 } // namespace v8
OLDNEW
« src/builtins.cc ('K') | « src/runtime/runtime.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698