| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/builtins/builtins-utils.h" | 5 #include "src/builtins/builtins-utils.h" |
| 6 #include "src/builtins/builtins.h" | 6 #include "src/builtins/builtins.h" |
| 7 #include "src/code-factory.h" | 7 #include "src/code-factory.h" |
| 8 #include "src/code-stub-assembler.h" | 8 #include "src/code-stub-assembler.h" |
| 9 #include "src/counters.h" | 9 #include "src/counters.h" |
| 10 #include "src/keys.h" | 10 #include "src/keys.h" |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 HandleScope scope(isolate); | 430 HandleScope scope(isolate); |
| 431 Handle<Object> object = args.atOrUndefined(isolate, 1); | 431 Handle<Object> object = args.atOrUndefined(isolate, 1); |
| 432 Maybe<bool> result = object->IsJSReceiver() | 432 Maybe<bool> result = object->IsJSReceiver() |
| 433 ? JSReceiver::TestIntegrityLevel( | 433 ? JSReceiver::TestIntegrityLevel( |
| 434 Handle<JSReceiver>::cast(object), SEALED) | 434 Handle<JSReceiver>::cast(object), SEALED) |
| 435 : Just(true); | 435 : Just(true); |
| 436 MAYBE_RETURN(result, isolate->heap()->exception()); | 436 MAYBE_RETURN(result, isolate->heap()->exception()); |
| 437 return isolate->heap()->ToBoolean(result.FromJust()); | 437 return isolate->heap()->ToBoolean(result.FromJust()); |
| 438 } | 438 } |
| 439 | 439 |
| 440 // ES6 section 19.1.2.14 Object.keys ( O ) | |
| 441 BUILTIN(ObjectKeys) { | |
| 442 HandleScope scope(isolate); | |
| 443 Handle<Object> object = args.atOrUndefined(isolate, 1); | |
| 444 Handle<JSReceiver> receiver; | |
| 445 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, | |
| 446 Object::ToObject(isolate, object)); | |
| 447 | |
| 448 Handle<FixedArray> keys; | |
| 449 int enum_length = receiver->map()->EnumLength(); | |
| 450 if (enum_length != kInvalidEnumCacheSentinel && | |
| 451 JSObject::cast(*receiver)->elements() == | |
| 452 isolate->heap()->empty_fixed_array()) { | |
| 453 DCHECK(receiver->IsJSObject()); | |
| 454 DCHECK(!JSObject::cast(*receiver)->HasNamedInterceptor()); | |
| 455 DCHECK(!JSObject::cast(*receiver)->IsAccessCheckNeeded()); | |
| 456 DCHECK(!receiver->map()->has_hidden_prototype()); | |
| 457 DCHECK(JSObject::cast(*receiver)->HasFastProperties()); | |
| 458 if (enum_length == 0) { | |
| 459 keys = isolate->factory()->empty_fixed_array(); | |
| 460 } else { | |
| 461 Handle<FixedArray> cache( | |
| 462 receiver->map()->instance_descriptors()->GetEnumCache()); | |
| 463 keys = isolate->factory()->CopyFixedArrayUpTo(cache, enum_length); | |
| 464 } | |
| 465 } else { | |
| 466 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
| 467 isolate, keys, | |
| 468 KeyAccumulator::GetKeys(receiver, KeyCollectionMode::kOwnOnly, | |
| 469 ENUMERABLE_STRINGS, | |
| 470 GetKeysConversion::kConvertToString)); | |
| 471 } | |
| 472 return *isolate->factory()->NewJSArrayWithElements(keys, FAST_ELEMENTS); | |
| 473 } | |
| 474 | |
| 475 BUILTIN(ObjectValues) { | 440 BUILTIN(ObjectValues) { |
| 476 HandleScope scope(isolate); | 441 HandleScope scope(isolate); |
| 477 Handle<Object> object = args.atOrUndefined(isolate, 1); | 442 Handle<Object> object = args.atOrUndefined(isolate, 1); |
| 478 Handle<JSReceiver> receiver; | 443 Handle<JSReceiver> receiver; |
| 479 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, | 444 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, |
| 480 Object::ToObject(isolate, object)); | 445 Object::ToObject(isolate, object)); |
| 481 Handle<FixedArray> values; | 446 Handle<FixedArray> values; |
| 482 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 447 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 483 isolate, values, JSReceiver::GetOwnValues(receiver, ENUMERABLE_STRINGS)); | 448 isolate, values, JSReceiver::GetOwnValues(receiver, ENUMERABLE_STRINGS)); |
| 484 return *isolate->factory()->NewJSArrayWithElements(values); | 449 return *isolate->factory()->NewJSArrayWithElements(values); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 if (object->IsJSReceiver()) { | 518 if (object->IsJSReceiver()) { |
| 554 MAYBE_RETURN(JSReceiver::SetIntegrityLevel(Handle<JSReceiver>::cast(object), | 519 MAYBE_RETURN(JSReceiver::SetIntegrityLevel(Handle<JSReceiver>::cast(object), |
| 555 SEALED, Object::THROW_ON_ERROR), | 520 SEALED, Object::THROW_ON_ERROR), |
| 556 isolate->heap()->exception()); | 521 isolate->heap()->exception()); |
| 557 } | 522 } |
| 558 return *object; | 523 return *object; |
| 559 } | 524 } |
| 560 | 525 |
| 561 } // namespace internal | 526 } // namespace internal |
| 562 } // namespace v8 | 527 } // namespace v8 |
| OLD | NEW |