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

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

Issue 115267: Fix for issue 339:... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 7 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/objects.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-2008 the V8 project authors. All rights reserved. 1 // Copyright 2007-2008 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 1309 matching lines...) Expand 10 before | Expand all | Expand 10 after
1320 CHECK(obj->Delete(prop_name)); 1320 CHECK(obj->Delete(prop_name));
1321 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); 1321 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value());
1322 1322
1323 i::Heap::CollectAllGarbage(); 1323 i::Heap::CollectAllGarbage();
1324 1324
1325 CHECK(obj->DeleteHiddenValue(key)); 1325 CHECK(obj->DeleteHiddenValue(key));
1326 CHECK(obj->GetHiddenValue(key).IsEmpty()); 1326 CHECK(obj->GetHiddenValue(key).IsEmpty());
1327 } 1327 }
1328 1328
1329 1329
1330 static v8::Handle<Value> InterceptorForHiddenProperties(
1331 Local<String> name, const AccessorInfo& info) {
1332 // Make sure objects move.
1333 bool saved_always_compact = i::FLAG_always_compact;
1334 if (!i::FLAG_never_compact) {
1335 i::FLAG_always_compact = true;
1336 }
1337 // The whole goal of this interceptor is to cause a GC during local property
1338 // lookup.
1339 i::Heap::CollectAllGarbage();
1340 i::FLAG_always_compact = saved_always_compact;
1341 return v8::Handle<Value>();
1342 }
1343
1344
1345 THREADED_TEST(HiddenPropertiesWithInterceptors) {
1346 v8::HandleScope scope;
1347 LocalContext context;
1348
1349 v8::Local<v8::String> key = v8_str("api-test::hidden-key");
1350
1351 // Associate an interceptor with an object and start setting hidden values.
1352 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
1353 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate();
1354 instance_templ->SetNamedPropertyHandler(InterceptorForHiddenProperties);
1355 Local<v8::Function> function = fun_templ->GetFunction();
1356 Local<v8::Object> obj = function->NewInstance();
1357 CHECK(obj->SetHiddenValue(key, v8::Integer::New(2302)));
1358 CHECK_EQ(2302, obj->GetHiddenValue(key)->Int32Value());
1359 }
1360
1361
1330 THREADED_TEST(External) { 1362 THREADED_TEST(External) {
1331 v8::HandleScope scope; 1363 v8::HandleScope scope;
1332 int x = 3; 1364 int x = 3;
1333 Local<v8::External> ext = v8::External::New(&x); 1365 Local<v8::External> ext = v8::External::New(&x);
1334 LocalContext env; 1366 LocalContext env;
1335 env->Global()->Set(v8_str("ext"), ext); 1367 env->Global()->Set(v8_str("ext"), ext);
1336 Local<Value> reext_obj = Script::Compile(v8_str("this.ext"))->Run(); 1368 Local<Value> reext_obj = Script::Compile(v8_str("this.ext"))->Run();
1337 v8::Handle<v8::External> reext = v8::Handle<v8::External>::Cast(reext_obj); 1369 v8::Handle<v8::External> reext = v8::Handle<v8::External>::Cast(reext_obj);
1338 int* ptr = static_cast<int*>(reext->Value()); 1370 int* ptr = static_cast<int*>(reext->Value());
1339 CHECK_EQ(x, 3); 1371 CHECK_EQ(x, 3);
(...skipping 5224 matching lines...) Expand 10 before | Expand all | Expand 10 after
6564 // the property 6596 // the property
6565 pass_on_get = false; 6597 pass_on_get = false;
6566 CHECK_EQ(3, global->Get(some_property)->Int32Value()); 6598 CHECK_EQ(3, global->Get(some_property)->Int32Value());
6567 CHECK_EQ(1, force_set_set_count); 6599 CHECK_EQ(1, force_set_set_count);
6568 CHECK_EQ(5, force_set_get_count); 6600 CHECK_EQ(5, force_set_get_count);
6569 // The interceptor should also work for other properties 6601 // The interceptor should also work for other properties
6570 CHECK_EQ(3, global->Get(v8::String::New("b"))->Int32Value()); 6602 CHECK_EQ(3, global->Get(v8::String::New("b"))->Int32Value());
6571 CHECK_EQ(1, force_set_set_count); 6603 CHECK_EQ(1, force_set_set_count);
6572 CHECK_EQ(6, force_set_get_count); 6604 CHECK_EQ(6, force_set_get_count);
6573 } 6605 }
OLDNEW
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698