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

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

Issue 501323002: Replace our homegrown ARRAY_SIZE() with Chrome's arraysize(). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 3 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
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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 "}" 256 "}"
257 "" 257 ""
258 "var obj = {};" 258 "var obj = {};"
259 "copy_props(obj);" 259 "copy_props(obj);"
260 "var unrel = new UnrelFun();" 260 "var unrel = new UnrelFun();"
261 "copy_props(unrel);"); 261 "copy_props(unrel);");
262 // Test with and without ICs 262 // Test with and without ICs
263 const char* test_objects[] = { 263 const char* test_objects[] = {
264 "fun_instance", "sub_fun_instance", "obj", "unrel" }; 264 "fun_instance", "sub_fun_instance", "obj", "unrel" };
265 unsigned bad_signature_start_offset = 2; 265 unsigned bad_signature_start_offset = 2;
266 for (unsigned i = 0; i < ARRAY_SIZE(test_objects); i++) { 266 for (unsigned i = 0; i < arraysize(test_objects); i++) {
267 i::ScopedVector<char> source(200); 267 i::ScopedVector<char> source(200);
268 i::SNPrintF( 268 i::SNPrintF(
269 source, "var test_object = %s; test_object", test_objects[i]); 269 source, "var test_object = %s; test_object", test_objects[i]);
270 Local<Value> test_object = CompileRun(source.start()); 270 Local<Value> test_object = CompileRun(source.start());
271 TestSignature("test_object.prop();", test_object); 271 TestSignature("test_object.prop();", test_object);
272 TestSignature("test_object.accessor;", test_object); 272 TestSignature("test_object.accessor;", test_object);
273 TestSignature("test_object[accessor_key];", test_object); 273 TestSignature("test_object[accessor_key];", test_object);
274 TestSignature("test_object.accessor = 1;", test_object); 274 TestSignature("test_object.accessor = 1;", test_object);
275 TestSignature("test_object[accessor_key] = 1;", test_object); 275 TestSignature("test_object[accessor_key] = 1;", test_object);
276 if (i >= bad_signature_start_offset) test_object = Local<Value>(); 276 if (i >= bad_signature_start_offset) test_object = Local<Value>();
(...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 1182
1183 THREADED_PROFILED_TEST(FastReturnValues) { 1183 THREADED_PROFILED_TEST(FastReturnValues) {
1184 LocalContext env; 1184 LocalContext env;
1185 v8::HandleScope scope(CcTest::isolate()); 1185 v8::HandleScope scope(CcTest::isolate());
1186 v8::Handle<v8::Value> value; 1186 v8::Handle<v8::Value> value;
1187 // check int32_t and uint32_t 1187 // check int32_t and uint32_t
1188 int32_t int_values[] = { 1188 int32_t int_values[] = {
1189 0, 234, -723, 1189 0, 234, -723,
1190 i::Smi::kMinValue, i::Smi::kMaxValue 1190 i::Smi::kMinValue, i::Smi::kMaxValue
1191 }; 1191 };
1192 for (size_t i = 0; i < ARRAY_SIZE(int_values); i++) { 1192 for (size_t i = 0; i < arraysize(int_values); i++) {
1193 for (int modifier = -1; modifier <= 1; modifier++) { 1193 for (int modifier = -1; modifier <= 1; modifier++) {
1194 int int_value = int_values[i] + modifier; 1194 int int_value = int_values[i] + modifier;
1195 // check int32_t 1195 // check int32_t
1196 fast_return_value_int32 = int_value; 1196 fast_return_value_int32 = int_value;
1197 value = TestFastReturnValues<int32_t>(); 1197 value = TestFastReturnValues<int32_t>();
1198 CHECK(value->IsInt32()); 1198 CHECK(value->IsInt32());
1199 CHECK(fast_return_value_int32 == value->Int32Value()); 1199 CHECK(fast_return_value_int32 == value->Int32Value());
1200 // check uint32_t 1200 // check uint32_t
1201 fast_return_value_uint32 = static_cast<uint32_t>(int_value); 1201 fast_return_value_uint32 = static_cast<uint32_t>(int_value);
1202 value = TestFastReturnValues<uint32_t>(); 1202 value = TestFastReturnValues<uint32_t>();
(...skipping 11 matching lines...) Expand all
1214 value = TestFastReturnValues<bool>(); 1214 value = TestFastReturnValues<bool>();
1215 CHECK(value->IsBoolean()); 1215 CHECK(value->IsBoolean());
1216 CHECK_EQ(fast_return_value_bool, value->ToBoolean()->Value()); 1216 CHECK_EQ(fast_return_value_bool, value->ToBoolean()->Value());
1217 } 1217 }
1218 // check oddballs 1218 // check oddballs
1219 ReturnValueOddball oddballs[] = { 1219 ReturnValueOddball oddballs[] = {
1220 kNullReturnValue, 1220 kNullReturnValue,
1221 kUndefinedReturnValue, 1221 kUndefinedReturnValue,
1222 kEmptyStringReturnValue 1222 kEmptyStringReturnValue
1223 }; 1223 };
1224 for (size_t i = 0; i < ARRAY_SIZE(oddballs); i++) { 1224 for (size_t i = 0; i < arraysize(oddballs); i++) {
1225 fast_return_value_void = oddballs[i]; 1225 fast_return_value_void = oddballs[i];
1226 value = TestFastReturnValues<void>(); 1226 value = TestFastReturnValues<void>();
1227 switch (fast_return_value_void) { 1227 switch (fast_return_value_void) {
1228 case kNullReturnValue: 1228 case kNullReturnValue:
1229 CHECK(value->IsNull()); 1229 CHECK(value->IsNull());
1230 break; 1230 break;
1231 case kUndefinedReturnValue: 1231 case kUndefinedReturnValue:
1232 CHECK(value->IsUndefined()); 1232 CHECK(value->IsUndefined());
1233 break; 1233 break;
1234 case kEmptyStringReturnValue: 1234 case kEmptyStringReturnValue:
(...skipping 17961 matching lines...) Expand 10 before | Expand all | Expand 10 after
19196 left = String::Concat(base, left); 19196 left = String::Concat(base, left);
19197 right = String::Concat(right, base); 19197 right = String::Concat(right, base);
19198 } 19198 }
19199 Handle<String> balanced = String::Concat(left, base); 19199 Handle<String> balanced = String::Concat(left, base);
19200 balanced = String::Concat(balanced, right); 19200 balanced = String::Concat(balanced, right);
19201 Handle<String> cons_strings[] = {left, balanced, right}; 19201 Handle<String> cons_strings[] = {left, balanced, right};
19202 Handle<String> two_byte = 19202 Handle<String> two_byte =
19203 String::NewExternal(isolate, 19203 String::NewExternal(isolate,
19204 new TestResource(string_contents, NULL, false)); 19204 new TestResource(string_contents, NULL, false));
19205 USE(two_byte); USE(cons_strings); 19205 USE(two_byte); USE(cons_strings);
19206 for (size_t i = 0; i < ARRAY_SIZE(cons_strings); i++) { 19206 for (size_t i = 0; i < arraysize(cons_strings); i++) {
19207 // Base assumptions. 19207 // Base assumptions.
19208 string = cons_strings[i]; 19208 string = cons_strings[i];
19209 CHECK(string->IsOneByte() && string->ContainsOnlyOneByte()); 19209 CHECK(string->IsOneByte() && string->ContainsOnlyOneByte());
19210 // Test left and right concatentation. 19210 // Test left and right concatentation.
19211 string = String::Concat(two_byte, cons_strings[i]); 19211 string = String::Concat(two_byte, cons_strings[i]);
19212 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte()); 19212 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte());
19213 string = String::Concat(cons_strings[i], two_byte); 19213 string = String::Concat(cons_strings[i], two_byte);
19214 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte()); 19214 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte());
19215 } 19215 }
19216 // Set bits in different positions 19216 // Set bits in different positions
(...skipping 3194 matching lines...) Expand 10 before | Expand all | Expand 10 after
22411 public: 22411 public:
22412 enum SignatureType { 22412 enum SignatureType {
22413 kNoSignature, 22413 kNoSignature,
22414 kSignatureOnReceiver, 22414 kSignatureOnReceiver,
22415 kSignatureOnPrototype 22415 kSignatureOnPrototype
22416 }; 22416 };
22417 22417
22418 void RunAll() { 22418 void RunAll() {
22419 SignatureType signature_types[] = 22419 SignatureType signature_types[] =
22420 {kNoSignature, kSignatureOnReceiver, kSignatureOnPrototype}; 22420 {kNoSignature, kSignatureOnReceiver, kSignatureOnPrototype};
22421 for (unsigned i = 0; i < ARRAY_SIZE(signature_types); i++) { 22421 for (unsigned i = 0; i < arraysize(signature_types); i++) {
22422 SignatureType signature_type = signature_types[i]; 22422 SignatureType signature_type = signature_types[i];
22423 for (int j = 0; j < 2; j++) { 22423 for (int j = 0; j < 2; j++) {
22424 bool global = j == 0; 22424 bool global = j == 0;
22425 int key = signature_type + 22425 int key = signature_type +
22426 ARRAY_SIZE(signature_types) * (global ? 1 : 0); 22426 arraysize(signature_types) * (global ? 1 : 0);
22427 Run(signature_type, global, key); 22427 Run(signature_type, global, key);
22428 } 22428 }
22429 } 22429 }
22430 } 22430 }
22431 22431
22432 void Run(SignatureType signature_type, bool global, int key) { 22432 void Run(SignatureType signature_type, bool global, int key) {
22433 v8::Isolate* isolate = CcTest::isolate(); 22433 v8::Isolate* isolate = CcTest::isolate();
22434 v8::HandleScope scope(isolate); 22434 v8::HandleScope scope(isolate);
22435 // Build a template for signature checks. 22435 // Build a template for signature checks.
22436 Local<v8::ObjectTemplate> signature_template; 22436 Local<v8::ObjectTemplate> signature_template;
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
22994 desc = x->GetOwnPropertyDescriptor(v8_str("p1")); 22994 desc = x->GetOwnPropertyDescriptor(v8_str("p1"));
22995 Local<Function> set = 22995 Local<Function> set =
22996 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("set"))); 22996 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("set")));
22997 Local<Function> get = 22997 Local<Function> get =
22998 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("get"))); 22998 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("get")));
22999 CHECK_EQ(v8_num(13), get->Call(x, 0, NULL)); 22999 CHECK_EQ(v8_num(13), get->Call(x, 0, NULL));
23000 Handle<Value> args[] = { v8_num(14) }; 23000 Handle<Value> args[] = { v8_num(14) };
23001 set->Call(x, 1, args); 23001 set->Call(x, 1, args);
23002 CHECK_EQ(v8_num(14), get->Call(x, 0, NULL)); 23002 CHECK_EQ(v8_num(14), get->Call(x, 0, NULL));
23003 } 23003 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698