OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 2725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2736 CHECK_EQ(2002, obj->Get(sym1)->Int32Value()); | 2736 CHECK_EQ(2002, obj->Get(sym1)->Int32Value()); |
2737 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length()); | 2737 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length()); |
2738 | 2738 |
2739 CHECK(obj->Has(sym1)); | 2739 CHECK(obj->Has(sym1)); |
2740 CHECK(obj->Has(sym2)); | 2740 CHECK(obj->Has(sym2)); |
2741 CHECK(obj->Delete(sym2)); | 2741 CHECK(obj->Delete(sym2)); |
2742 CHECK(obj->Has(sym1)); | 2742 CHECK(obj->Has(sym1)); |
2743 CHECK(!obj->Has(sym2)); | 2743 CHECK(!obj->Has(sym2)); |
2744 CHECK_EQ(2002, obj->Get(sym1)->Int32Value()); | 2744 CHECK_EQ(2002, obj->Get(sym1)->Int32Value()); |
2745 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length()); | 2745 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length()); |
| 2746 |
| 2747 // Symbol properties are inherited. |
| 2748 v8::Local<v8::Object> child = v8::Object::New(); |
| 2749 child->SetPrototype(obj); |
| 2750 CHECK(child->Has(sym1)); |
| 2751 CHECK_EQ(2002, child->Get(sym1)->Int32Value()); |
| 2752 CHECK_EQ(0, child->GetOwnPropertyNames()->Length()); |
2746 } | 2753 } |
2747 | 2754 |
2748 | 2755 |
| 2756 THREADED_TEST(PrivateProperties) { |
| 2757 LocalContext env; |
| 2758 v8::Isolate* isolate = env->GetIsolate(); |
| 2759 v8::HandleScope scope(isolate); |
| 2760 |
| 2761 v8::Local<v8::Object> obj = v8::Object::New(); |
| 2762 v8::Local<v8::Private> priv1 = v8::Private::New(isolate); |
| 2763 v8::Local<v8::Private> priv2 = v8::Private::New(isolate, "my-private"); |
| 2764 |
| 2765 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 2766 |
| 2767 CHECK(priv2->Name()->Equals(v8::String::New("my-private"))); |
| 2768 |
| 2769 // Make sure delete of a non-existent private symbol property works. |
| 2770 CHECK(obj->DeletePrivate(priv1)); |
| 2771 CHECK(!obj->HasPrivate(priv1)); |
| 2772 |
| 2773 CHECK(obj->SetPrivate(priv1, v8::Integer::New(1503))); |
| 2774 CHECK(obj->HasPrivate(priv1)); |
| 2775 CHECK_EQ(1503, obj->GetPrivate(priv1)->Int32Value()); |
| 2776 CHECK(obj->SetPrivate(priv1, v8::Integer::New(2002))); |
| 2777 CHECK(obj->HasPrivate(priv1)); |
| 2778 CHECK_EQ(2002, obj->GetPrivate(priv1)->Int32Value()); |
| 2779 |
| 2780 CHECK_EQ(0, obj->GetOwnPropertyNames()->Length()); |
| 2781 int num_props = obj->GetPropertyNames()->Length(); |
| 2782 CHECK(obj->Set(v8::String::New("bla"), v8::Integer::New(20))); |
| 2783 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length()); |
| 2784 CHECK_EQ(num_props + 1, obj->GetPropertyNames()->Length()); |
| 2785 |
| 2786 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 2787 |
| 2788 // Add another property and delete it afterwards to force the object in |
| 2789 // slow case. |
| 2790 CHECK(obj->SetPrivate(priv2, v8::Integer::New(2008))); |
| 2791 CHECK_EQ(2002, obj->GetPrivate(priv1)->Int32Value()); |
| 2792 CHECK_EQ(2008, obj->GetPrivate(priv2)->Int32Value()); |
| 2793 CHECK_EQ(2002, obj->GetPrivate(priv1)->Int32Value()); |
| 2794 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length()); |
| 2795 |
| 2796 CHECK(obj->HasPrivate(priv1)); |
| 2797 CHECK(obj->HasPrivate(priv2)); |
| 2798 CHECK(obj->DeletePrivate(priv2)); |
| 2799 CHECK(obj->HasPrivate(priv1)); |
| 2800 CHECK(!obj->HasPrivate(priv2)); |
| 2801 CHECK_EQ(2002, obj->GetPrivate(priv1)->Int32Value()); |
| 2802 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length()); |
| 2803 |
| 2804 // Private properties are inherited (for the time being). |
| 2805 v8::Local<v8::Object> child = v8::Object::New(); |
| 2806 child->SetPrototype(obj); |
| 2807 CHECK(child->HasPrivate(priv1)); |
| 2808 CHECK_EQ(2002, child->GetPrivate(priv1)->Int32Value()); |
| 2809 CHECK_EQ(0, child->GetOwnPropertyNames()->Length()); |
| 2810 } |
| 2811 |
| 2812 |
2749 class ScopedArrayBufferContents { | 2813 class ScopedArrayBufferContents { |
2750 public: | 2814 public: |
2751 explicit ScopedArrayBufferContents( | 2815 explicit ScopedArrayBufferContents( |
2752 const v8::ArrayBuffer::Contents& contents) | 2816 const v8::ArrayBuffer::Contents& contents) |
2753 : contents_(contents) {} | 2817 : contents_(contents) {} |
2754 ~ScopedArrayBufferContents() { free(contents_.Data()); } | 2818 ~ScopedArrayBufferContents() { free(contents_.Data()); } |
2755 void* Data() const { return contents_.Data(); } | 2819 void* Data() const { return contents_.Data(); } |
2756 size_t ByteLength() const { return contents_.ByteLength(); } | 2820 size_t ByteLength() const { return contents_.ByteLength(); } |
2757 private: | 2821 private: |
2758 const v8::ArrayBuffer::Contents contents_; | 2822 const v8::ArrayBuffer::Contents contents_; |
(...skipping 17952 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20711 } | 20775 } |
20712 for (int i = 0; i < runs; i++) { | 20776 for (int i = 0; i < runs; i++) { |
20713 Local<String> expected; | 20777 Local<String> expected; |
20714 if (i != 0) { | 20778 if (i != 0) { |
20715 CHECK_EQ(v8_str("escape value"), values[i]); | 20779 CHECK_EQ(v8_str("escape value"), values[i]); |
20716 } else { | 20780 } else { |
20717 CHECK(values[i].IsEmpty()); | 20781 CHECK(values[i].IsEmpty()); |
20718 } | 20782 } |
20719 } | 20783 } |
20720 } | 20784 } |
OLD | NEW |