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 28 matching lines...) Expand all Loading... |
39 #include "include/v8-util.h" | 39 #include "include/v8-util.h" |
40 #include "src/api.h" | 40 #include "src/api.h" |
41 #include "src/arguments.h" | 41 #include "src/arguments.h" |
42 #include "src/base/platform/platform.h" | 42 #include "src/base/platform/platform.h" |
43 #include "src/compilation-cache.h" | 43 #include "src/compilation-cache.h" |
44 #include "src/cpu-profiler.h" | 44 #include "src/cpu-profiler.h" |
45 #include "src/execution.h" | 45 #include "src/execution.h" |
46 #include "src/isolate.h" | 46 #include "src/isolate.h" |
47 #include "src/objects.h" | 47 #include "src/objects.h" |
48 #include "src/parser.h" | 48 #include "src/parser.h" |
| 49 #include "src/smart-pointers.h" |
49 #include "src/snapshot.h" | 50 #include "src/snapshot.h" |
50 #include "src/unicode-inl.h" | 51 #include "src/unicode-inl.h" |
51 #include "src/utils.h" | 52 #include "src/utils.h" |
52 #include "src/vm-state.h" | 53 #include "src/vm-state.h" |
53 #include "test/cctest/cctest.h" | 54 #include "test/cctest/cctest.h" |
54 | 55 |
55 static const bool kLogThreading = false; | 56 static const bool kLogThreading = false; |
56 | 57 |
57 using ::v8::Boolean; | 58 using ::v8::Boolean; |
58 using ::v8::BooleanObject; | 59 using ::v8::BooleanObject; |
(...skipping 4671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4730 v8::False(isolate)); | 4731 v8::False(isolate)); |
4731 script = Script::Compile(v8_str("throw 'error'"), | 4732 script = Script::Compile(v8_str("throw 'error'"), |
4732 &origin); | 4733 &origin); |
4733 script->Run(); | 4734 script->Run(); |
4734 CHECK(message_received); | 4735 CHECK(message_received); |
4735 // clear out the message listener | 4736 // clear out the message listener |
4736 v8::V8::RemoveMessageListeners(check_message_5b); | 4737 v8::V8::RemoveMessageListeners(check_message_5b); |
4737 } | 4738 } |
4738 | 4739 |
4739 | 4740 |
| 4741 TEST(NativeWeakMap) { |
| 4742 v8::Isolate* isolate = CcTest::isolate(); |
| 4743 HandleScope scope(isolate); |
| 4744 Local<v8::NativeWeakMap> weak_map(v8::NativeWeakMap::New(isolate)); |
| 4745 CHECK(!weak_map.IsEmpty()); |
| 4746 |
| 4747 LocalContext env; |
| 4748 Local<Object> value = v8::Object::New(isolate); |
| 4749 |
| 4750 Local<Object> local1 = v8::Object::New(isolate); |
| 4751 CHECK(!weak_map->Has(local1)); |
| 4752 CHECK(weak_map->Get(local1)->IsUndefined()); |
| 4753 weak_map->Set(local1, value); |
| 4754 CHECK(weak_map->Has(local1)); |
| 4755 CHECK(value->Equals(weak_map->Get(local1))); |
| 4756 |
| 4757 WeakCallCounter counter(1234); |
| 4758 WeakCallCounterAndPersistent<Value> o1(&counter); |
| 4759 WeakCallCounterAndPersistent<Value> o2(&counter); |
| 4760 WeakCallCounterAndPersistent<Value> s1(&counter); |
| 4761 { |
| 4762 HandleScope scope(isolate); |
| 4763 Local<v8::Object> obj1 = v8::Object::New(isolate); |
| 4764 Local<v8::Object> obj2 = v8::Object::New(isolate); |
| 4765 Local<v8::Symbol> sym1 = v8::Symbol::New(isolate); |
| 4766 |
| 4767 weak_map->Set(obj1, value); |
| 4768 weak_map->Set(obj2, value); |
| 4769 weak_map->Set(sym1, value); |
| 4770 |
| 4771 o1.handle.Reset(isolate, obj1); |
| 4772 o2.handle.Reset(isolate, obj2); |
| 4773 s1.handle.Reset(isolate, sym1); |
| 4774 |
| 4775 CHECK(weak_map->Has(local1)); |
| 4776 CHECK(weak_map->Has(obj1)); |
| 4777 CHECK(weak_map->Has(obj2)); |
| 4778 CHECK(weak_map->Has(sym1)); |
| 4779 |
| 4780 CHECK(value->Equals(weak_map->Get(local1))); |
| 4781 CHECK(value->Equals(weak_map->Get(obj1))); |
| 4782 CHECK(value->Equals(weak_map->Get(obj2))); |
| 4783 CHECK(value->Equals(weak_map->Get(sym1))); |
| 4784 } |
| 4785 CcTest::heap()->CollectAllGarbage(TestHeap::Heap::kNoGCFlags); |
| 4786 { |
| 4787 HandleScope scope(isolate); |
| 4788 CHECK(value->Equals(weak_map->Get(local1))); |
| 4789 CHECK(value->Equals(weak_map->Get(Local<Value>::New(isolate, o1.handle)))); |
| 4790 CHECK(value->Equals(weak_map->Get(Local<Value>::New(isolate, o2.handle)))); |
| 4791 CHECK(value->Equals(weak_map->Get(Local<Value>::New(isolate, s1.handle)))); |
| 4792 } |
| 4793 |
| 4794 o1.handle.SetWeak(&o1, &WeakPointerCallback); |
| 4795 o2.handle.SetWeak(&o2, &WeakPointerCallback); |
| 4796 s1.handle.SetWeak(&s1, &WeakPointerCallback); |
| 4797 |
| 4798 CcTest::heap()->CollectAllGarbage(TestHeap::Heap::kNoGCFlags); |
| 4799 CHECK_EQ(3, counter.NumberOfWeakCalls()); |
| 4800 |
| 4801 CHECK(o1.handle.IsEmpty()); |
| 4802 CHECK(o2.handle.IsEmpty()); |
| 4803 CHECK(s1.handle.IsEmpty()); |
| 4804 |
| 4805 CHECK(value->Equals(weak_map->Get(local1))); |
| 4806 CHECK(weak_map->Delete(local1)); |
| 4807 CHECK(!weak_map->Has(local1)); |
| 4808 CHECK(weak_map->Get(local1)->IsUndefined()); |
| 4809 } |
| 4810 |
| 4811 |
4740 THREADED_TEST(GetSetProperty) { | 4812 THREADED_TEST(GetSetProperty) { |
4741 LocalContext context; | 4813 LocalContext context; |
4742 v8::Isolate* isolate = context->GetIsolate(); | 4814 v8::Isolate* isolate = context->GetIsolate(); |
4743 v8::HandleScope scope(isolate); | 4815 v8::HandleScope scope(isolate); |
4744 context->Global()->Set(v8_str("foo"), v8_num(14)); | 4816 context->Global()->Set(v8_str("foo"), v8_num(14)); |
4745 context->Global()->Set(v8_str("12"), v8_num(92)); | 4817 context->Global()->Set(v8_str("12"), v8_num(92)); |
4746 context->Global()->Set(v8::Integer::New(isolate, 16), v8_num(32)); | 4818 context->Global()->Set(v8::Integer::New(isolate, 16), v8_num(32)); |
4747 context->Global()->Set(v8_num(13), v8_num(56)); | 4819 context->Global()->Set(v8_num(13), v8_num(56)); |
4748 Local<Value> foo = CompileRun("this.foo"); | 4820 Local<Value> foo = CompileRun("this.foo"); |
4749 CHECK_EQ(14, foo->Int32Value()); | 4821 CHECK_EQ(14, foo->Int32Value()); |
(...skipping 20140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
24890 "bar2.js"); | 24962 "bar2.js"); |
24891 } | 24963 } |
24892 | 24964 |
24893 | 24965 |
24894 TEST(StreamingScriptWithSourceMappingURLInTheMiddle) { | 24966 TEST(StreamingScriptWithSourceMappingURLInTheMiddle) { |
24895 const char* chunks[] = {"function foo() { ret", "urn 13; }\n//#", | 24967 const char* chunks[] = {"function foo() { ret", "urn 13; }\n//#", |
24896 " sourceMappingURL=bar2.js\n", "foo();", NULL}; | 24968 " sourceMappingURL=bar2.js\n", "foo();", NULL}; |
24897 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, true, NULL, | 24969 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, true, NULL, |
24898 "bar2.js"); | 24970 "bar2.js"); |
24899 } | 24971 } |
OLD | NEW |