OLD | NEW |
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/runtime/runtime.h" | 10 #include "src/runtime/runtime.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 return Handle<Name>::cast(key); | 58 return Handle<Name>::cast(key); |
59 } else { | 59 } else { |
60 Handle<Object> converted; | 60 Handle<Object> converted; |
61 ASSIGN_RETURN_ON_EXCEPTION(isolate, converted, | 61 ASSIGN_RETURN_ON_EXCEPTION(isolate, converted, |
62 Execution::ToString(isolate, key), Name); | 62 Execution::ToString(isolate, key), Name); |
63 return Handle<Name>::cast(converted); | 63 return Handle<Name>::cast(converted); |
64 } | 64 } |
65 } | 65 } |
66 | 66 |
67 | 67 |
68 MaybeHandle<Object> Runtime::HasObjectProperty(Isolate* isolate, | |
69 Handle<JSReceiver> object, | |
70 Handle<Object> key) { | |
71 Maybe<bool> maybe; | |
72 // Check if the given key is an array index. | |
73 uint32_t index; | |
74 if (key->ToArrayIndex(&index)) { | |
75 maybe = JSReceiver::HasElement(object, index); | |
76 } else { | |
77 // Convert the key to a name - possibly by calling back into JavaScript. | |
78 Handle<Name> name; | |
79 ASSIGN_RETURN_ON_EXCEPTION(isolate, name, ToName(isolate, key), Object); | |
80 | |
81 maybe = JSReceiver::HasProperty(object, name); | |
82 } | |
83 | |
84 if (!maybe.has_value) return MaybeHandle<Object>(); | |
85 return isolate->factory()->ToBoolean(maybe.value); | |
86 } | |
87 | |
88 | |
89 MaybeHandle<Object> Runtime::GetObjectProperty(Isolate* isolate, | 68 MaybeHandle<Object> Runtime::GetObjectProperty(Isolate* isolate, |
90 Handle<Object> object, | 69 Handle<Object> object, |
91 Handle<Object> key) { | 70 Handle<Object> key) { |
92 if (object->IsUndefined() || object->IsNull()) { | 71 if (object->IsUndefined() || object->IsNull()) { |
93 Handle<Object> args[2] = {key, object}; | 72 Handle<Object> args[2] = {key, object}; |
94 THROW_NEW_ERROR(isolate, NewTypeError("non_object_property_load", | 73 THROW_NEW_ERROR(isolate, NewTypeError("non_object_property_load", |
95 HandleVector(args, 2)), | 74 HandleVector(args, 2)), |
96 Object); | 75 Object); |
97 } | 76 } |
98 | 77 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 if (name->AsArrayIndex(&index)) { | 235 if (name->AsArrayIndex(&index)) { |
257 return JSObject::SetElement(js_object, index, value, attr, SLOPPY, false, | 236 return JSObject::SetElement(js_object, index, value, attr, SLOPPY, false, |
258 DEFINE_PROPERTY); | 237 DEFINE_PROPERTY); |
259 } else { | 238 } else { |
260 return JSObject::SetOwnPropertyIgnoreAttributes(js_object, name, value, | 239 return JSObject::SetOwnPropertyIgnoreAttributes(js_object, name, value, |
261 attr); | 240 attr); |
262 } | 241 } |
263 } | 242 } |
264 | 243 |
265 | 244 |
266 MaybeHandle<Object> Runtime::DeleteObjectProperty(Isolate* isolate, | |
267 Handle<JSReceiver> receiver, | |
268 Handle<Object> key, | |
269 JSReceiver::DeleteMode mode) { | |
270 // Check if the given key is an array index. | |
271 uint32_t index; | |
272 if (key->ToArrayIndex(&index)) { | |
273 // In Firefox/SpiderMonkey, Safari and Opera you can access the | |
274 // characters of a string using [] notation. In the case of a | |
275 // String object we just need to redirect the deletion to the | |
276 // underlying string if the index is in range. Since the | |
277 // underlying string does nothing with the deletion, we can ignore | |
278 // such deletions. | |
279 if (receiver->IsStringObjectWithCharacterAt(index)) { | |
280 return isolate->factory()->true_value(); | |
281 } | |
282 | |
283 return JSReceiver::DeleteElement(receiver, index, mode); | |
284 } | |
285 | |
286 Handle<Name> name; | |
287 if (key->IsName()) { | |
288 name = Handle<Name>::cast(key); | |
289 } else { | |
290 // Call-back into JavaScript to convert the key to a string. | |
291 Handle<Object> converted; | |
292 ASSIGN_RETURN_ON_EXCEPTION(isolate, converted, | |
293 Execution::ToString(isolate, key), Object); | |
294 name = Handle<String>::cast(converted); | |
295 } | |
296 | |
297 if (name->IsString()) name = String::Flatten(Handle<String>::cast(name)); | |
298 return JSReceiver::DeleteProperty(receiver, name, mode); | |
299 } | |
300 | |
301 | |
302 RUNTIME_FUNCTION(Runtime_GetPrototype) { | 245 RUNTIME_FUNCTION(Runtime_GetPrototype) { |
303 HandleScope scope(isolate); | 246 HandleScope scope(isolate); |
304 DCHECK(args.length() == 1); | 247 DCHECK(args.length() == 1); |
305 CONVERT_ARG_HANDLE_CHECKED(Object, obj, 0); | 248 CONVERT_ARG_HANDLE_CHECKED(Object, obj, 0); |
306 // We don't expect access checks to be needed on JSProxy objects. | 249 // We don't expect access checks to be needed on JSProxy objects. |
307 DCHECK(!obj->IsAccessCheckNeeded() || obj->IsJSObject()); | 250 DCHECK(!obj->IsAccessCheckNeeded() || obj->IsJSObject()); |
308 PrototypeIterator iter(isolate, obj, PrototypeIterator::START_AT_RECEIVER); | 251 PrototypeIterator iter(isolate, obj, PrototypeIterator::START_AT_RECEIVER); |
309 do { | 252 do { |
310 if (PrototypeIterator::GetCurrent(iter)->IsAccessCheckNeeded() && | 253 if (PrototypeIterator::GetCurrent(iter)->IsAccessCheckNeeded() && |
311 !isolate->MayNamedAccess( | 254 !isolate->MayNamedAccess( |
(...skipping 1323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1635 | 1578 |
1636 RUNTIME_FUNCTION(RuntimeReference_ClassOf) { | 1579 RUNTIME_FUNCTION(RuntimeReference_ClassOf) { |
1637 SealHandleScope shs(isolate); | 1580 SealHandleScope shs(isolate); |
1638 DCHECK(args.length() == 1); | 1581 DCHECK(args.length() == 1); |
1639 CONVERT_ARG_CHECKED(Object, obj, 0); | 1582 CONVERT_ARG_CHECKED(Object, obj, 0); |
1640 if (!obj->IsJSReceiver()) return isolate->heap()->null_value(); | 1583 if (!obj->IsJSReceiver()) return isolate->heap()->null_value(); |
1641 return JSReceiver::cast(obj)->class_name(); | 1584 return JSReceiver::cast(obj)->class_name(); |
1642 } | 1585 } |
1643 } | 1586 } |
1644 } // namespace v8::internal | 1587 } // namespace v8::internal |
OLD | NEW |