Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: test/cctest/test-api.cc

Issue 886473005: Add WeakMap to v8.h (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Moved constructor&destructor to api.cc Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/runtime/runtime-collections.cc ('k') | test/cctest/test-weakmaps.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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(WeakKeyMap) {
4742 v8::Isolate* isolate = CcTest::isolate();
4743 i::SmartPointer<v8::WeakKeyMap> weak_map(v8::WeakKeyMap::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
4740 THREADED_TEST(GetSetProperty) { 4813 THREADED_TEST(GetSetProperty) {
4741 LocalContext context; 4814 LocalContext context;
4742 v8::Isolate* isolate = context->GetIsolate(); 4815 v8::Isolate* isolate = context->GetIsolate();
4743 v8::HandleScope scope(isolate); 4816 v8::HandleScope scope(isolate);
4744 context->Global()->Set(v8_str("foo"), v8_num(14)); 4817 context->Global()->Set(v8_str("foo"), v8_num(14));
4745 context->Global()->Set(v8_str("12"), v8_num(92)); 4818 context->Global()->Set(v8_str("12"), v8_num(92));
4746 context->Global()->Set(v8::Integer::New(isolate, 16), v8_num(32)); 4819 context->Global()->Set(v8::Integer::New(isolate, 16), v8_num(32));
4747 context->Global()->Set(v8_num(13), v8_num(56)); 4820 context->Global()->Set(v8_num(13), v8_num(56));
4748 Local<Value> foo = CompileRun("this.foo"); 4821 Local<Value> foo = CompileRun("this.foo");
4749 CHECK_EQ(14, foo->Int32Value()); 4822 CHECK_EQ(14, foo->Int32Value());
(...skipping 20140 matching lines...) Expand 10 before | Expand all | Expand 10 after
24890 "bar2.js"); 24963 "bar2.js");
24891 } 24964 }
24892 24965
24893 24966
24894 TEST(StreamingScriptWithSourceMappingURLInTheMiddle) { 24967 TEST(StreamingScriptWithSourceMappingURLInTheMiddle) {
24895 const char* chunks[] = {"function foo() { ret", "urn 13; }\n//#", 24968 const char* chunks[] = {"function foo() { ret", "urn 13; }\n//#",
24896 " sourceMappingURL=bar2.js\n", "foo();", NULL}; 24969 " sourceMappingURL=bar2.js\n", "foo();", NULL};
24897 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, true, NULL, 24970 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, true, NULL,
24898 "bar2.js"); 24971 "bar2.js");
24899 } 24972 }
OLDNEW
« no previous file with comments | « src/runtime/runtime-collections.cc ('k') | test/cctest/test-weakmaps.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698