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

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

Issue 155635: Introduce faster utilty methods for storing and retrieving native pointers (Closed)
Patch Set: last pass Created 11 years, 5 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/api.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 1248 matching lines...) Expand 10 before | Expand all | Expand 10 after
1259 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate(); 1259 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate();
1260 instance_templ->SetInternalFieldCount(1); 1260 instance_templ->SetInternalFieldCount(1);
1261 Local<v8::Object> obj = templ->GetFunction()->NewInstance(); 1261 Local<v8::Object> obj = templ->GetFunction()->NewInstance();
1262 CHECK_EQ(1, obj->InternalFieldCount()); 1262 CHECK_EQ(1, obj->InternalFieldCount());
1263 CHECK(obj->GetInternalField(0)->IsUndefined()); 1263 CHECK(obj->GetInternalField(0)->IsUndefined());
1264 obj->SetInternalField(0, v8_num(17)); 1264 obj->SetInternalField(0, v8_num(17));
1265 CHECK_EQ(17, obj->GetInternalField(0)->Int32Value()); 1265 CHECK_EQ(17, obj->GetInternalField(0)->Int32Value());
1266 } 1266 }
1267 1267
1268 1268
1269 THREADED_TEST(InternalFieldsNativePointers) {
1270 v8::HandleScope scope;
1271 LocalContext env;
1272
1273 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
1274 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate();
1275 instance_templ->SetInternalFieldCount(1);
1276 Local<v8::Object> obj = templ->GetFunction()->NewInstance();
1277 CHECK_EQ(1, obj->InternalFieldCount());
1278 CHECK(obj->GetPointerFromInternalField(0) == NULL);
1279
1280 char* data = new char[100];
1281
1282 void* aligned = data;
1283 CHECK_EQ(0, reinterpret_cast<uintptr_t>(aligned) & 0x1);
1284 void* unaligned = data + 1;
1285 CHECK_EQ(1, reinterpret_cast<uintptr_t>(unaligned) & 0x1);
1286
1287 // Check reading and writing aligned pointers.
1288 obj->SetPointerInInternalField(0, aligned);
1289 i::Heap::CollectAllGarbage();
1290 CHECK_EQ(aligned, obj->GetPointerFromInternalField(0));
1291
1292 // Check reading and writing unaligned pointers.
1293 obj->SetPointerInInternalField(0, unaligned);
1294 i::Heap::CollectAllGarbage();
1295 CHECK_EQ(unaligned, obj->GetPointerFromInternalField(0));
1296
1297 delete[] data;
1298 }
1299
1300
1269 THREADED_TEST(IdentityHash) { 1301 THREADED_TEST(IdentityHash) {
1270 v8::HandleScope scope; 1302 v8::HandleScope scope;
1271 LocalContext env; 1303 LocalContext env;
1272 1304
1273 // Ensure that the test starts with an fresh heap to test whether the hash 1305 // Ensure that the test starts with an fresh heap to test whether the hash
1274 // code is based on the address. 1306 // code is based on the address.
1275 i::Heap::CollectAllGarbage(); 1307 i::Heap::CollectAllGarbage();
1276 Local<v8::Object> obj = v8::Object::New(); 1308 Local<v8::Object> obj = v8::Object::New();
1277 int hash = obj->GetIdentityHash(); 1309 int hash = obj->GetIdentityHash();
1278 int hash1 = obj->GetIdentityHash(); 1310 int hash1 = obj->GetIdentityHash();
(...skipping 5813 matching lines...) Expand 10 before | Expand all | Expand 10 after
7092 "var obj = { x: { foo: 42 }, y: 87 };\n" 7124 "var obj = { x: { foo: 42 }, y: 87 };\n"
7093 "var x = obj.x;\n" 7125 "var x = obj.x;\n"
7094 "delete obj.y;\n" 7126 "delete obj.y;\n"
7095 "for (var i = 0; i < 5; i++) f(obj);"); 7127 "for (var i = 0; i < 5; i++) f(obj);");
7096 // Detach the global object to make 'this' refer directly to the 7128 // Detach the global object to make 'this' refer directly to the
7097 // global object (not the proxy), and make sure that the dictionary 7129 // global object (not the proxy), and make sure that the dictionary
7098 // load IC doesn't mess up loading directly from the global object. 7130 // load IC doesn't mess up loading directly from the global object.
7099 context->DetachGlobal(); 7131 context->DetachGlobal();
7100 CHECK_EQ(42, CompileRun("f(this).foo")->Int32Value()); 7132 CHECK_EQ(42, CompileRun("f(this).foo")->Int32Value());
7101 } 7133 }
OLDNEW
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698