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" | |
50 #include "src/snapshot.h" | 49 #include "src/snapshot.h" |
51 #include "src/unicode-inl.h" | 50 #include "src/unicode-inl.h" |
52 #include "src/utils.h" | 51 #include "src/utils.h" |
53 #include "src/vm-state.h" | 52 #include "src/vm-state.h" |
54 #include "test/cctest/cctest.h" | 53 #include "test/cctest/cctest.h" |
55 | 54 |
56 static const bool kLogThreading = false; | 55 static const bool kLogThreading = false; |
57 | 56 |
58 using ::v8::Boolean; | 57 using ::v8::Boolean; |
59 using ::v8::BooleanObject; | 58 using ::v8::BooleanObject; |
(...skipping 4671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4731 v8::False(isolate)); | 4730 v8::False(isolate)); |
4732 script = Script::Compile(v8_str("throw 'error'"), | 4731 script = Script::Compile(v8_str("throw 'error'"), |
4733 &origin); | 4732 &origin); |
4734 script->Run(); | 4733 script->Run(); |
4735 CHECK(message_received); | 4734 CHECK(message_received); |
4736 // clear out the message listener | 4735 // clear out the message listener |
4737 v8::V8::RemoveMessageListeners(check_message_5b); | 4736 v8::V8::RemoveMessageListeners(check_message_5b); |
4738 } | 4737 } |
4739 | 4738 |
4740 | 4739 |
4741 TEST(WeakMap) { | |
4742 v8::Isolate* isolate = CcTest::isolate(); | |
4743 i::SmartPointer<v8::WeakMap> weak_map(v8::WeakMap::New(isolate)); | |
4744 CHECK(!weak_map.is_empty()); | |
4745 | |
4746 LocalContext env; | |
4747 HandleScope scope(isolate); | |
4748 | |
4749 Local<Object> value = v8::Object::New(isolate); | |
4750 | |
4751 Local<Object> local1 = v8::Object::New(isolate); | |
4752 CHECK(!weak_map->Has(local1)); | |
4753 CHECK(weak_map->Get(local1)->IsUndefined()); | |
4754 weak_map->Set(local1, value); | |
4755 CHECK(weak_map->Has(local1)); | |
4756 CHECK(value->Equals(weak_map->Get(local1))); | |
4757 | |
4758 WeakCallCounter counter(1234); | |
4759 WeakCallCounterAndPersistent<Value> o1(&counter); | |
4760 WeakCallCounterAndPersistent<Value> o2(&counter); | |
4761 WeakCallCounterAndPersistent<Value> s1(&counter); | |
4762 { | |
4763 HandleScope scope(isolate); | |
4764 Local<v8::Object> obj1 = v8::Object::New(isolate); | |
4765 Local<v8::Object> obj2 = v8::Object::New(isolate); | |
4766 Local<v8::Symbol> sym1 = v8::Symbol::New(isolate); | |
4767 | |
4768 weak_map->Set(obj1, value); | |
4769 weak_map->Set(obj2, value); | |
4770 weak_map->Set(sym1, value); | |
4771 | |
4772 o1.handle.Reset(isolate, obj1); | |
4773 o2.handle.Reset(isolate, obj2); | |
4774 s1.handle.Reset(isolate, sym1); | |
4775 | |
4776 CHECK(weak_map->Has(local1)); | |
4777 CHECK(weak_map->Has(obj1)); | |
4778 CHECK(weak_map->Has(obj2)); | |
4779 CHECK(weak_map->Has(sym1)); | |
4780 | |
4781 CHECK(value->Equals(weak_map->Get(local1))); | |
4782 CHECK(value->Equals(weak_map->Get(obj1))); | |
4783 CHECK(value->Equals(weak_map->Get(obj2))); | |
4784 CHECK(value->Equals(weak_map->Get(sym1))); | |
4785 } | |
4786 CcTest::heap()->CollectAllGarbage(TestHeap::Heap::kNoGCFlags); | |
4787 { | |
4788 HandleScope scope(isolate); | |
4789 CHECK(value->Equals(weak_map->Get(local1))); | |
4790 CHECK(value->Equals(weak_map->Get(Local<Value>::New(isolate, o1.handle)))); | |
4791 CHECK(value->Equals(weak_map->Get(Local<Value>::New(isolate, o2.handle)))); | |
4792 CHECK(value->Equals(weak_map->Get(Local<Value>::New(isolate, s1.handle)))); | |
4793 } | |
4794 | |
4795 o1.handle.SetWeak(&o1, &WeakPointerCallback); | |
4796 o2.handle.SetWeak(&o2, &WeakPointerCallback); | |
4797 s1.handle.SetWeak(&s1, &WeakPointerCallback); | |
4798 | |
4799 CcTest::heap()->CollectAllGarbage(TestHeap::Heap::kNoGCFlags); | |
4800 CHECK_EQ(3, counter.NumberOfWeakCalls()); | |
4801 | |
4802 CHECK(o1.handle.IsEmpty()); | |
4803 CHECK(o2.handle.IsEmpty()); | |
4804 CHECK(s1.handle.IsEmpty()); | |
4805 | |
4806 CHECK(value->Equals(weak_map->Get(local1))); | |
4807 CHECK(weak_map->Delete(local1)); | |
4808 CHECK(!weak_map->Has(local1)); | |
4809 CHECK(weak_map->Get(local1)->IsUndefined()); | |
4810 } | |
4811 | |
4812 | |
4813 THREADED_TEST(GetSetProperty) { | 4740 THREADED_TEST(GetSetProperty) { |
4814 LocalContext context; | 4741 LocalContext context; |
4815 v8::Isolate* isolate = context->GetIsolate(); | 4742 v8::Isolate* isolate = context->GetIsolate(); |
4816 v8::HandleScope scope(isolate); | 4743 v8::HandleScope scope(isolate); |
4817 context->Global()->Set(v8_str("foo"), v8_num(14)); | 4744 context->Global()->Set(v8_str("foo"), v8_num(14)); |
4818 context->Global()->Set(v8_str("12"), v8_num(92)); | 4745 context->Global()->Set(v8_str("12"), v8_num(92)); |
4819 context->Global()->Set(v8::Integer::New(isolate, 16), v8_num(32)); | 4746 context->Global()->Set(v8::Integer::New(isolate, 16), v8_num(32)); |
4820 context->Global()->Set(v8_num(13), v8_num(56)); | 4747 context->Global()->Set(v8_num(13), v8_num(56)); |
4821 Local<Value> foo = CompileRun("this.foo"); | 4748 Local<Value> foo = CompileRun("this.foo"); |
4822 CHECK_EQ(14, foo->Int32Value()); | 4749 CHECK_EQ(14, foo->Int32Value()); |
(...skipping 20101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
24924 "bar2.js"); | 24851 "bar2.js"); |
24925 } | 24852 } |
24926 | 24853 |
24927 | 24854 |
24928 TEST(StreamingScriptWithSourceMappingURLInTheMiddle) { | 24855 TEST(StreamingScriptWithSourceMappingURLInTheMiddle) { |
24929 const char* chunks[] = {"function foo() { ret", "urn 13; }\n//#", | 24856 const char* chunks[] = {"function foo() { ret", "urn 13; }\n//#", |
24930 " sourceMappingURL=bar2.js\n", "foo();", NULL}; | 24857 " sourceMappingURL=bar2.js\n", "foo();", NULL}; |
24931 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, true, NULL, | 24858 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, true, NULL, |
24932 "bar2.js"); | 24859 "bar2.js"); |
24933 } | 24860 } |
OLD | NEW |