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 7684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7695 v8::V8::RemoveMessageListeners(MissingScriptInfoMessageListener); | 7695 v8::V8::RemoveMessageListeners(MissingScriptInfoMessageListener); |
7696 } | 7696 } |
7697 | 7697 |
7698 | 7698 |
7699 struct FlagAndPersistent { | 7699 struct FlagAndPersistent { |
7700 bool flag; | 7700 bool flag; |
7701 v8::Persistent<v8::Object> handle; | 7701 v8::Persistent<v8::Object> handle; |
7702 }; | 7702 }; |
7703 | 7703 |
7704 | 7704 |
7705 static void SetFlag( | 7705 static void SetFlag(const v8::PhantomCallbackData<FlagAndPersistent>& data) { |
7706 const v8::WeakCallbackData<v8::Object, FlagAndPersistent>& data) { | |
7707 data.GetParameter()->flag = true; | 7706 data.GetParameter()->flag = true; |
7708 } | 7707 } |
7709 | 7708 |
7710 | 7709 |
7711 static void IndependentWeakHandle(bool global_gc, bool interlinked) { | 7710 static void IndependentWeakHandle(bool global_gc, bool interlinked) { |
7712 v8::Isolate* iso = CcTest::isolate(); | 7711 v8::Isolate* iso = CcTest::isolate(); |
7713 v8::HandleScope scope(iso); | 7712 v8::HandleScope scope(iso); |
7714 v8::Handle<Context> context = Context::New(iso); | 7713 v8::Handle<Context> context = Context::New(iso); |
7715 Context::Scope context_scope(context); | 7714 Context::Scope context_scope(context); |
7716 | 7715 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7762 | 7761 |
7763 | 7762 |
7764 THREADED_TEST(IndependentWeakHandle) { | 7763 THREADED_TEST(IndependentWeakHandle) { |
7765 IndependentWeakHandle(false, false); | 7764 IndependentWeakHandle(false, false); |
7766 IndependentWeakHandle(false, true); | 7765 IndependentWeakHandle(false, true); |
7767 IndependentWeakHandle(true, false); | 7766 IndependentWeakHandle(true, false); |
7768 IndependentWeakHandle(true, true); | 7767 IndependentWeakHandle(true, true); |
7769 } | 7768 } |
7770 | 7769 |
7771 | 7770 |
| 7771 class Trivial { |
| 7772 public: |
| 7773 explicit Trivial(int x) : x_(x) {} |
| 7774 |
| 7775 int x() { return x_; } |
| 7776 void set_x(int x) { x_ = x; } |
| 7777 |
| 7778 private: |
| 7779 int x_; |
| 7780 }; |
| 7781 |
| 7782 |
| 7783 class Trivial2 { |
| 7784 public: |
| 7785 Trivial2(int x, int y) : y_(y), x_(x) {} |
| 7786 |
| 7787 int x() { return x_; } |
| 7788 void set_x(int x) { x_ = x; } |
| 7789 |
| 7790 int y() { return y_; } |
| 7791 void set_y(int y) { y_ = y; } |
| 7792 |
| 7793 private: |
| 7794 int y_; |
| 7795 int x_; |
| 7796 }; |
| 7797 |
| 7798 |
| 7799 void CheckInternalFields( |
| 7800 const v8::InternalFieldsCallbackData<Trivial, Trivial2>& data) { |
| 7801 Trivial* t1 = data.GetInternalField1(); |
| 7802 Trivial2* t2 = data.GetInternalField2(); |
| 7803 CHECK_EQ(42, t1->x()); |
| 7804 CHECK_EQ(103, t2->x()); |
| 7805 t1->set_x(1729); |
| 7806 t2->set_x(33550336); |
| 7807 } |
| 7808 |
| 7809 |
| 7810 void InternalFieldCallback(bool global_gc) { |
| 7811 LocalContext env; |
| 7812 v8::Isolate* isolate = env->GetIsolate(); |
| 7813 v8::HandleScope scope(isolate); |
| 7814 |
| 7815 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); |
| 7816 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate(); |
| 7817 Trivial* t1; |
| 7818 Trivial2* t2; |
| 7819 instance_templ->SetInternalFieldCount(2); |
| 7820 { |
| 7821 v8::HandleScope scope(isolate); |
| 7822 Local<v8::Object> obj = templ->GetFunction()->NewInstance(); |
| 7823 v8::Persistent<v8::Object> handle(isolate, obj); |
| 7824 CHECK_EQ(2, obj->InternalFieldCount()); |
| 7825 CHECK(obj->GetInternalField(0)->IsUndefined()); |
| 7826 t1 = new Trivial(42); |
| 7827 t2 = new Trivial2(103, 9); |
| 7828 |
| 7829 obj->SetAlignedPointerInInternalField(0, t1); |
| 7830 t1 = reinterpret_cast<Trivial*>(obj->GetAlignedPointerFromInternalField(0)); |
| 7831 CHECK_EQ(42, t1->x()); |
| 7832 |
| 7833 obj->SetAlignedPointerInInternalField(1, t2); |
| 7834 t2 = |
| 7835 reinterpret_cast<Trivial2*>(obj->GetAlignedPointerFromInternalField(1)); |
| 7836 CHECK_EQ(103, t2->x()); |
| 7837 |
| 7838 handle.SetPhantom(CheckInternalFields, 0, 1); |
| 7839 if (!global_gc) { |
| 7840 handle.MarkIndependent(); |
| 7841 } |
| 7842 } |
| 7843 if (global_gc) { |
| 7844 CcTest::heap()->CollectAllGarbage(TestHeap::Heap::kNoGCFlags); |
| 7845 } else { |
| 7846 CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
| 7847 } |
| 7848 |
| 7849 CHECK_EQ(1729, t1->x()); |
| 7850 CHECK_EQ(33550336, t2->x()); |
| 7851 |
| 7852 delete t1; |
| 7853 delete t2; |
| 7854 } |
| 7855 |
| 7856 |
| 7857 THREADED_TEST(InternalFieldCallback) { |
| 7858 InternalFieldCallback(false); |
| 7859 InternalFieldCallback(true); |
| 7860 } |
| 7861 |
| 7862 |
7772 static void ResetUseValueAndSetFlag( | 7863 static void ResetUseValueAndSetFlag( |
7773 const v8::WeakCallbackData<v8::Object, FlagAndPersistent>& data) { | 7864 const v8::WeakCallbackData<v8::Object, FlagAndPersistent>& data) { |
7774 // Blink will reset the handle, and then use the other handle, so they | 7865 // Blink will reset the handle, and then use the other handle, so they |
7775 // can't use the same backing slot. | 7866 // can't use the same backing slot. |
7776 data.GetParameter()->handle.Reset(); | 7867 data.GetParameter()->handle.Reset(); |
7777 data.GetValue()->IsBoolean(); // Make sure the handle still works. | 7868 data.GetValue()->IsBoolean(); // Make sure the handle still works. |
7778 data.GetParameter()->flag = true; | 7869 data.GetParameter()->flag = true; |
7779 } | 7870 } |
7780 | 7871 |
7781 | 7872 |
(...skipping 16856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
24638 TEST(ClassPrototypeCreationContext) { | 24729 TEST(ClassPrototypeCreationContext) { |
24639 i::FLAG_harmony_classes = true; | 24730 i::FLAG_harmony_classes = true; |
24640 v8::Isolate* isolate = CcTest::isolate(); | 24731 v8::Isolate* isolate = CcTest::isolate(); |
24641 v8::HandleScope handle_scope(isolate); | 24732 v8::HandleScope handle_scope(isolate); |
24642 LocalContext env; | 24733 LocalContext env; |
24643 | 24734 |
24644 Handle<Object> result = Handle<Object>::Cast( | 24735 Handle<Object> result = Handle<Object>::Cast( |
24645 CompileRun("'use strict'; class Example { }; Example.prototype")); | 24736 CompileRun("'use strict'; class Example { }; Example.prototype")); |
24646 CHECK(env.local() == result->CreationContext()); | 24737 CHECK(env.local() == result->CreationContext()); |
24647 } | 24738 } |
OLD | NEW |