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

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

Issue 1094002: New GCCallbacks with additional parameters. (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: '' Created 10 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « src/heap.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2007-2009 the V8 project authors. All rights reserved. 1 // Copyright 2007-2009 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 9937 matching lines...) Expand 10 before | Expand all | Expand 10 after
9948 // This compile will get the code from the compilation cache. 9948 // This compile will get the code from the compilation cache.
9949 CompileRun(source); 9949 CompileRun(source);
9950 9950
9951 script = v8::Script::Compile(v8_str("new C1();")); 9951 script = v8::Script::Compile(v8_str("new C1();"));
9952 for (int i = 0; i < 10; i++) { 9952 for (int i = 0; i < 10; i++) {
9953 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); 9953 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run());
9954 CHECK_EQ(42, c1->Get(v8_str("x"))->Int32Value()); 9954 CHECK_EQ(42, c1->Get(v8_str("x"))->Int32Value());
9955 CHECK_EQ(23, c1->Get(v8_str("y"))->Int32Value()); 9955 CHECK_EQ(23, c1->Get(v8_str("y"))->Int32Value());
9956 } 9956 }
9957 } 9957 }
9958
9959 int prologue_call_count = 0;
9960 int epilogue_call_count = 0;
9961 int prologue_call_count_second = 0;
9962 int epilogue_call_count_second = 0;
9963
9964 void PrologueCallback(v8::GCType, v8::GCCallbackFlags) {
9965 ++prologue_call_count;
9966 }
9967
9968 void EpilogueCallback(v8::GCType, v8::GCCallbackFlags) {
9969 ++epilogue_call_count;
9970 }
9971
9972 void PrologueCallbackSecond(v8::GCType, v8::GCCallbackFlags) {
9973 ++prologue_call_count_second;
9974 }
9975
9976 void EpilogueCallbackSecond(v8::GCType, v8::GCCallbackFlags) {
9977 ++epilogue_call_count_second;
9978 }
9979
9980 TEST(GCCallbacks) {
9981 LocalContext context;
9982
9983 v8::V8::AddGCPrologueCallback(PrologueCallback);
9984 v8::V8::AddGCEpilogueCallback(EpilogueCallback);
9985 CHECK_EQ(0, prologue_call_count);
9986 CHECK_EQ(0, epilogue_call_count);
9987 i::Heap::CollectAllGarbage(false);
9988 CHECK_EQ(1, prologue_call_count);
9989 CHECK_EQ(1, epilogue_call_count);
9990 v8::V8::AddGCPrologueCallback(PrologueCallbackSecond);
9991 v8::V8::AddGCEpilogueCallback(EpilogueCallbackSecond);
9992 i::Heap::CollectAllGarbage(false);
9993 CHECK_EQ(2, prologue_call_count);
9994 CHECK_EQ(2, epilogue_call_count);
9995 CHECK_EQ(1, prologue_call_count_second);
9996 CHECK_EQ(1, epilogue_call_count_second);
9997 v8::V8::RemoveGCPrologueCallback(PrologueCallback);
9998 v8::V8::RemoveGCEpilogueCallback(EpilogueCallback);
9999 i::Heap::CollectAllGarbage(false);
10000 CHECK_EQ(2, prologue_call_count);
10001 CHECK_EQ(2, epilogue_call_count);
10002 CHECK_EQ(2, prologue_call_count_second);
10003 CHECK_EQ(2, epilogue_call_count_second);
10004 v8::V8::RemoveGCPrologueCallback(PrologueCallbackSecond);
10005 v8::V8::RemoveGCEpilogueCallback(EpilogueCallbackSecond);
10006 i::Heap::CollectAllGarbage(false);
10007 CHECK_EQ(2, prologue_call_count);
10008 CHECK_EQ(2, epilogue_call_count);
10009 CHECK_EQ(2, prologue_call_count_second);
10010 CHECK_EQ(2, epilogue_call_count_second);
10011 }
OLDNEW
« no previous file with comments | « src/heap.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698