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 4638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4697 v8::False(isolate)); | 4698 v8::False(isolate)); |
4698 script = Script::Compile(v8_str("throw 'error'"), | 4699 script = Script::Compile(v8_str("throw 'error'"), |
4699 &origin); | 4700 &origin); |
4700 script->Run(); | 4701 script->Run(); |
4701 CHECK(message_received); | 4702 CHECK(message_received); |
4702 // clear out the message listener | 4703 // clear out the message listener |
4703 v8::V8::RemoveMessageListeners(check_message_5b); | 4704 v8::V8::RemoveMessageListeners(check_message_5b); |
4704 } | 4705 } |
4705 | 4706 |
4706 | 4707 |
| 4708 TEST(WeakMap) { |
| 4709 v8::Isolate* isolate = CcTest::isolate(); |
| 4710 i::SmartPointer<v8::WeakMap> weak_map(v8::WeakMap::New(isolate)); |
| 4711 CHECK(!weak_map.is_empty()); |
| 4712 |
| 4713 LocalContext env; |
| 4714 HandleScope scope(isolate); |
| 4715 |
| 4716 Local<Object> value = v8::Object::New(isolate); |
| 4717 |
| 4718 Local<Object> local1 = v8::Object::New(isolate); |
| 4719 CHECK(!weak_map->Has(local1)); |
| 4720 CHECK_EQ(v8::Undefined(isolate), weak_map->Get(local1)); |
| 4721 weak_map->Set(local1, value); |
| 4722 CHECK(weak_map->Has(local1)); |
| 4723 CHECK_EQ(value, weak_map->Get(local1)); |
| 4724 |
| 4725 WeakCallCounter counter(1234); |
| 4726 WeakCallCounterAndPersistent<Value> o1(&counter); |
| 4727 WeakCallCounterAndPersistent<Value> o2(&counter); |
| 4728 WeakCallCounterAndPersistent<Value> s1(&counter); |
| 4729 { |
| 4730 HandleScope scope(isolate); |
| 4731 Local<v8::Object> obj1 = v8::Object::New(isolate); |
| 4732 Local<v8::Object> obj2 = v8::Object::New(isolate); |
| 4733 Local<v8::Symbol> sym1 = v8::Symbol::New(isolate); |
| 4734 |
| 4735 weak_map->Set(obj1, value); |
| 4736 weak_map->Set(obj2, value); |
| 4737 weak_map->Set(sym1, value); |
| 4738 |
| 4739 o1.handle.Reset(isolate, obj1); |
| 4740 o2.handle.Reset(isolate, obj2); |
| 4741 s1.handle.Reset(isolate, sym1); |
| 4742 |
| 4743 CHECK(weak_map->Has(local1)); |
| 4744 CHECK(weak_map->Has(obj1)); |
| 4745 CHECK(weak_map->Has(obj2)); |
| 4746 CHECK(weak_map->Has(sym1)); |
| 4747 |
| 4748 CHECK_EQ(value, weak_map->Get(local1)); |
| 4749 CHECK_EQ(value, weak_map->Get(obj1)); |
| 4750 CHECK_EQ(value, weak_map->Get(obj2)); |
| 4751 CHECK_EQ(value, weak_map->Get(sym1)); |
| 4752 } |
| 4753 CcTest::heap()->CollectAllGarbage(TestHeap::Heap::kNoGCFlags); |
| 4754 { |
| 4755 HandleScope scope(isolate); |
| 4756 CHECK_EQ(value, weak_map->Get(local1)); |
| 4757 CHECK_EQ(value, weak_map->Get(Local<Value>::New(isolate, o1.handle))); |
| 4758 CHECK_EQ(value, weak_map->Get(Local<Value>::New(isolate, o2.handle))); |
| 4759 CHECK_EQ(value, weak_map->Get(Local<Value>::New(isolate, s1.handle))); |
| 4760 } |
| 4761 |
| 4762 o1.handle.SetWeak(&o1, &WeakPointerCallback); |
| 4763 o2.handle.SetWeak(&o2, &WeakPointerCallback); |
| 4764 s1.handle.SetWeak(&s1, &WeakPointerCallback); |
| 4765 |
| 4766 CcTest::heap()->CollectAllGarbage(TestHeap::Heap::kNoGCFlags); |
| 4767 CHECK_EQ(3, counter.NumberOfWeakCalls()); |
| 4768 |
| 4769 CHECK(o1.handle.IsEmpty()); |
| 4770 CHECK(o2.handle.IsEmpty()); |
| 4771 CHECK(s1.handle.IsEmpty()); |
| 4772 |
| 4773 CHECK_EQ(value, weak_map->Get(local1)); |
| 4774 CHECK(weak_map->Delete(local1)); |
| 4775 CHECK(!weak_map->Has(local1)); |
| 4776 CHECK_EQ(v8::Undefined(isolate), weak_map->Get(local1)); |
| 4777 } |
| 4778 |
| 4779 |
4707 THREADED_TEST(GetSetProperty) { | 4780 THREADED_TEST(GetSetProperty) { |
4708 LocalContext context; | 4781 LocalContext context; |
4709 v8::Isolate* isolate = context->GetIsolate(); | 4782 v8::Isolate* isolate = context->GetIsolate(); |
4710 v8::HandleScope scope(isolate); | 4783 v8::HandleScope scope(isolate); |
4711 context->Global()->Set(v8_str("foo"), v8_num(14)); | 4784 context->Global()->Set(v8_str("foo"), v8_num(14)); |
4712 context->Global()->Set(v8_str("12"), v8_num(92)); | 4785 context->Global()->Set(v8_str("12"), v8_num(92)); |
4713 context->Global()->Set(v8::Integer::New(isolate, 16), v8_num(32)); | 4786 context->Global()->Set(v8::Integer::New(isolate, 16), v8_num(32)); |
4714 context->Global()->Set(v8_num(13), v8_num(56)); | 4787 context->Global()->Set(v8_num(13), v8_num(56)); |
4715 Local<Value> foo = CompileRun("this.foo"); | 4788 Local<Value> foo = CompileRun("this.foo"); |
4716 CHECK_EQ(14, foo->Int32Value()); | 4789 CHECK_EQ(14, foo->Int32Value()); |
(...skipping 20049 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
24766 "bar2.js"); | 24839 "bar2.js"); |
24767 } | 24840 } |
24768 | 24841 |
24769 | 24842 |
24770 TEST(StreamingScriptWithSourceMappingURLInTheMiddle) { | 24843 TEST(StreamingScriptWithSourceMappingURLInTheMiddle) { |
24771 const char* chunks[] = {"function foo() { ret", "urn 13; }\n//#", | 24844 const char* chunks[] = {"function foo() { ret", "urn 13; }\n//#", |
24772 " sourceMappingURL=bar2.js\n", "foo();", NULL}; | 24845 " sourceMappingURL=bar2.js\n", "foo();", NULL}; |
24773 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, true, NULL, | 24846 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, true, NULL, |
24774 "bar2.js"); | 24847 "bar2.js"); |
24775 } | 24848 } |
OLD | NEW |