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

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

Issue 157543002: A64: Synchronize with r18581. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-accessors.cc ('k') | test/cctest/test-assembler-arm.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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 static Local<Value> signature_expected_receiver; 146 static Local<Value> signature_expected_receiver;
147 static void IncrementingSignatureCallback( 147 static void IncrementingSignatureCallback(
148 const v8::FunctionCallbackInfo<v8::Value>& args) { 148 const v8::FunctionCallbackInfo<v8::Value>& args) {
149 ApiTestFuzzer::Fuzz(); 149 ApiTestFuzzer::Fuzz();
150 signature_callback_count++; 150 signature_callback_count++;
151 CHECK_EQ(signature_expected_receiver, args.Holder()); 151 CHECK_EQ(signature_expected_receiver, args.Holder());
152 CHECK_EQ(signature_expected_receiver, args.This()); 152 CHECK_EQ(signature_expected_receiver, args.This());
153 v8::Handle<v8::Array> result = 153 v8::Handle<v8::Array> result =
154 v8::Array::New(args.GetIsolate(), args.Length()); 154 v8::Array::New(args.GetIsolate(), args.Length());
155 for (int i = 0; i < args.Length(); i++) 155 for (int i = 0; i < args.Length(); i++)
156 result->Set(v8::Integer::New(i), args[i]); 156 result->Set(v8::Integer::New(args.GetIsolate(), i), args[i]);
157 args.GetReturnValue().Set(result); 157 args.GetReturnValue().Set(result);
158 } 158 }
159 159
160 160
161 static void SignatureCallback( 161 static void SignatureCallback(
162 const v8::FunctionCallbackInfo<v8::Value>& args) { 162 const v8::FunctionCallbackInfo<v8::Value>& args) {
163 ApiTestFuzzer::Fuzz(); 163 ApiTestFuzzer::Fuzz();
164 v8::Handle<v8::Array> result = 164 v8::Handle<v8::Array> result =
165 v8::Array::New(args.GetIsolate(), args.Length()); 165 v8::Array::New(args.GetIsolate(), args.Length());
166 for (int i = 0; i < args.Length(); i++) { 166 for (int i = 0; i < args.Length(); i++) {
167 result->Set(v8::Integer::New(i), args[i]); 167 result->Set(v8::Integer::New(args.GetIsolate(), i), args[i]);
168 } 168 }
169 args.GetReturnValue().Set(result); 169 args.GetReturnValue().Set(result);
170 } 170 }
171 171
172 172
173 // Tests that call v8::V8::Dispose() cannot be threaded. 173 // Tests that call v8::V8::Dispose() cannot be threaded.
174 TEST(InitializeAndDisposeOnce) { 174 TEST(InitializeAndDisposeOnce) {
175 CHECK(v8::V8::Initialize()); 175 CHECK(v8::V8::Initialize());
176 CHECK(v8::V8::Dispose()); 176 CHECK(v8::V8::Dispose());
177 } 177 }
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 undef_str->WriteUtf8(value); 404 undef_str->WriteUtf8(value);
405 CHECK_EQ(0, strcmp(value, "undefined")); 405 CHECK_EQ(0, strcmp(value, "undefined"));
406 i::DeleteArray(value); 406 i::DeleteArray(value);
407 } 407 }
408 408
409 409
410 THREADED_TEST(Access) { 410 THREADED_TEST(Access) {
411 LocalContext env; 411 LocalContext env;
412 v8::Isolate* isolate = env->GetIsolate(); 412 v8::Isolate* isolate = env->GetIsolate();
413 v8::HandleScope scope(isolate); 413 v8::HandleScope scope(isolate);
414 Local<v8::Object> obj = v8::Object::New(); 414 Local<v8::Object> obj = v8::Object::New(isolate);
415 Local<Value> foo_before = obj->Get(v8_str("foo")); 415 Local<Value> foo_before = obj->Get(v8_str("foo"));
416 CHECK(foo_before->IsUndefined()); 416 CHECK(foo_before->IsUndefined());
417 Local<String> bar_str = v8_str("bar"); 417 Local<String> bar_str = v8_str("bar");
418 obj->Set(v8_str("foo"), bar_str); 418 obj->Set(v8_str("foo"), bar_str);
419 Local<Value> foo_after = obj->Get(v8_str("foo")); 419 Local<Value> foo_after = obj->Get(v8_str("foo"));
420 CHECK(!foo_after->IsUndefined()); 420 CHECK(!foo_after->IsUndefined());
421 CHECK(foo_after->IsString()); 421 CHECK(foo_after->IsString());
422 CHECK_EQ(bar_str, foo_after); 422 CHECK_EQ(bar_str, foo_after);
423 } 423 }
424 424
425 425
426 THREADED_TEST(AccessElement) { 426 THREADED_TEST(AccessElement) {
427 LocalContext env; 427 LocalContext env;
428 v8::HandleScope scope(env->GetIsolate()); 428 v8::HandleScope scope(env->GetIsolate());
429 Local<v8::Object> obj = v8::Object::New(); 429 Local<v8::Object> obj = v8::Object::New(env->GetIsolate());
430 Local<Value> before = obj->Get(1); 430 Local<Value> before = obj->Get(1);
431 CHECK(before->IsUndefined()); 431 CHECK(before->IsUndefined());
432 Local<String> bar_str = v8_str("bar"); 432 Local<String> bar_str = v8_str("bar");
433 obj->Set(1, bar_str); 433 obj->Set(1, bar_str);
434 Local<Value> after = obj->Get(1); 434 Local<Value> after = obj->Get(1);
435 CHECK(!after->IsUndefined()); 435 CHECK(!after->IsUndefined());
436 CHECK(after->IsString()); 436 CHECK(after->IsString());
437 CHECK_EQ(bar_str, after); 437 CHECK_EQ(bar_str, after);
438 438
439 Local<v8::Array> value = CompileRun("[\"a\", \"b\"]").As<v8::Array>(); 439 Local<v8::Array> value = CompileRun("[\"a\", \"b\"]").As<v8::Array>();
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 static void SimpleCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { 1096 static void SimpleCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
1097 ApiTestFuzzer::Fuzz(); 1097 ApiTestFuzzer::Fuzz();
1098 CheckReturnValue(info, FUNCTION_ADDR(SimpleCallback)); 1098 CheckReturnValue(info, FUNCTION_ADDR(SimpleCallback));
1099 info.GetReturnValue().Set(v8_num(51423 + info.Length())); 1099 info.GetReturnValue().Set(v8_num(51423 + info.Length()));
1100 } 1100 }
1101 1101
1102 1102
1103 template<typename Callback> 1103 template<typename Callback>
1104 static void TestSimpleCallback(Callback callback) { 1104 static void TestSimpleCallback(Callback callback) {
1105 LocalContext env; 1105 LocalContext env;
1106 v8::HandleScope scope(env->GetIsolate()); 1106 v8::Isolate* isolate = env->GetIsolate();
1107 v8::HandleScope scope(isolate);
1107 1108
1108 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); 1109 v8::Handle<v8::ObjectTemplate> object_template =
1109 object_template->Set(env->GetIsolate(), "callback", 1110 v8::ObjectTemplate::New(isolate);
1110 v8::FunctionTemplate::New(env->GetIsolate(), callback)); 1111 object_template->Set(isolate, "callback",
1112 v8::FunctionTemplate::New(isolate, callback));
1111 v8::Local<v8::Object> object = object_template->NewInstance(); 1113 v8::Local<v8::Object> object = object_template->NewInstance();
1112 (*env)->Global()->Set(v8_str("callback_object"), object); 1114 (*env)->Global()->Set(v8_str("callback_object"), object);
1113 v8::Handle<v8::Script> script; 1115 v8::Handle<v8::Script> script;
1114 script = v8_compile("callback_object.callback(17)"); 1116 script = v8_compile("callback_object.callback(17)");
1115 for (int i = 0; i < 30; i++) { 1117 for (int i = 0; i < 30; i++) {
1116 CHECK_EQ(51424, script->Run()->Int32Value()); 1118 CHECK_EQ(51424, script->Run()->Int32Value());
1117 } 1119 }
1118 script = v8_compile("callback_object.callback(17, 24)"); 1120 script = v8_compile("callback_object.callback(17, 24)");
1119 for (int i = 0; i < 30; i++) { 1121 for (int i = 0; i < 30; i++) {
1120 CHECK_EQ(51425, script->Run()->Int32Value()); 1122 CHECK_EQ(51425, script->Run()->Int32Value());
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1192 case kEmptyStringReturnValue: 1194 case kEmptyStringReturnValue:
1193 info.GetReturnValue().SetEmptyString(); 1195 info.GetReturnValue().SetEmptyString();
1194 break; 1196 break;
1195 } 1197 }
1196 } 1198 }
1197 1199
1198 template<> 1200 template<>
1199 void FastReturnValueCallback<Object>( 1201 void FastReturnValueCallback<Object>(
1200 const v8::FunctionCallbackInfo<v8::Value>& info) { 1202 const v8::FunctionCallbackInfo<v8::Value>& info) {
1201 v8::Handle<v8::Object> object; 1203 v8::Handle<v8::Object> object;
1202 if (!fast_return_value_object_is_empty) object = Object::New(); 1204 if (!fast_return_value_object_is_empty) {
1205 object = Object::New(info.GetIsolate());
1206 }
1203 info.GetReturnValue().Set(object); 1207 info.GetReturnValue().Set(object);
1204 } 1208 }
1205 1209
1206 template<typename T> 1210 template<typename T>
1207 Handle<Value> TestFastReturnValues() { 1211 Handle<Value> TestFastReturnValues() {
1208 LocalContext env; 1212 LocalContext env;
1209 v8::EscapableHandleScope scope(env->GetIsolate()); 1213 v8::Isolate* isolate = env->GetIsolate();
1210 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); 1214 v8::EscapableHandleScope scope(isolate);
1215 v8::Handle<v8::ObjectTemplate> object_template =
1216 v8::ObjectTemplate::New(isolate);
1211 v8::FunctionCallback callback = &FastReturnValueCallback<T>; 1217 v8::FunctionCallback callback = &FastReturnValueCallback<T>;
1212 object_template->Set(env->GetIsolate(), "callback", 1218 object_template->Set(isolate, "callback",
1213 v8::FunctionTemplate::New(env->GetIsolate(), callback)); 1219 v8::FunctionTemplate::New(isolate, callback));
1214 v8::Local<v8::Object> object = object_template->NewInstance(); 1220 v8::Local<v8::Object> object = object_template->NewInstance();
1215 (*env)->Global()->Set(v8_str("callback_object"), object); 1221 (*env)->Global()->Set(v8_str("callback_object"), object);
1216 return scope.Escape(CompileRun("callback_object.callback()")); 1222 return scope.Escape(CompileRun("callback_object.callback()"));
1217 } 1223 }
1218 1224
1219 1225
1220 THREADED_PROFILED_TEST(FastReturnValues) { 1226 THREADED_PROFILED_TEST(FastReturnValues) {
1221 LocalContext env; 1227 LocalContext env;
1222 v8::HandleScope scope(CcTest::isolate()); 1228 v8::HandleScope scope(CcTest::isolate());
1223 v8::Handle<v8::Value> value; 1229 v8::Handle<v8::Value> value;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1330 1336
1331 1337
1332 static void TestExternalPointerWrapping() { 1338 static void TestExternalPointerWrapping() {
1333 LocalContext env; 1339 LocalContext env;
1334 v8::Isolate* isolate = env->GetIsolate(); 1340 v8::Isolate* isolate = env->GetIsolate();
1335 v8::HandleScope scope(isolate); 1341 v8::HandleScope scope(isolate);
1336 1342
1337 v8::Handle<v8::Value> data = 1343 v8::Handle<v8::Value> data =
1338 v8::External::New(isolate, expected_ptr); 1344 v8::External::New(isolate, expected_ptr);
1339 1345
1340 v8::Handle<v8::Object> obj = v8::Object::New(); 1346 v8::Handle<v8::Object> obj = v8::Object::New(isolate);
1341 obj->Set(v8_str("func"), 1347 obj->Set(v8_str("func"),
1342 v8::FunctionTemplate::New(isolate, callback, data)->GetFunction()); 1348 v8::FunctionTemplate::New(isolate, callback, data)->GetFunction());
1343 env->Global()->Set(v8_str("obj"), obj); 1349 env->Global()->Set(v8_str("obj"), obj);
1344 1350
1345 CHECK(CompileRun( 1351 CHECK(CompileRun(
1346 "function foo() {\n" 1352 "function foo() {\n"
1347 " for (var i = 0; i < 13; i++) obj.func();\n" 1353 " for (var i = 0; i < 13; i++) obj.func();\n"
1348 "}\n" 1354 "}\n"
1349 "foo(), true")->BooleanValue()); 1355 "foo(), true")->BooleanValue());
1350 } 1356 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1439 other_instance->FindInstanceInPrototypeChain(base)); 1445 other_instance->FindInstanceInPrototypeChain(base));
1440 CHECK_EQ(derived_instance2, 1446 CHECK_EQ(derived_instance2,
1441 other_instance->FindInstanceInPrototypeChain(derived)); 1447 other_instance->FindInstanceInPrototypeChain(derived));
1442 CHECK_EQ(other_instance, 1448 CHECK_EQ(other_instance,
1443 other_instance->FindInstanceInPrototypeChain(other)); 1449 other_instance->FindInstanceInPrototypeChain(other));
1444 } 1450 }
1445 1451
1446 1452
1447 THREADED_TEST(TinyInteger) { 1453 THREADED_TEST(TinyInteger) {
1448 LocalContext env; 1454 LocalContext env;
1449 v8::HandleScope scope(env->GetIsolate()); 1455 v8::Isolate* isolate = env->GetIsolate();
1450 v8::Isolate* isolate = CcTest::isolate(); 1456 v8::HandleScope scope(isolate);
1451 1457
1452 int32_t value = 239; 1458 int32_t value = 239;
1453 Local<v8::Integer> value_obj = v8::Integer::New(value); 1459 Local<v8::Integer> value_obj = v8::Integer::New(isolate, value);
1454 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1460 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1455 1461
1456 value_obj = v8::Integer::New(value, isolate); 1462 value_obj = v8::Integer::New(isolate, value);
1457 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1463 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1458 } 1464 }
1459 1465
1460 1466
1461 THREADED_TEST(BigSmiInteger) { 1467 THREADED_TEST(BigSmiInteger) {
1462 LocalContext env; 1468 LocalContext env;
1463 v8::HandleScope scope(env->GetIsolate()); 1469 v8::HandleScope scope(env->GetIsolate());
1464 v8::Isolate* isolate = CcTest::isolate(); 1470 v8::Isolate* isolate = CcTest::isolate();
1465 1471
1466 int32_t value = i::Smi::kMaxValue; 1472 int32_t value = i::Smi::kMaxValue;
1467 // We cannot add one to a Smi::kMaxValue without wrapping. 1473 // We cannot add one to a Smi::kMaxValue without wrapping.
1468 if (i::SmiValuesAre31Bits()) { 1474 if (i::SmiValuesAre31Bits()) {
1469 CHECK(i::Smi::IsValid(value)); 1475 CHECK(i::Smi::IsValid(value));
1470 CHECK(!i::Smi::IsValid(value + 1)); 1476 CHECK(!i::Smi::IsValid(value + 1));
1471 1477
1472 Local<v8::Integer> value_obj = v8::Integer::New(value); 1478 Local<v8::Integer> value_obj = v8::Integer::New(isolate, value);
1473 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1479 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1474 1480
1475 value_obj = v8::Integer::New(value, isolate); 1481 value_obj = v8::Integer::New(isolate, value);
1476 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1482 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1477 } 1483 }
1478 } 1484 }
1479 1485
1480 1486
1481 THREADED_TEST(BigInteger) { 1487 THREADED_TEST(BigInteger) {
1482 LocalContext env; 1488 LocalContext env;
1483 v8::HandleScope scope(env->GetIsolate()); 1489 v8::HandleScope scope(env->GetIsolate());
1484 v8::Isolate* isolate = CcTest::isolate(); 1490 v8::Isolate* isolate = CcTest::isolate();
1485 1491
1486 // We cannot add one to a Smi::kMaxValue without wrapping. 1492 // We cannot add one to a Smi::kMaxValue without wrapping.
1487 if (i::SmiValuesAre31Bits()) { 1493 if (i::SmiValuesAre31Bits()) {
1488 // The casts allow this to compile, even if Smi::kMaxValue is 2^31-1. 1494 // The casts allow this to compile, even if Smi::kMaxValue is 2^31-1.
1489 // The code will not be run in that case, due to the "if" guard. 1495 // The code will not be run in that case, due to the "if" guard.
1490 int32_t value = 1496 int32_t value =
1491 static_cast<int32_t>(static_cast<uint32_t>(i::Smi::kMaxValue) + 1); 1497 static_cast<int32_t>(static_cast<uint32_t>(i::Smi::kMaxValue) + 1);
1492 CHECK(value > i::Smi::kMaxValue); 1498 CHECK(value > i::Smi::kMaxValue);
1493 CHECK(!i::Smi::IsValid(value)); 1499 CHECK(!i::Smi::IsValid(value));
1494 1500
1495 Local<v8::Integer> value_obj = v8::Integer::New(value); 1501 Local<v8::Integer> value_obj = v8::Integer::New(isolate, value);
1496 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1502 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1497 1503
1498 value_obj = v8::Integer::New(value, isolate); 1504 value_obj = v8::Integer::New(isolate, value);
1499 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1505 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1500 } 1506 }
1501 } 1507 }
1502 1508
1503 1509
1504 THREADED_TEST(TinyUnsignedInteger) { 1510 THREADED_TEST(TinyUnsignedInteger) {
1505 LocalContext env; 1511 LocalContext env;
1506 v8::HandleScope scope(env->GetIsolate()); 1512 v8::HandleScope scope(env->GetIsolate());
1507 v8::Isolate* isolate = CcTest::isolate(); 1513 v8::Isolate* isolate = CcTest::isolate();
1508 1514
1509 uint32_t value = 239; 1515 uint32_t value = 239;
1510 1516
1511 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(value); 1517 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(isolate, value);
1512 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1518 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1513 1519
1514 value_obj = v8::Integer::NewFromUnsigned(value, isolate); 1520 value_obj = v8::Integer::NewFromUnsigned(isolate, value);
1515 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1521 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1516 } 1522 }
1517 1523
1518 1524
1519 THREADED_TEST(BigUnsignedSmiInteger) { 1525 THREADED_TEST(BigUnsignedSmiInteger) {
1520 LocalContext env; 1526 LocalContext env;
1521 v8::HandleScope scope(env->GetIsolate()); 1527 v8::HandleScope scope(env->GetIsolate());
1522 v8::Isolate* isolate = CcTest::isolate(); 1528 v8::Isolate* isolate = CcTest::isolate();
1523 1529
1524 uint32_t value = static_cast<uint32_t>(i::Smi::kMaxValue); 1530 uint32_t value = static_cast<uint32_t>(i::Smi::kMaxValue);
1525 CHECK(i::Smi::IsValid(value)); 1531 CHECK(i::Smi::IsValid(value));
1526 CHECK(!i::Smi::IsValid(value + 1)); 1532 CHECK(!i::Smi::IsValid(value + 1));
1527 1533
1528 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(value); 1534 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(isolate, value);
1529 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1535 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1530 1536
1531 value_obj = v8::Integer::NewFromUnsigned(value, isolate); 1537 value_obj = v8::Integer::NewFromUnsigned(isolate, value);
1532 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1538 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1533 } 1539 }
1534 1540
1535 1541
1536 THREADED_TEST(BigUnsignedInteger) { 1542 THREADED_TEST(BigUnsignedInteger) {
1537 LocalContext env; 1543 LocalContext env;
1538 v8::HandleScope scope(env->GetIsolate()); 1544 v8::HandleScope scope(env->GetIsolate());
1539 v8::Isolate* isolate = CcTest::isolate(); 1545 v8::Isolate* isolate = CcTest::isolate();
1540 1546
1541 uint32_t value = static_cast<uint32_t>(i::Smi::kMaxValue) + 1; 1547 uint32_t value = static_cast<uint32_t>(i::Smi::kMaxValue) + 1;
1542 CHECK(value > static_cast<uint32_t>(i::Smi::kMaxValue)); 1548 CHECK(value > static_cast<uint32_t>(i::Smi::kMaxValue));
1543 CHECK(!i::Smi::IsValid(value)); 1549 CHECK(!i::Smi::IsValid(value));
1544 1550
1545 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(value); 1551 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(isolate, value);
1546 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1552 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1547 1553
1548 value_obj = v8::Integer::NewFromUnsigned(value, isolate); 1554 value_obj = v8::Integer::NewFromUnsigned(isolate, value);
1549 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1555 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1550 } 1556 }
1551 1557
1552 1558
1553 THREADED_TEST(OutOfSignedRangeUnsignedInteger) { 1559 THREADED_TEST(OutOfSignedRangeUnsignedInteger) {
1554 LocalContext env; 1560 LocalContext env;
1555 v8::HandleScope scope(env->GetIsolate()); 1561 v8::HandleScope scope(env->GetIsolate());
1556 v8::Isolate* isolate = CcTest::isolate(); 1562 v8::Isolate* isolate = CcTest::isolate();
1557 1563
1558 uint32_t INT32_MAX_AS_UINT = (1U << 31) - 1; 1564 uint32_t INT32_MAX_AS_UINT = (1U << 31) - 1;
1559 uint32_t value = INT32_MAX_AS_UINT + 1; 1565 uint32_t value = INT32_MAX_AS_UINT + 1;
1560 CHECK(value > INT32_MAX_AS_UINT); // No overflow. 1566 CHECK(value > INT32_MAX_AS_UINT); // No overflow.
1561 1567
1562 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(value); 1568 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(isolate, value);
1563 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1569 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1564 1570
1565 value_obj = v8::Integer::NewFromUnsigned(value, isolate); 1571 value_obj = v8::Integer::NewFromUnsigned(isolate, value);
1566 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1572 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1567 } 1573 }
1568 1574
1569 1575
1570 THREADED_TEST(IsNativeError) { 1576 THREADED_TEST(IsNativeError) {
1571 LocalContext env; 1577 LocalContext env;
1572 v8::HandleScope scope(env->GetIsolate()); 1578 v8::HandleScope scope(env->GetIsolate());
1573 v8::Handle<Value> syntax_error = CompileRun( 1579 v8::Handle<Value> syntax_error = CompileRun(
1574 "var out = 0; try { eval(\"#\"); } catch(x) { out = x; } out; "); 1580 "var out = 0; try { eval(\"#\"); } catch(x) { out = x; } out; ");
1575 CHECK(syntax_error->IsNativeError()); 1581 CHECK(syntax_error->IsNativeError());
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1701 CHECK(true_boolean_object->ValueOf()); 1707 CHECK(true_boolean_object->ValueOf());
1702 CHECK(!true_boolean_object->IsTrue()); 1708 CHECK(!true_boolean_object->IsTrue());
1703 CHECK(!true_boolean_object->IsFalse()); 1709 CHECK(!true_boolean_object->IsFalse());
1704 } 1710 }
1705 1711
1706 1712
1707 THREADED_TEST(Number) { 1713 THREADED_TEST(Number) {
1708 LocalContext env; 1714 LocalContext env;
1709 v8::HandleScope scope(env->GetIsolate()); 1715 v8::HandleScope scope(env->GetIsolate());
1710 double PI = 3.1415926; 1716 double PI = 3.1415926;
1711 Local<v8::Number> pi_obj = v8::Number::New(PI); 1717 Local<v8::Number> pi_obj = v8::Number::New(env->GetIsolate(), PI);
1712 CHECK_EQ(PI, pi_obj->NumberValue()); 1718 CHECK_EQ(PI, pi_obj->NumberValue());
1713 } 1719 }
1714 1720
1715 1721
1716 THREADED_TEST(ToNumber) { 1722 THREADED_TEST(ToNumber) {
1717 LocalContext env; 1723 LocalContext env;
1718 v8::Isolate* isolate = CcTest::isolate(); 1724 v8::Isolate* isolate = CcTest::isolate();
1719 v8::HandleScope scope(isolate); 1725 v8::HandleScope scope(isolate);
1720 Local<String> str = v8_str("3.1415926"); 1726 Local<String> str = v8_str("3.1415926");
1721 CHECK_EQ(3.1415926, str->NumberValue()); 1727 CHECK_EQ(3.1415926, str->NumberValue());
1722 v8::Handle<v8::Boolean> t = v8::True(isolate); 1728 v8::Handle<v8::Boolean> t = v8::True(isolate);
1723 CHECK_EQ(1.0, t->NumberValue()); 1729 CHECK_EQ(1.0, t->NumberValue());
1724 v8::Handle<v8::Boolean> f = v8::False(isolate); 1730 v8::Handle<v8::Boolean> f = v8::False(isolate);
1725 CHECK_EQ(0.0, f->NumberValue()); 1731 CHECK_EQ(0.0, f->NumberValue());
1726 } 1732 }
1727 1733
1728 1734
1729 THREADED_TEST(Date) { 1735 THREADED_TEST(Date) {
1730 LocalContext env; 1736 LocalContext env;
1731 v8::HandleScope scope(env->GetIsolate()); 1737 v8::HandleScope scope(env->GetIsolate());
1732 double PI = 3.1415926; 1738 double PI = 3.1415926;
1733 Local<Value> date = v8::Date::New(env->GetIsolate(), PI); 1739 Local<Value> date = v8::Date::New(env->GetIsolate(), PI);
1734 CHECK_EQ(3.0, date->NumberValue()); 1740 CHECK_EQ(3.0, date->NumberValue());
1735 date.As<v8::Date>()->Set(v8_str("property"), v8::Integer::New(42)); 1741 date.As<v8::Date>()->Set(v8_str("property"),
1742 v8::Integer::New(env->GetIsolate(), 42));
1736 CHECK_EQ(42, date.As<v8::Date>()->Get(v8_str("property"))->Int32Value()); 1743 CHECK_EQ(42, date.As<v8::Date>()->Get(v8_str("property"))->Int32Value());
1737 } 1744 }
1738 1745
1739 1746
1740 THREADED_TEST(Boolean) { 1747 THREADED_TEST(Boolean) {
1741 LocalContext env; 1748 LocalContext env;
1742 v8::HandleScope scope(env->GetIsolate()); 1749 v8::Isolate* isolate = env->GetIsolate();
1743 v8::Handle<v8::Boolean> t = v8::True(CcTest::isolate()); 1750 v8::HandleScope scope(isolate);
1751 v8::Handle<v8::Boolean> t = v8::True(isolate);
1744 CHECK(t->Value()); 1752 CHECK(t->Value());
1745 v8::Handle<v8::Boolean> f = v8::False(CcTest::isolate()); 1753 v8::Handle<v8::Boolean> f = v8::False(isolate);
1746 CHECK(!f->Value()); 1754 CHECK(!f->Value());
1747 v8::Handle<v8::Primitive> u = v8::Undefined(CcTest::isolate()); 1755 v8::Handle<v8::Primitive> u = v8::Undefined(isolate);
1748 CHECK(!u->BooleanValue()); 1756 CHECK(!u->BooleanValue());
1749 v8::Handle<v8::Primitive> n = v8::Null(CcTest::isolate()); 1757 v8::Handle<v8::Primitive> n = v8::Null(isolate);
1750 CHECK(!n->BooleanValue()); 1758 CHECK(!n->BooleanValue());
1751 v8::Handle<String> str1 = v8_str(""); 1759 v8::Handle<String> str1 = v8_str("");
1752 CHECK(!str1->BooleanValue()); 1760 CHECK(!str1->BooleanValue());
1753 v8::Handle<String> str2 = v8_str("x"); 1761 v8::Handle<String> str2 = v8_str("x");
1754 CHECK(str2->BooleanValue()); 1762 CHECK(str2->BooleanValue());
1755 CHECK(!v8::Number::New(0)->BooleanValue()); 1763 CHECK(!v8::Number::New(isolate, 0)->BooleanValue());
1756 CHECK(v8::Number::New(-1)->BooleanValue()); 1764 CHECK(v8::Number::New(isolate, -1)->BooleanValue());
1757 CHECK(v8::Number::New(1)->BooleanValue()); 1765 CHECK(v8::Number::New(isolate, 1)->BooleanValue());
1758 CHECK(v8::Number::New(42)->BooleanValue()); 1766 CHECK(v8::Number::New(isolate, 42)->BooleanValue());
1759 CHECK(!v8_compile("NaN")->Run()->BooleanValue()); 1767 CHECK(!v8_compile("NaN")->Run()->BooleanValue());
1760 } 1768 }
1761 1769
1762 1770
1763 static void DummyCallHandler(const v8::FunctionCallbackInfo<v8::Value>& args) { 1771 static void DummyCallHandler(const v8::FunctionCallbackInfo<v8::Value>& args) {
1764 ApiTestFuzzer::Fuzz(); 1772 ApiTestFuzzer::Fuzz();
1765 args.GetReturnValue().Set(v8_num(13.4)); 1773 args.GetReturnValue().Set(v8_num(13.4));
1766 } 1774 }
1767 1775
1768 1776
(...skipping 19 matching lines...) Expand all
1788 v8::Handle<Value> result(script->Run()); 1796 v8::Handle<Value> result(script->Run());
1789 CHECK_EQ(13.4, result->NumberValue()); 1797 CHECK_EQ(13.4, result->NumberValue());
1790 CHECK_EQ(200, v8_compile("x")->Run()->Int32Value()); 1798 CHECK_EQ(200, v8_compile("x")->Run()->Int32Value());
1791 CHECK_EQ(876, v8_compile("m")->Run()->Int32Value()); 1799 CHECK_EQ(876, v8_compile("m")->Run()->Int32Value());
1792 } 1800 }
1793 1801
1794 1802
1795 THREADED_TEST(ObjectTemplate) { 1803 THREADED_TEST(ObjectTemplate) {
1796 v8::Isolate* isolate = CcTest::isolate(); 1804 v8::Isolate* isolate = CcTest::isolate();
1797 v8::HandleScope scope(isolate); 1805 v8::HandleScope scope(isolate);
1798 Local<ObjectTemplate> templ1 = ObjectTemplate::New(); 1806 Local<ObjectTemplate> templ1 = ObjectTemplate::New(isolate);
1799 templ1->Set(isolate, "x", v8_num(10)); 1807 templ1->Set(isolate, "x", v8_num(10));
1800 templ1->Set(isolate, "y", v8_num(13)); 1808 templ1->Set(isolate, "y", v8_num(13));
1801 LocalContext env; 1809 LocalContext env;
1802 Local<v8::Object> instance1 = templ1->NewInstance(); 1810 Local<v8::Object> instance1 = templ1->NewInstance();
1803 env->Global()->Set(v8_str("p"), instance1); 1811 env->Global()->Set(v8_str("p"), instance1);
1804 CHECK(v8_compile("(p.x == 10)")->Run()->BooleanValue()); 1812 CHECK(v8_compile("(p.x == 10)")->Run()->BooleanValue());
1805 CHECK(v8_compile("(p.y == 13)")->Run()->BooleanValue()); 1813 CHECK(v8_compile("(p.y == 13)")->Run()->BooleanValue());
1806 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(isolate); 1814 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(isolate);
1807 fun->PrototypeTemplate()->Set(isolate, "nirk", v8_num(123)); 1815 fun->PrototypeTemplate()->Set(isolate, "nirk", v8_num(123));
1808 Local<ObjectTemplate> templ2 = fun->InstanceTemplate(); 1816 Local<ObjectTemplate> templ2 = fun->InstanceTemplate();
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
2437 2445
2438 v8::Handle<Script> call_recursively_script; 2446 v8::Handle<Script> call_recursively_script;
2439 static const int kTargetRecursionDepth = 200; // near maximum 2447 static const int kTargetRecursionDepth = 200; // near maximum
2440 2448
2441 2449
2442 static void CallScriptRecursivelyCall( 2450 static void CallScriptRecursivelyCall(
2443 const v8::FunctionCallbackInfo<v8::Value>& args) { 2451 const v8::FunctionCallbackInfo<v8::Value>& args) {
2444 ApiTestFuzzer::Fuzz(); 2452 ApiTestFuzzer::Fuzz();
2445 int depth = args.This()->Get(v8_str("depth"))->Int32Value(); 2453 int depth = args.This()->Get(v8_str("depth"))->Int32Value();
2446 if (depth == kTargetRecursionDepth) return; 2454 if (depth == kTargetRecursionDepth) return;
2447 args.This()->Set(v8_str("depth"), v8::Integer::New(depth + 1)); 2455 args.This()->Set(v8_str("depth"),
2456 v8::Integer::New(args.GetIsolate(), depth + 1));
2448 args.GetReturnValue().Set(call_recursively_script->Run()); 2457 args.GetReturnValue().Set(call_recursively_script->Run());
2449 } 2458 }
2450 2459
2451 2460
2452 static void CallFunctionRecursivelyCall( 2461 static void CallFunctionRecursivelyCall(
2453 const v8::FunctionCallbackInfo<v8::Value>& args) { 2462 const v8::FunctionCallbackInfo<v8::Value>& args) {
2454 ApiTestFuzzer::Fuzz(); 2463 ApiTestFuzzer::Fuzz();
2455 int depth = args.This()->Get(v8_str("depth"))->Int32Value(); 2464 int depth = args.This()->Get(v8_str("depth"))->Int32Value();
2456 if (depth == kTargetRecursionDepth) { 2465 if (depth == kTargetRecursionDepth) {
2457 printf("[depth = %d]\n", depth); 2466 printf("[depth = %d]\n", depth);
2458 return; 2467 return;
2459 } 2468 }
2460 args.This()->Set(v8_str("depth"), v8::Integer::New(depth + 1)); 2469 args.This()->Set(v8_str("depth"),
2470 v8::Integer::New(args.GetIsolate(), depth + 1));
2461 v8::Handle<Value> function = 2471 v8::Handle<Value> function =
2462 args.This()->Get(v8_str("callFunctionRecursively")); 2472 args.This()->Get(v8_str("callFunctionRecursively"));
2463 args.GetReturnValue().Set( 2473 args.GetReturnValue().Set(
2464 function.As<Function>()->Call(args.This(), 0, NULL)); 2474 function.As<Function>()->Call(args.This(), 0, NULL));
2465 } 2475 }
2466 2476
2467 2477
2468 THREADED_TEST(DeepCrossLanguageRecursion) { 2478 THREADED_TEST(DeepCrossLanguageRecursion) {
2469 v8::Isolate* isolate = CcTest::isolate(); 2479 v8::Isolate* isolate = CcTest::isolate();
2470 v8::HandleScope scope(isolate); 2480 v8::HandleScope scope(isolate);
2471 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(); 2481 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(isolate);
2472 global->Set(v8_str("callScriptRecursively"), 2482 global->Set(v8_str("callScriptRecursively"),
2473 v8::FunctionTemplate::New(isolate, CallScriptRecursivelyCall)); 2483 v8::FunctionTemplate::New(isolate, CallScriptRecursivelyCall));
2474 global->Set(v8_str("callFunctionRecursively"), 2484 global->Set(v8_str("callFunctionRecursively"),
2475 v8::FunctionTemplate::New(isolate, CallFunctionRecursivelyCall)); 2485 v8::FunctionTemplate::New(isolate, CallFunctionRecursivelyCall));
2476 LocalContext env(NULL, global); 2486 LocalContext env(NULL, global);
2477 2487
2478 env->Global()->Set(v8_str("depth"), v8::Integer::New(0)); 2488 env->Global()->Set(v8_str("depth"), v8::Integer::New(isolate, 0));
2479 call_recursively_script = v8_compile("callScriptRecursively()"); 2489 call_recursively_script = v8_compile("callScriptRecursively()");
2480 call_recursively_script->Run(); 2490 call_recursively_script->Run();
2481 call_recursively_script = v8::Handle<Script>(); 2491 call_recursively_script = v8::Handle<Script>();
2482 2492
2483 env->Global()->Set(v8_str("depth"), v8::Integer::New(0)); 2493 env->Global()->Set(v8_str("depth"), v8::Integer::New(isolate, 0));
2484 Script::Compile(v8_str("callFunctionRecursively()"))->Run(); 2494 Script::Compile(v8_str("callFunctionRecursively()"))->Run();
2485 } 2495 }
2486 2496
2487 2497
2488 static void ThrowingPropertyHandlerGet( 2498 static void ThrowingPropertyHandlerGet(
2489 Local<String> key, 2499 Local<String> key,
2490 const v8::PropertyCallbackInfo<v8::Value>& info) { 2500 const v8::PropertyCallbackInfo<v8::Value>& info) {
2491 ApiTestFuzzer::Fuzz(); 2501 ApiTestFuzzer::Fuzz();
2492 info.GetReturnValue().Set(info.GetIsolate()->ThrowException(key)); 2502 info.GetReturnValue().Set(info.GetIsolate()->ThrowException(key));
2493 } 2503 }
2494 2504
2495 2505
2496 static void ThrowingPropertyHandlerSet( 2506 static void ThrowingPropertyHandlerSet(
2497 Local<String> key, 2507 Local<String> key,
2498 Local<Value>, 2508 Local<Value>,
2499 const v8::PropertyCallbackInfo<v8::Value>& info) { 2509 const v8::PropertyCallbackInfo<v8::Value>& info) {
2500 info.GetIsolate()->ThrowException(key); 2510 info.GetIsolate()->ThrowException(key);
2501 info.GetReturnValue().SetUndefined(); // not the same as empty handle 2511 info.GetReturnValue().SetUndefined(); // not the same as empty handle
2502 } 2512 }
2503 2513
2504 2514
2505 THREADED_TEST(CallbackExceptionRegression) { 2515 THREADED_TEST(CallbackExceptionRegression) {
2506 v8::HandleScope scope(CcTest::isolate()); 2516 v8::Isolate* isolate = CcTest::isolate();
2507 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 2517 v8::HandleScope scope(isolate);
2518 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate);
2508 obj->SetNamedPropertyHandler(ThrowingPropertyHandlerGet, 2519 obj->SetNamedPropertyHandler(ThrowingPropertyHandlerGet,
2509 ThrowingPropertyHandlerSet); 2520 ThrowingPropertyHandlerSet);
2510 LocalContext env; 2521 LocalContext env;
2511 env->Global()->Set(v8_str("obj"), obj->NewInstance()); 2522 env->Global()->Set(v8_str("obj"), obj->NewInstance());
2512 v8::Handle<Value> otto = Script::Compile(v8_str( 2523 v8::Handle<Value> otto = Script::Compile(v8_str(
2513 "try { with (obj) { otto; } } catch (e) { e; }"))->Run(); 2524 "try { with (obj) { otto; } } catch (e) { e; }"))->Run();
2514 CHECK_EQ(v8_str("otto"), otto); 2525 CHECK_EQ(v8_str("otto"), otto);
2515 v8::Handle<Value> netto = Script::Compile(v8_str( 2526 v8::Handle<Value> netto = Script::Compile(v8_str(
2516 "try { with (obj) { netto = 4; } } catch (e) { e; }"))->Run(); 2527 "try { with (obj) { netto = 4; } } catch (e) { e; }"))->Run();
2517 CHECK_EQ(v8_str("netto"), netto); 2528 CHECK_EQ(v8_str("netto"), netto);
(...skipping 22 matching lines...) Expand all
2540 instance_templ->SetInternalFieldCount(1); 2551 instance_templ->SetInternalFieldCount(1);
2541 Local<v8::Object> obj = templ->GetFunction()->NewInstance(); 2552 Local<v8::Object> obj = templ->GetFunction()->NewInstance();
2542 CHECK_EQ(1, obj->InternalFieldCount()); 2553 CHECK_EQ(1, obj->InternalFieldCount());
2543 CHECK(obj->GetInternalField(0)->IsUndefined()); 2554 CHECK(obj->GetInternalField(0)->IsUndefined());
2544 obj->SetInternalField(0, v8_num(17)); 2555 obj->SetInternalField(0, v8_num(17));
2545 CHECK_EQ(17, obj->GetInternalField(0)->Int32Value()); 2556 CHECK_EQ(17, obj->GetInternalField(0)->Int32Value());
2546 } 2557 }
2547 2558
2548 2559
2549 THREADED_TEST(GlobalObjectInternalFields) { 2560 THREADED_TEST(GlobalObjectInternalFields) {
2550 v8::HandleScope scope(CcTest::isolate()); 2561 v8::Isolate* isolate = CcTest::isolate();
2551 Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 2562 v8::HandleScope scope(isolate);
2563 Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(isolate);
2552 global_template->SetInternalFieldCount(1); 2564 global_template->SetInternalFieldCount(1);
2553 LocalContext env(NULL, global_template); 2565 LocalContext env(NULL, global_template);
2554 v8::Handle<v8::Object> global_proxy = env->Global(); 2566 v8::Handle<v8::Object> global_proxy = env->Global();
2555 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); 2567 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>();
2556 CHECK_EQ(1, global->InternalFieldCount()); 2568 CHECK_EQ(1, global->InternalFieldCount());
2557 CHECK(global->GetInternalField(0)->IsUndefined()); 2569 CHECK(global->GetInternalField(0)->IsUndefined());
2558 global->SetInternalField(0, v8_num(17)); 2570 global->SetInternalField(0, v8_num(17));
2559 CHECK_EQ(17, global->GetInternalField(0)->Int32Value()); 2571 CHECK_EQ(17, global->GetInternalField(0)->Int32Value());
2560 } 2572 }
2561 2573
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
2649 static void CheckEmbedderData(LocalContext* env, 2661 static void CheckEmbedderData(LocalContext* env,
2650 int index, 2662 int index,
2651 v8::Handle<Value> data) { 2663 v8::Handle<Value> data) {
2652 (*env)->SetEmbedderData(index, data); 2664 (*env)->SetEmbedderData(index, data);
2653 CHECK((*env)->GetEmbedderData(index)->StrictEquals(data)); 2665 CHECK((*env)->GetEmbedderData(index)->StrictEquals(data));
2654 } 2666 }
2655 2667
2656 2668
2657 THREADED_TEST(EmbedderData) { 2669 THREADED_TEST(EmbedderData) {
2658 LocalContext env; 2670 LocalContext env;
2659 v8::HandleScope scope(env->GetIsolate()); 2671 v8::Isolate* isolate = env->GetIsolate();
2672 v8::HandleScope scope(isolate);
2660 2673
2661 CheckEmbedderData( 2674 CheckEmbedderData(
2662 &env, 3, 2675 &env, 3,
2663 v8::String::NewFromUtf8(env->GetIsolate(), "The quick brown fox jumps")); 2676 v8::String::NewFromUtf8(isolate, "The quick brown fox jumps"));
2664 CheckEmbedderData(&env, 2, v8::String::NewFromUtf8(env->GetIsolate(), 2677 CheckEmbedderData(&env, 2, v8::String::NewFromUtf8(isolate,
2665 "over the lazy dog.")); 2678 "over the lazy dog."));
2666 CheckEmbedderData(&env, 1, v8::Number::New(1.2345)); 2679 CheckEmbedderData(&env, 1, v8::Number::New(isolate, 1.2345));
2667 CheckEmbedderData(&env, 0, v8::Boolean::New(env->GetIsolate(), true)); 2680 CheckEmbedderData(&env, 0, v8::Boolean::New(isolate, true));
2668 } 2681 }
2669 2682
2670 2683
2671 THREADED_TEST(IdentityHash) { 2684 THREADED_TEST(IdentityHash) {
2672 LocalContext env; 2685 LocalContext env;
2673 v8::HandleScope scope(env->GetIsolate()); 2686 v8::Isolate* isolate = env->GetIsolate();
2687 v8::HandleScope scope(isolate);
2674 2688
2675 // Ensure that the test starts with an fresh heap to test whether the hash 2689 // Ensure that the test starts with an fresh heap to test whether the hash
2676 // code is based on the address. 2690 // code is based on the address.
2677 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 2691 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
2678 Local<v8::Object> obj = v8::Object::New(); 2692 Local<v8::Object> obj = v8::Object::New(isolate);
2679 int hash = obj->GetIdentityHash(); 2693 int hash = obj->GetIdentityHash();
2680 int hash1 = obj->GetIdentityHash(); 2694 int hash1 = obj->GetIdentityHash();
2681 CHECK_EQ(hash, hash1); 2695 CHECK_EQ(hash, hash1);
2682 int hash2 = v8::Object::New()->GetIdentityHash(); 2696 int hash2 = v8::Object::New(isolate)->GetIdentityHash();
2683 // Since the identity hash is essentially a random number two consecutive 2697 // Since the identity hash is essentially a random number two consecutive
2684 // objects should not be assigned the same hash code. If the test below fails 2698 // objects should not be assigned the same hash code. If the test below fails
2685 // the random number generator should be evaluated. 2699 // the random number generator should be evaluated.
2686 CHECK_NE(hash, hash2); 2700 CHECK_NE(hash, hash2);
2687 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 2701 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
2688 int hash3 = v8::Object::New()->GetIdentityHash(); 2702 int hash3 = v8::Object::New(isolate)->GetIdentityHash();
2689 // Make sure that the identity hash is not based on the initial address of 2703 // Make sure that the identity hash is not based on the initial address of
2690 // the object alone. If the test below fails the random number generator 2704 // the object alone. If the test below fails the random number generator
2691 // should be evaluated. 2705 // should be evaluated.
2692 CHECK_NE(hash, hash3); 2706 CHECK_NE(hash, hash3);
2693 int hash4 = obj->GetIdentityHash(); 2707 int hash4 = obj->GetIdentityHash();
2694 CHECK_EQ(hash, hash4); 2708 CHECK_EQ(hash, hash4);
2695 2709
2696 // Check identity hashes behaviour in the presence of JS accessors. 2710 // Check identity hashes behaviour in the presence of JS accessors.
2697 // Put a getter for 'v8::IdentityHash' on the Object's prototype: 2711 // Put a getter for 'v8::IdentityHash' on the Object's prototype:
2698 { 2712 {
2699 CompileRun("Object.prototype['v8::IdentityHash'] = 42;\n"); 2713 CompileRun("Object.prototype['v8::IdentityHash'] = 42;\n");
2700 Local<v8::Object> o1 = v8::Object::New(); 2714 Local<v8::Object> o1 = v8::Object::New(isolate);
2701 Local<v8::Object> o2 = v8::Object::New(); 2715 Local<v8::Object> o2 = v8::Object::New(isolate);
2702 CHECK_NE(o1->GetIdentityHash(), o2->GetIdentityHash()); 2716 CHECK_NE(o1->GetIdentityHash(), o2->GetIdentityHash());
2703 } 2717 }
2704 { 2718 {
2705 CompileRun( 2719 CompileRun(
2706 "function cnst() { return 42; };\n" 2720 "function cnst() { return 42; };\n"
2707 "Object.prototype.__defineGetter__('v8::IdentityHash', cnst);\n"); 2721 "Object.prototype.__defineGetter__('v8::IdentityHash', cnst);\n");
2708 Local<v8::Object> o1 = v8::Object::New(); 2722 Local<v8::Object> o1 = v8::Object::New(isolate);
2709 Local<v8::Object> o2 = v8::Object::New(); 2723 Local<v8::Object> o2 = v8::Object::New(isolate);
2710 CHECK_NE(o1->GetIdentityHash(), o2->GetIdentityHash()); 2724 CHECK_NE(o1->GetIdentityHash(), o2->GetIdentityHash());
2711 } 2725 }
2712 } 2726 }
2713 2727
2714 2728
2715 THREADED_TEST(SymbolProperties) { 2729 THREADED_TEST(SymbolProperties) {
2716 i::FLAG_harmony_symbols = true; 2730 i::FLAG_harmony_symbols = true;
2717 2731
2718 LocalContext env; 2732 LocalContext env;
2719 v8::Isolate* isolate = env->GetIsolate(); 2733 v8::Isolate* isolate = env->GetIsolate();
2720 v8::HandleScope scope(isolate); 2734 v8::HandleScope scope(isolate);
2721 2735
2722 v8::Local<v8::Object> obj = v8::Object::New(); 2736 v8::Local<v8::Object> obj = v8::Object::New(isolate);
2723 v8::Local<v8::Symbol> sym1 = v8::Symbol::New(isolate); 2737 v8::Local<v8::Symbol> sym1 = v8::Symbol::New(isolate);
2724 v8::Local<v8::Symbol> sym2 = v8::Symbol::New(isolate, "my-symbol"); 2738 v8::Local<v8::Symbol> sym2 = v8::Symbol::New(isolate, "my-symbol");
2725 2739
2726 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 2740 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
2727 2741
2728 // Check basic symbol functionality. 2742 // Check basic symbol functionality.
2729 CHECK(sym1->IsSymbol()); 2743 CHECK(sym1->IsSymbol());
2730 CHECK(sym2->IsSymbol()); 2744 CHECK(sym2->IsSymbol());
2731 CHECK(!obj->IsSymbol()); 2745 CHECK(!obj->IsSymbol());
2732 2746
(...skipping 20 matching lines...) Expand all
2753 CHECK(!obj->IsSymbolObject()); 2767 CHECK(!obj->IsSymbolObject());
2754 CHECK(sym_obj->Equals(sym2)); 2768 CHECK(sym_obj->Equals(sym2));
2755 CHECK(!sym_obj->StrictEquals(sym2)); 2769 CHECK(!sym_obj->StrictEquals(sym2));
2756 CHECK(v8::SymbolObject::Cast(*sym_obj)->Equals(sym_obj)); 2770 CHECK(v8::SymbolObject::Cast(*sym_obj)->Equals(sym_obj));
2757 CHECK(v8::SymbolObject::Cast(*sym_obj)->ValueOf()->Equals(sym2)); 2771 CHECK(v8::SymbolObject::Cast(*sym_obj)->ValueOf()->Equals(sym2));
2758 2772
2759 // Make sure delete of a non-existent symbol property works. 2773 // Make sure delete of a non-existent symbol property works.
2760 CHECK(obj->Delete(sym1)); 2774 CHECK(obj->Delete(sym1));
2761 CHECK(!obj->Has(sym1)); 2775 CHECK(!obj->Has(sym1));
2762 2776
2763 CHECK(obj->Set(sym1, v8::Integer::New(1503))); 2777 CHECK(obj->Set(sym1, v8::Integer::New(isolate, 1503)));
2764 CHECK(obj->Has(sym1)); 2778 CHECK(obj->Has(sym1));
2765 CHECK_EQ(1503, obj->Get(sym1)->Int32Value()); 2779 CHECK_EQ(1503, obj->Get(sym1)->Int32Value());
2766 CHECK(obj->Set(sym1, v8::Integer::New(2002))); 2780 CHECK(obj->Set(sym1, v8::Integer::New(isolate, 2002)));
2767 CHECK(obj->Has(sym1)); 2781 CHECK(obj->Has(sym1));
2768 CHECK_EQ(2002, obj->Get(sym1)->Int32Value()); 2782 CHECK_EQ(2002, obj->Get(sym1)->Int32Value());
2769 CHECK_EQ(v8::None, obj->GetPropertyAttributes(sym1)); 2783 CHECK_EQ(v8::None, obj->GetPropertyAttributes(sym1));
2770 2784
2771 CHECK_EQ(0, obj->GetOwnPropertyNames()->Length()); 2785 CHECK_EQ(0, obj->GetOwnPropertyNames()->Length());
2772 int num_props = obj->GetPropertyNames()->Length(); 2786 int num_props = obj->GetPropertyNames()->Length();
2773 CHECK( 2787 CHECK(obj->Set(v8::String::NewFromUtf8(isolate, "bla"),
2774 obj->Set(v8::String::NewFromUtf8(isolate, "bla"), v8::Integer::New(20))); 2788 v8::Integer::New(isolate, 20)));
2775 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length()); 2789 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length());
2776 CHECK_EQ(num_props + 1, obj->GetPropertyNames()->Length()); 2790 CHECK_EQ(num_props + 1, obj->GetPropertyNames()->Length());
2777 2791
2778 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 2792 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
2779 2793
2780 // Add another property and delete it afterwards to force the object in 2794 // Add another property and delete it afterwards to force the object in
2781 // slow case. 2795 // slow case.
2782 CHECK(obj->Set(sym2, v8::Integer::New(2008))); 2796 CHECK(obj->Set(sym2, v8::Integer::New(isolate, 2008)));
2783 CHECK_EQ(2002, obj->Get(sym1)->Int32Value()); 2797 CHECK_EQ(2002, obj->Get(sym1)->Int32Value());
2784 CHECK_EQ(2008, obj->Get(sym2)->Int32Value()); 2798 CHECK_EQ(2008, obj->Get(sym2)->Int32Value());
2785 CHECK_EQ(2002, obj->Get(sym1)->Int32Value()); 2799 CHECK_EQ(2002, obj->Get(sym1)->Int32Value());
2786 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length()); 2800 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length());
2787 2801
2788 CHECK(obj->Has(sym1)); 2802 CHECK(obj->Has(sym1));
2789 CHECK(obj->Has(sym2)); 2803 CHECK(obj->Has(sym2));
2790 CHECK(obj->Delete(sym2)); 2804 CHECK(obj->Delete(sym2));
2791 CHECK(obj->Has(sym1)); 2805 CHECK(obj->Has(sym1));
2792 CHECK(!obj->Has(sym2)); 2806 CHECK(!obj->Has(sym2));
2793 CHECK_EQ(2002, obj->Get(sym1)->Int32Value()); 2807 CHECK_EQ(2002, obj->Get(sym1)->Int32Value());
2794 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length()); 2808 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length());
2795 2809
2796 // Symbol properties are inherited. 2810 // Symbol properties are inherited.
2797 v8::Local<v8::Object> child = v8::Object::New(); 2811 v8::Local<v8::Object> child = v8::Object::New(isolate);
2798 child->SetPrototype(obj); 2812 child->SetPrototype(obj);
2799 CHECK(child->Has(sym1)); 2813 CHECK(child->Has(sym1));
2800 CHECK_EQ(2002, child->Get(sym1)->Int32Value()); 2814 CHECK_EQ(2002, child->Get(sym1)->Int32Value());
2801 CHECK_EQ(0, child->GetOwnPropertyNames()->Length()); 2815 CHECK_EQ(0, child->GetOwnPropertyNames()->Length());
2802 } 2816 }
2803 2817
2804 2818
2805 THREADED_TEST(PrivateProperties) { 2819 THREADED_TEST(PrivateProperties) {
2806 LocalContext env; 2820 LocalContext env;
2807 v8::Isolate* isolate = env->GetIsolate(); 2821 v8::Isolate* isolate = env->GetIsolate();
2808 v8::HandleScope scope(isolate); 2822 v8::HandleScope scope(isolate);
2809 2823
2810 v8::Local<v8::Object> obj = v8::Object::New(); 2824 v8::Local<v8::Object> obj = v8::Object::New(isolate);
2811 v8::Local<v8::Private> priv1 = v8::Private::New(isolate); 2825 v8::Local<v8::Private> priv1 = v8::Private::New(isolate);
2812 v8::Local<v8::Private> priv2 = v8::Private::New(isolate, "my-private"); 2826 v8::Local<v8::Private> priv2 = v8::Private::New(isolate, "my-private");
2813 2827
2814 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 2828 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
2815 2829
2816 CHECK(priv2->Name()->Equals(v8::String::NewFromUtf8(isolate, "my-private"))); 2830 CHECK(priv2->Name()->Equals(v8::String::NewFromUtf8(isolate, "my-private")));
2817 2831
2818 // Make sure delete of a non-existent private symbol property works. 2832 // Make sure delete of a non-existent private symbol property works.
2819 CHECK(obj->DeletePrivate(priv1)); 2833 CHECK(obj->DeletePrivate(priv1));
2820 CHECK(!obj->HasPrivate(priv1)); 2834 CHECK(!obj->HasPrivate(priv1));
2821 2835
2822 CHECK(obj->SetPrivate(priv1, v8::Integer::New(1503))); 2836 CHECK(obj->SetPrivate(priv1, v8::Integer::New(isolate, 1503)));
2823 CHECK(obj->HasPrivate(priv1)); 2837 CHECK(obj->HasPrivate(priv1));
2824 CHECK_EQ(1503, obj->GetPrivate(priv1)->Int32Value()); 2838 CHECK_EQ(1503, obj->GetPrivate(priv1)->Int32Value());
2825 CHECK(obj->SetPrivate(priv1, v8::Integer::New(2002))); 2839 CHECK(obj->SetPrivate(priv1, v8::Integer::New(isolate, 2002)));
2826 CHECK(obj->HasPrivate(priv1)); 2840 CHECK(obj->HasPrivate(priv1));
2827 CHECK_EQ(2002, obj->GetPrivate(priv1)->Int32Value()); 2841 CHECK_EQ(2002, obj->GetPrivate(priv1)->Int32Value());
2828 2842
2829 CHECK_EQ(0, obj->GetOwnPropertyNames()->Length()); 2843 CHECK_EQ(0, obj->GetOwnPropertyNames()->Length());
2830 int num_props = obj->GetPropertyNames()->Length(); 2844 int num_props = obj->GetPropertyNames()->Length();
2831 CHECK( 2845 CHECK(obj->Set(v8::String::NewFromUtf8(isolate, "bla"),
2832 obj->Set(v8::String::NewFromUtf8(isolate, "bla"), v8::Integer::New(20))); 2846 v8::Integer::New(isolate, 20)));
2833 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length()); 2847 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length());
2834 CHECK_EQ(num_props + 1, obj->GetPropertyNames()->Length()); 2848 CHECK_EQ(num_props + 1, obj->GetPropertyNames()->Length());
2835 2849
2836 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 2850 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
2837 2851
2838 // Add another property and delete it afterwards to force the object in 2852 // Add another property and delete it afterwards to force the object in
2839 // slow case. 2853 // slow case.
2840 CHECK(obj->SetPrivate(priv2, v8::Integer::New(2008))); 2854 CHECK(obj->SetPrivate(priv2, v8::Integer::New(isolate, 2008)));
2841 CHECK_EQ(2002, obj->GetPrivate(priv1)->Int32Value()); 2855 CHECK_EQ(2002, obj->GetPrivate(priv1)->Int32Value());
2842 CHECK_EQ(2008, obj->GetPrivate(priv2)->Int32Value()); 2856 CHECK_EQ(2008, obj->GetPrivate(priv2)->Int32Value());
2843 CHECK_EQ(2002, obj->GetPrivate(priv1)->Int32Value()); 2857 CHECK_EQ(2002, obj->GetPrivate(priv1)->Int32Value());
2844 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length()); 2858 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length());
2845 2859
2846 CHECK(obj->HasPrivate(priv1)); 2860 CHECK(obj->HasPrivate(priv1));
2847 CHECK(obj->HasPrivate(priv2)); 2861 CHECK(obj->HasPrivate(priv2));
2848 CHECK(obj->DeletePrivate(priv2)); 2862 CHECK(obj->DeletePrivate(priv2));
2849 CHECK(obj->HasPrivate(priv1)); 2863 CHECK(obj->HasPrivate(priv1));
2850 CHECK(!obj->HasPrivate(priv2)); 2864 CHECK(!obj->HasPrivate(priv2));
2851 CHECK_EQ(2002, obj->GetPrivate(priv1)->Int32Value()); 2865 CHECK_EQ(2002, obj->GetPrivate(priv1)->Int32Value());
2852 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length()); 2866 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length());
2853 2867
2854 // Private properties are inherited (for the time being). 2868 // Private properties are inherited (for the time being).
2855 v8::Local<v8::Object> child = v8::Object::New(); 2869 v8::Local<v8::Object> child = v8::Object::New(isolate);
2856 child->SetPrototype(obj); 2870 child->SetPrototype(obj);
2857 CHECK(child->HasPrivate(priv1)); 2871 CHECK(child->HasPrivate(priv1));
2858 CHECK_EQ(2002, child->GetPrivate(priv1)->Int32Value()); 2872 CHECK_EQ(2002, child->GetPrivate(priv1)->Int32Value());
2859 CHECK_EQ(0, child->GetOwnPropertyNames()->Length()); 2873 CHECK_EQ(0, child->GetOwnPropertyNames()->Length());
2860 } 2874 }
2861 2875
2862 2876
2863 class ScopedArrayBufferContents { 2877 class ScopedArrayBufferContents {
2864 public: 2878 public:
2865 explicit ScopedArrayBufferContents( 2879 explicit ScopedArrayBufferContents(
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
3119 CheckIsTypedArrayVarNeutered("f64a"); 3133 CheckIsTypedArrayVarNeutered("f64a");
3120 3134
3121 CHECK(CompileRun("dv.byteLength == 0 && dv.byteOffset == 0")->IsTrue()); 3135 CHECK(CompileRun("dv.byteLength == 0 && dv.byteOffset == 0")->IsTrue());
3122 CheckDataViewIsNeutered(dv); 3136 CheckDataViewIsNeutered(dv);
3123 } 3137 }
3124 3138
3125 3139
3126 3140
3127 THREADED_TEST(HiddenProperties) { 3141 THREADED_TEST(HiddenProperties) {
3128 LocalContext env; 3142 LocalContext env;
3129 v8::HandleScope scope(env->GetIsolate()); 3143 v8::Isolate* isolate = env->GetIsolate();
3144 v8::HandleScope scope(isolate);
3130 3145
3131 v8::Local<v8::Object> obj = v8::Object::New(); 3146 v8::Local<v8::Object> obj = v8::Object::New(env->GetIsolate());
3132 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); 3147 v8::Local<v8::String> key = v8_str("api-test::hidden-key");
3133 v8::Local<v8::String> empty = v8_str(""); 3148 v8::Local<v8::String> empty = v8_str("");
3134 v8::Local<v8::String> prop_name = v8_str("prop_name"); 3149 v8::Local<v8::String> prop_name = v8_str("prop_name");
3135 3150
3136 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 3151 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
3137 3152
3138 // Make sure delete of a non-existent hidden value works 3153 // Make sure delete of a non-existent hidden value works
3139 CHECK(obj->DeleteHiddenValue(key)); 3154 CHECK(obj->DeleteHiddenValue(key));
3140 3155
3141 CHECK(obj->SetHiddenValue(key, v8::Integer::New(1503))); 3156 CHECK(obj->SetHiddenValue(key, v8::Integer::New(isolate, 1503)));
3142 CHECK_EQ(1503, obj->GetHiddenValue(key)->Int32Value()); 3157 CHECK_EQ(1503, obj->GetHiddenValue(key)->Int32Value());
3143 CHECK(obj->SetHiddenValue(key, v8::Integer::New(2002))); 3158 CHECK(obj->SetHiddenValue(key, v8::Integer::New(isolate, 2002)));
3144 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); 3159 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value());
3145 3160
3146 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 3161 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
3147 3162
3148 // Make sure we do not find the hidden property. 3163 // Make sure we do not find the hidden property.
3149 CHECK(!obj->Has(empty)); 3164 CHECK(!obj->Has(empty));
3150 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); 3165 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value());
3151 CHECK(obj->Get(empty)->IsUndefined()); 3166 CHECK(obj->Get(empty)->IsUndefined());
3152 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); 3167 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value());
3153 CHECK(obj->Set(empty, v8::Integer::New(2003))); 3168 CHECK(obj->Set(empty, v8::Integer::New(isolate, 2003)));
3154 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); 3169 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value());
3155 CHECK_EQ(2003, obj->Get(empty)->Int32Value()); 3170 CHECK_EQ(2003, obj->Get(empty)->Int32Value());
3156 3171
3157 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 3172 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
3158 3173
3159 // Add another property and delete it afterwards to force the object in 3174 // Add another property and delete it afterwards to force the object in
3160 // slow case. 3175 // slow case.
3161 CHECK(obj->Set(prop_name, v8::Integer::New(2008))); 3176 CHECK(obj->Set(prop_name, v8::Integer::New(isolate, 2008)));
3162 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); 3177 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value());
3163 CHECK_EQ(2008, obj->Get(prop_name)->Int32Value()); 3178 CHECK_EQ(2008, obj->Get(prop_name)->Int32Value());
3164 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); 3179 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value());
3165 CHECK(obj->Delete(prop_name)); 3180 CHECK(obj->Delete(prop_name));
3166 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); 3181 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value());
3167 3182
3168 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 3183 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
3169 3184
3170 CHECK(obj->SetHiddenValue(key, Handle<Value>())); 3185 CHECK(obj->SetHiddenValue(key, Handle<Value>()));
3171 CHECK(obj->GetHiddenValue(key).IsEmpty()); 3186 CHECK(obj->GetHiddenValue(key).IsEmpty());
3172 3187
3173 CHECK(obj->SetHiddenValue(key, v8::Integer::New(2002))); 3188 CHECK(obj->SetHiddenValue(key, v8::Integer::New(isolate, 2002)));
3174 CHECK(obj->DeleteHiddenValue(key)); 3189 CHECK(obj->DeleteHiddenValue(key));
3175 CHECK(obj->GetHiddenValue(key).IsEmpty()); 3190 CHECK(obj->GetHiddenValue(key).IsEmpty());
3176 } 3191 }
3177 3192
3178 3193
3179 THREADED_TEST(Regress97784) { 3194 THREADED_TEST(Regress97784) {
3180 // Regression test for crbug.com/97784 3195 // Regression test for crbug.com/97784
3181 // Messing with the Object.prototype should not have effect on 3196 // Messing with the Object.prototype should not have effect on
3182 // hidden properties. 3197 // hidden properties.
3183 LocalContext env; 3198 LocalContext env;
3184 v8::HandleScope scope(env->GetIsolate()); 3199 v8::HandleScope scope(env->GetIsolate());
3185 3200
3186 v8::Local<v8::Object> obj = v8::Object::New(); 3201 v8::Local<v8::Object> obj = v8::Object::New(env->GetIsolate());
3187 v8::Local<v8::String> key = v8_str("hidden"); 3202 v8::Local<v8::String> key = v8_str("hidden");
3188 3203
3189 CompileRun( 3204 CompileRun(
3190 "set_called = false;" 3205 "set_called = false;"
3191 "Object.defineProperty(" 3206 "Object.defineProperty("
3192 " Object.prototype," 3207 " Object.prototype,"
3193 " 'hidden'," 3208 " 'hidden',"
3194 " {get: function() { return 45; }," 3209 " {get: function() { return 45; },"
3195 " set: function() { set_called = true; }})"); 3210 " set: function() { set_called = true; }})");
3196 3211
3197 CHECK(obj->GetHiddenValue(key).IsEmpty()); 3212 CHECK(obj->GetHiddenValue(key).IsEmpty());
3198 // Make sure that the getter and setter from Object.prototype is not invoked. 3213 // Make sure that the getter and setter from Object.prototype is not invoked.
3199 // If it did we would have full access to the hidden properties in 3214 // If it did we would have full access to the hidden properties in
3200 // the accessor. 3215 // the accessor.
3201 CHECK(obj->SetHiddenValue(key, v8::Integer::New(42))); 3216 CHECK(obj->SetHiddenValue(key, v8::Integer::New(env->GetIsolate(), 42)));
3202 ExpectFalse("set_called"); 3217 ExpectFalse("set_called");
3203 CHECK_EQ(42, obj->GetHiddenValue(key)->Int32Value()); 3218 CHECK_EQ(42, obj->GetHiddenValue(key)->Int32Value());
3204 } 3219 }
3205 3220
3206 3221
3207 static bool interceptor_for_hidden_properties_called; 3222 static bool interceptor_for_hidden_properties_called;
3208 static void InterceptorForHiddenProperties( 3223 static void InterceptorForHiddenProperties(
3209 Local<String> name, const v8::PropertyCallbackInfo<v8::Value>& info) { 3224 Local<String> name, const v8::PropertyCallbackInfo<v8::Value>& info) {
3210 interceptor_for_hidden_properties_called = true; 3225 interceptor_for_hidden_properties_called = true;
3211 } 3226 }
3212 3227
3213 3228
3214 THREADED_TEST(HiddenPropertiesWithInterceptors) { 3229 THREADED_TEST(HiddenPropertiesWithInterceptors) {
3215 LocalContext context; 3230 LocalContext context;
3216 v8::Isolate* isolate = context->GetIsolate(); 3231 v8::Isolate* isolate = context->GetIsolate();
3217 v8::HandleScope scope(isolate); 3232 v8::HandleScope scope(isolate);
3218 3233
3219 interceptor_for_hidden_properties_called = false; 3234 interceptor_for_hidden_properties_called = false;
3220 3235
3221 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); 3236 v8::Local<v8::String> key = v8_str("api-test::hidden-key");
3222 3237
3223 // Associate an interceptor with an object and start setting hidden values. 3238 // Associate an interceptor with an object and start setting hidden values.
3224 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate); 3239 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate);
3225 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); 3240 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate();
3226 instance_templ->SetNamedPropertyHandler(InterceptorForHiddenProperties); 3241 instance_templ->SetNamedPropertyHandler(InterceptorForHiddenProperties);
3227 Local<v8::Function> function = fun_templ->GetFunction(); 3242 Local<v8::Function> function = fun_templ->GetFunction();
3228 Local<v8::Object> obj = function->NewInstance(); 3243 Local<v8::Object> obj = function->NewInstance();
3229 CHECK(obj->SetHiddenValue(key, v8::Integer::New(2302))); 3244 CHECK(obj->SetHiddenValue(key, v8::Integer::New(isolate, 2302)));
3230 CHECK_EQ(2302, obj->GetHiddenValue(key)->Int32Value()); 3245 CHECK_EQ(2302, obj->GetHiddenValue(key)->Int32Value());
3231 CHECK(!interceptor_for_hidden_properties_called); 3246 CHECK(!interceptor_for_hidden_properties_called);
3232 } 3247 }
3233 3248
3234 3249
3235 THREADED_TEST(External) { 3250 THREADED_TEST(External) {
3236 v8::HandleScope scope(CcTest::isolate()); 3251 v8::HandleScope scope(CcTest::isolate());
3237 int x = 3; 3252 int x = 3;
3238 Local<v8::External> ext = v8::External::New(CcTest::isolate(), &x); 3253 Local<v8::External> ext = v8::External::New(CcTest::isolate(), &x);
3239 LocalContext env; 3254 LocalContext env;
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
3511 3526
3512 WeakCallCounterAndPersistent<Value> g1s1(&counter); 3527 WeakCallCounterAndPersistent<Value> g1s1(&counter);
3513 WeakCallCounterAndPersistent<Value> g1s2(&counter); 3528 WeakCallCounterAndPersistent<Value> g1s2(&counter);
3514 WeakCallCounterAndPersistent<Value> g1c1(&counter); 3529 WeakCallCounterAndPersistent<Value> g1c1(&counter);
3515 WeakCallCounterAndPersistent<Value> g2s1(&counter); 3530 WeakCallCounterAndPersistent<Value> g2s1(&counter);
3516 WeakCallCounterAndPersistent<Value> g2s2(&counter); 3531 WeakCallCounterAndPersistent<Value> g2s2(&counter);
3517 WeakCallCounterAndPersistent<Value> g2c1(&counter); 3532 WeakCallCounterAndPersistent<Value> g2c1(&counter);
3518 3533
3519 { 3534 {
3520 HandleScope scope(iso); 3535 HandleScope scope(iso);
3521 g1s1.handle.Reset(iso, Object::New()); 3536 g1s1.handle.Reset(iso, Object::New(iso));
3522 g1s2.handle.Reset(iso, Object::New()); 3537 g1s2.handle.Reset(iso, Object::New(iso));
3523 g1c1.handle.Reset(iso, Object::New()); 3538 g1c1.handle.Reset(iso, Object::New(iso));
3524 g1s1.handle.SetWeak(&g1s1, &WeakPointerCallback); 3539 g1s1.handle.SetWeak(&g1s1, &WeakPointerCallback);
3525 g1s2.handle.SetWeak(&g1s2, &WeakPointerCallback); 3540 g1s2.handle.SetWeak(&g1s2, &WeakPointerCallback);
3526 g1c1.handle.SetWeak(&g1c1, &WeakPointerCallback); 3541 g1c1.handle.SetWeak(&g1c1, &WeakPointerCallback);
3527 3542
3528 g2s1.handle.Reset(iso, Object::New()); 3543 g2s1.handle.Reset(iso, Object::New(iso));
3529 g2s2.handle.Reset(iso, Object::New()); 3544 g2s2.handle.Reset(iso, Object::New(iso));
3530 g2c1.handle.Reset(iso, Object::New()); 3545 g2c1.handle.Reset(iso, Object::New(iso));
3531 g2s1.handle.SetWeak(&g2s1, &WeakPointerCallback); 3546 g2s1.handle.SetWeak(&g2s1, &WeakPointerCallback);
3532 g2s2.handle.SetWeak(&g2s2, &WeakPointerCallback); 3547 g2s2.handle.SetWeak(&g2s2, &WeakPointerCallback);
3533 g2c1.handle.SetWeak(&g2c1, &WeakPointerCallback); 3548 g2c1.handle.SetWeak(&g2c1, &WeakPointerCallback);
3534 } 3549 }
3535 3550
3536 WeakCallCounterAndPersistent<Value> root(&counter); 3551 WeakCallCounterAndPersistent<Value> root(&counter);
3537 root.handle.Reset(iso, g1s1.handle); // make a root. 3552 root.handle.Reset(iso, g1s1.handle); // make a root.
3538 3553
3539 // Connect group 1 and 2, make a cycle. 3554 // Connect group 1 and 2, make a cycle.
3540 { 3555 {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
3605 3620
3606 WeakCallCounterAndPersistent<Object> g1s1(&counter); 3621 WeakCallCounterAndPersistent<Object> g1s1(&counter);
3607 WeakCallCounterAndPersistent<String> g1s2(&counter); 3622 WeakCallCounterAndPersistent<String> g1s2(&counter);
3608 WeakCallCounterAndPersistent<String> g1c1(&counter); 3623 WeakCallCounterAndPersistent<String> g1c1(&counter);
3609 WeakCallCounterAndPersistent<Object> g2s1(&counter); 3624 WeakCallCounterAndPersistent<Object> g2s1(&counter);
3610 WeakCallCounterAndPersistent<String> g2s2(&counter); 3625 WeakCallCounterAndPersistent<String> g2s2(&counter);
3611 WeakCallCounterAndPersistent<String> g2c1(&counter); 3626 WeakCallCounterAndPersistent<String> g2c1(&counter);
3612 3627
3613 { 3628 {
3614 HandleScope scope(iso); 3629 HandleScope scope(iso);
3615 g1s1.handle.Reset(iso, Object::New()); 3630 g1s1.handle.Reset(iso, Object::New(iso));
3616 g1s2.handle.Reset(iso, String::NewFromUtf8(iso, "foo1")); 3631 g1s2.handle.Reset(iso, String::NewFromUtf8(iso, "foo1"));
3617 g1c1.handle.Reset(iso, String::NewFromUtf8(iso, "foo2")); 3632 g1c1.handle.Reset(iso, String::NewFromUtf8(iso, "foo2"));
3618 g1s1.handle.SetWeak(&g1s1, &WeakPointerCallback); 3633 g1s1.handle.SetWeak(&g1s1, &WeakPointerCallback);
3619 g1s2.handle.SetWeak(&g1s2, &WeakPointerCallback); 3634 g1s2.handle.SetWeak(&g1s2, &WeakPointerCallback);
3620 g1c1.handle.SetWeak(&g1c1, &WeakPointerCallback); 3635 g1c1.handle.SetWeak(&g1c1, &WeakPointerCallback);
3621 3636
3622 g2s1.handle.Reset(iso, Object::New()); 3637 g2s1.handle.Reset(iso, Object::New(iso));
3623 g2s2.handle.Reset(iso, String::NewFromUtf8(iso, "foo3")); 3638 g2s2.handle.Reset(iso, String::NewFromUtf8(iso, "foo3"));
3624 g2c1.handle.Reset(iso, String::NewFromUtf8(iso, "foo4")); 3639 g2c1.handle.Reset(iso, String::NewFromUtf8(iso, "foo4"));
3625 g2s1.handle.SetWeak(&g2s1, &WeakPointerCallback); 3640 g2s1.handle.SetWeak(&g2s1, &WeakPointerCallback);
3626 g2s2.handle.SetWeak(&g2s2, &WeakPointerCallback); 3641 g2s2.handle.SetWeak(&g2s2, &WeakPointerCallback);
3627 g2c1.handle.SetWeak(&g2c1, &WeakPointerCallback); 3642 g2c1.handle.SetWeak(&g2c1, &WeakPointerCallback);
3628 } 3643 }
3629 3644
3630 WeakCallCounterAndPersistent<Value> root(&counter); 3645 WeakCallCounterAndPersistent<Value> root(&counter);
3631 root.handle.Reset(iso, g1s1.handle); // make a root. 3646 root.handle.Reset(iso, g1s1.handle); // make a root.
3632 3647
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
3701 WeakCallCounterAndPersistent<Value> g1s2(&counter); 3716 WeakCallCounterAndPersistent<Value> g1s2(&counter);
3702 WeakCallCounterAndPersistent<Value> g2s1(&counter); 3717 WeakCallCounterAndPersistent<Value> g2s1(&counter);
3703 WeakCallCounterAndPersistent<Value> g2s2(&counter); 3718 WeakCallCounterAndPersistent<Value> g2s2(&counter);
3704 WeakCallCounterAndPersistent<Value> g3s1(&counter); 3719 WeakCallCounterAndPersistent<Value> g3s1(&counter);
3705 WeakCallCounterAndPersistent<Value> g3s2(&counter); 3720 WeakCallCounterAndPersistent<Value> g3s2(&counter);
3706 WeakCallCounterAndPersistent<Value> g4s1(&counter); 3721 WeakCallCounterAndPersistent<Value> g4s1(&counter);
3707 WeakCallCounterAndPersistent<Value> g4s2(&counter); 3722 WeakCallCounterAndPersistent<Value> g4s2(&counter);
3708 3723
3709 { 3724 {
3710 HandleScope scope(iso); 3725 HandleScope scope(iso);
3711 g1s1.handle.Reset(iso, Object::New()); 3726 g1s1.handle.Reset(iso, Object::New(iso));
3712 g1s2.handle.Reset(iso, Object::New()); 3727 g1s2.handle.Reset(iso, Object::New(iso));
3713 g1s1.handle.SetWeak(&g1s1, &WeakPointerCallback); 3728 g1s1.handle.SetWeak(&g1s1, &WeakPointerCallback);
3714 g1s2.handle.SetWeak(&g1s2, &WeakPointerCallback); 3729 g1s2.handle.SetWeak(&g1s2, &WeakPointerCallback);
3715 CHECK(g1s1.handle.IsWeak()); 3730 CHECK(g1s1.handle.IsWeak());
3716 CHECK(g1s2.handle.IsWeak()); 3731 CHECK(g1s2.handle.IsWeak());
3717 3732
3718 g2s1.handle.Reset(iso, Object::New()); 3733 g2s1.handle.Reset(iso, Object::New(iso));
3719 g2s2.handle.Reset(iso, Object::New()); 3734 g2s2.handle.Reset(iso, Object::New(iso));
3720 g2s1.handle.SetWeak(&g2s1, &WeakPointerCallback); 3735 g2s1.handle.SetWeak(&g2s1, &WeakPointerCallback);
3721 g2s2.handle.SetWeak(&g2s2, &WeakPointerCallback); 3736 g2s2.handle.SetWeak(&g2s2, &WeakPointerCallback);
3722 CHECK(g2s1.handle.IsWeak()); 3737 CHECK(g2s1.handle.IsWeak());
3723 CHECK(g2s2.handle.IsWeak()); 3738 CHECK(g2s2.handle.IsWeak());
3724 3739
3725 g3s1.handle.Reset(iso, Object::New()); 3740 g3s1.handle.Reset(iso, Object::New(iso));
3726 g3s2.handle.Reset(iso, Object::New()); 3741 g3s2.handle.Reset(iso, Object::New(iso));
3727 g3s1.handle.SetWeak(&g3s1, &WeakPointerCallback); 3742 g3s1.handle.SetWeak(&g3s1, &WeakPointerCallback);
3728 g3s2.handle.SetWeak(&g3s2, &WeakPointerCallback); 3743 g3s2.handle.SetWeak(&g3s2, &WeakPointerCallback);
3729 CHECK(g3s1.handle.IsWeak()); 3744 CHECK(g3s1.handle.IsWeak());
3730 CHECK(g3s2.handle.IsWeak()); 3745 CHECK(g3s2.handle.IsWeak());
3731 3746
3732 g4s1.handle.Reset(iso, Object::New()); 3747 g4s1.handle.Reset(iso, Object::New(iso));
3733 g4s2.handle.Reset(iso, Object::New()); 3748 g4s2.handle.Reset(iso, Object::New(iso));
3734 g4s1.handle.SetWeak(&g4s1, &WeakPointerCallback); 3749 g4s1.handle.SetWeak(&g4s1, &WeakPointerCallback);
3735 g4s2.handle.SetWeak(&g4s2, &WeakPointerCallback); 3750 g4s2.handle.SetWeak(&g4s2, &WeakPointerCallback);
3736 CHECK(g4s1.handle.IsWeak()); 3751 CHECK(g4s1.handle.IsWeak());
3737 CHECK(g4s2.handle.IsWeak()); 3752 CHECK(g4s2.handle.IsWeak());
3738 } 3753 }
3739 3754
3740 WeakCallCounterAndPersistent<Value> root(&counter); 3755 WeakCallCounterAndPersistent<Value> root(&counter);
3741 root.handle.Reset(iso, g1s1.handle); // make a root. 3756 root.handle.Reset(iso, g1s1.handle); // make a root.
3742 3757
3743 // Connect groups. We're building the following cycle: 3758 // Connect groups. We're building the following cycle:
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
3812 3827
3813 WeakCallCounterAndPersistent<Value> g1s1(&counter); 3828 WeakCallCounterAndPersistent<Value> g1s1(&counter);
3814 WeakCallCounterAndPersistent<Value> g1s2(&counter); 3829 WeakCallCounterAndPersistent<Value> g1s2(&counter);
3815 WeakCallCounterAndPersistent<Value> g2s1(&counter); 3830 WeakCallCounterAndPersistent<Value> g2s1(&counter);
3816 WeakCallCounterAndPersistent<Value> g2s2(&counter); 3831 WeakCallCounterAndPersistent<Value> g2s2(&counter);
3817 WeakCallCounterAndPersistent<Value> g3s1(&counter); 3832 WeakCallCounterAndPersistent<Value> g3s1(&counter);
3818 WeakCallCounterAndPersistent<Value> g3s2(&counter); 3833 WeakCallCounterAndPersistent<Value> g3s2(&counter);
3819 3834
3820 { 3835 {
3821 HandleScope scope(iso); 3836 HandleScope scope(iso);
3822 g1s1.handle.Reset(iso, Object::New()); 3837 g1s1.handle.Reset(iso, Object::New(iso));
3823 g1s2.handle.Reset(iso, Object::New()); 3838 g1s2.handle.Reset(iso, Object::New(iso));
3824 g1s1.handle.SetWeak(&g1s1, &WeakPointerCallback); 3839 g1s1.handle.SetWeak(&g1s1, &WeakPointerCallback);
3825 g1s2.handle.SetWeak(&g1s2, &WeakPointerCallback); 3840 g1s2.handle.SetWeak(&g1s2, &WeakPointerCallback);
3826 3841
3827 g2s1.handle.Reset(iso, Object::New()); 3842 g2s1.handle.Reset(iso, Object::New(iso));
3828 g2s2.handle.Reset(iso, Object::New()); 3843 g2s2.handle.Reset(iso, Object::New(iso));
3829 g2s1.handle.SetWeak(&g2s1, &WeakPointerCallback); 3844 g2s1.handle.SetWeak(&g2s1, &WeakPointerCallback);
3830 g2s2.handle.SetWeak(&g2s2, &WeakPointerCallback); 3845 g2s2.handle.SetWeak(&g2s2, &WeakPointerCallback);
3831 3846
3832 g3s1.handle.Reset(iso, Object::New()); 3847 g3s1.handle.Reset(iso, Object::New(iso));
3833 g3s2.handle.Reset(iso, Object::New()); 3848 g3s2.handle.Reset(iso, Object::New(iso));
3834 g3s1.handle.SetWeak(&g3s1, &WeakPointerCallback); 3849 g3s1.handle.SetWeak(&g3s1, &WeakPointerCallback);
3835 g3s2.handle.SetWeak(&g3s2, &WeakPointerCallback); 3850 g3s2.handle.SetWeak(&g3s2, &WeakPointerCallback);
3836 } 3851 }
3837 3852
3838 // Make a root. 3853 // Make a root.
3839 WeakCallCounterAndPersistent<Value> root(&counter); 3854 WeakCallCounterAndPersistent<Value> root(&counter);
3840 root.handle.Reset(iso, g1s1.handle); 3855 root.handle.Reset(iso, g1s1.handle);
3841 root.handle.MarkPartiallyDependent(); 3856 root.handle.MarkPartiallyDependent();
3842 3857
3843 // Connect groups. We're building the following cycle: 3858 // Connect groups. We're building the following cycle:
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
3941 CHECK_EQ(7.56, message->GetScriptData()->NumberValue()); 3956 CHECK_EQ(7.56, message->GetScriptData()->NumberValue());
3942 CHECK(!message->IsSharedCrossOrigin()); 3957 CHECK(!message->IsSharedCrossOrigin());
3943 message_received = true; 3958 message_received = true;
3944 } 3959 }
3945 3960
3946 3961
3947 THREADED_TEST(MessageHandler0) { 3962 THREADED_TEST(MessageHandler0) {
3948 message_received = false; 3963 message_received = false;
3949 v8::HandleScope scope(CcTest::isolate()); 3964 v8::HandleScope scope(CcTest::isolate());
3950 CHECK(!message_received); 3965 CHECK(!message_received);
3966 LocalContext context;
3951 v8::V8::AddMessageListener(check_message_0, v8_num(5.76)); 3967 v8::V8::AddMessageListener(check_message_0, v8_num(5.76));
3952 LocalContext context;
3953 v8::ScriptOrigin origin = 3968 v8::ScriptOrigin origin =
3954 v8::ScriptOrigin(v8_str("6.75")); 3969 v8::ScriptOrigin(v8_str("6.75"));
3955 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"), 3970 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"),
3956 &origin); 3971 &origin);
3957 script->SetData(v8_str("7.56")); 3972 script->SetData(v8_str("7.56"));
3958 script->Run(); 3973 script->Run();
3959 CHECK(message_received); 3974 CHECK(message_received);
3960 // clear out the message listener 3975 // clear out the message listener
3961 v8::V8::RemoveMessageListeners(check_message_0); 3976 v8::V8::RemoveMessageListeners(check_message_0);
3962 } 3977 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
4023 4038
4024 TEST(MessageHandler3) { 4039 TEST(MessageHandler3) {
4025 message_received = false; 4040 message_received = false;
4026 v8::Isolate* isolate = CcTest::isolate(); 4041 v8::Isolate* isolate = CcTest::isolate();
4027 v8::HandleScope scope(isolate); 4042 v8::HandleScope scope(isolate);
4028 CHECK(!message_received); 4043 CHECK(!message_received);
4029 v8::V8::AddMessageListener(check_message_3); 4044 v8::V8::AddMessageListener(check_message_3);
4030 LocalContext context; 4045 LocalContext context;
4031 v8::ScriptOrigin origin = 4046 v8::ScriptOrigin origin =
4032 v8::ScriptOrigin(v8_str("6.75"), 4047 v8::ScriptOrigin(v8_str("6.75"),
4033 v8::Integer::New(1, isolate), 4048 v8::Integer::New(isolate, 1),
4034 v8::Integer::New(2, isolate), 4049 v8::Integer::New(isolate, 2),
4035 v8::True(isolate)); 4050 v8::True(isolate));
4036 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"), 4051 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"),
4037 &origin); 4052 &origin);
4038 script->Run(); 4053 script->Run();
4039 CHECK(message_received); 4054 CHECK(message_received);
4040 // clear out the message listener 4055 // clear out the message listener
4041 v8::V8::RemoveMessageListeners(check_message_3); 4056 v8::V8::RemoveMessageListeners(check_message_3);
4042 } 4057 }
4043 4058
4044 4059
4045 static void check_message_4(v8::Handle<v8::Message> message, 4060 static void check_message_4(v8::Handle<v8::Message> message,
4046 v8::Handle<Value> data) { 4061 v8::Handle<Value> data) {
4047 CHECK(!message->IsSharedCrossOrigin()); 4062 CHECK(!message->IsSharedCrossOrigin());
4048 CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue()); 4063 CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue());
4049 message_received = true; 4064 message_received = true;
4050 } 4065 }
4051 4066
4052 4067
4053 TEST(MessageHandler4) { 4068 TEST(MessageHandler4) {
4054 message_received = false; 4069 message_received = false;
4055 v8::Isolate* isolate = CcTest::isolate(); 4070 v8::Isolate* isolate = CcTest::isolate();
4056 v8::HandleScope scope(isolate); 4071 v8::HandleScope scope(isolate);
4057 CHECK(!message_received); 4072 CHECK(!message_received);
4058 v8::V8::AddMessageListener(check_message_4); 4073 v8::V8::AddMessageListener(check_message_4);
4059 LocalContext context; 4074 LocalContext context;
4060 v8::ScriptOrigin origin = 4075 v8::ScriptOrigin origin =
4061 v8::ScriptOrigin(v8_str("6.75"), 4076 v8::ScriptOrigin(v8_str("6.75"),
4062 v8::Integer::New(1, isolate), 4077 v8::Integer::New(isolate, 1),
4063 v8::Integer::New(2, isolate), 4078 v8::Integer::New(isolate, 2),
4064 v8::False(isolate)); 4079 v8::False(isolate));
4065 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"), 4080 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"),
4066 &origin); 4081 &origin);
4067 script->Run(); 4082 script->Run();
4068 CHECK(message_received); 4083 CHECK(message_received);
4069 // clear out the message listener 4084 // clear out the message listener
4070 v8::V8::RemoveMessageListeners(check_message_4); 4085 v8::V8::RemoveMessageListeners(check_message_4);
4071 } 4086 }
4072 4087
4073 4088
(...skipping 15 matching lines...) Expand all
4089 4104
4090 TEST(MessageHandler5) { 4105 TEST(MessageHandler5) {
4091 message_received = false; 4106 message_received = false;
4092 v8::Isolate* isolate = CcTest::isolate(); 4107 v8::Isolate* isolate = CcTest::isolate();
4093 v8::HandleScope scope(isolate); 4108 v8::HandleScope scope(isolate);
4094 CHECK(!message_received); 4109 CHECK(!message_received);
4095 v8::V8::AddMessageListener(check_message_5a); 4110 v8::V8::AddMessageListener(check_message_5a);
4096 LocalContext context; 4111 LocalContext context;
4097 v8::ScriptOrigin origin = 4112 v8::ScriptOrigin origin =
4098 v8::ScriptOrigin(v8_str("6.75"), 4113 v8::ScriptOrigin(v8_str("6.75"),
4099 v8::Integer::New(1, isolate), 4114 v8::Integer::New(isolate, 1),
4100 v8::Integer::New(2, isolate), 4115 v8::Integer::New(isolate, 2),
4101 v8::True(isolate)); 4116 v8::True(isolate));
4102 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"), 4117 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"),
4103 &origin); 4118 &origin);
4104 script->Run(); 4119 script->Run();
4105 CHECK(message_received); 4120 CHECK(message_received);
4106 // clear out the message listener 4121 // clear out the message listener
4107 v8::V8::RemoveMessageListeners(check_message_5a); 4122 v8::V8::RemoveMessageListeners(check_message_5a);
4108 4123
4109 message_received = false; 4124 message_received = false;
4110 v8::V8::AddMessageListener(check_message_5b); 4125 v8::V8::AddMessageListener(check_message_5b);
4111 origin = 4126 origin =
4112 v8::ScriptOrigin(v8_str("6.75"), 4127 v8::ScriptOrigin(v8_str("6.75"),
4113 v8::Integer::New(1, isolate), 4128 v8::Integer::New(isolate, 1),
4114 v8::Integer::New(2, isolate), 4129 v8::Integer::New(isolate, 2),
4115 v8::False(isolate)); 4130 v8::False(isolate));
4116 script = Script::Compile(v8_str("throw 'error'"), 4131 script = Script::Compile(v8_str("throw 'error'"),
4117 &origin); 4132 &origin);
4118 script->Run(); 4133 script->Run();
4119 CHECK(message_received); 4134 CHECK(message_received);
4120 // clear out the message listener 4135 // clear out the message listener
4121 v8::V8::RemoveMessageListeners(check_message_5b); 4136 v8::V8::RemoveMessageListeners(check_message_5b);
4122 } 4137 }
4123 4138
4124 4139
4125 THREADED_TEST(GetSetProperty) { 4140 THREADED_TEST(GetSetProperty) {
4126 LocalContext context; 4141 LocalContext context;
4127 v8::HandleScope scope(context->GetIsolate()); 4142 v8::Isolate* isolate = context->GetIsolate();
4143 v8::HandleScope scope(isolate);
4128 context->Global()->Set(v8_str("foo"), v8_num(14)); 4144 context->Global()->Set(v8_str("foo"), v8_num(14));
4129 context->Global()->Set(v8_str("12"), v8_num(92)); 4145 context->Global()->Set(v8_str("12"), v8_num(92));
4130 context->Global()->Set(v8::Integer::New(16), v8_num(32)); 4146 context->Global()->Set(v8::Integer::New(isolate, 16), v8_num(32));
4131 context->Global()->Set(v8_num(13), v8_num(56)); 4147 context->Global()->Set(v8_num(13), v8_num(56));
4132 Local<Value> foo = Script::Compile(v8_str("this.foo"))->Run(); 4148 Local<Value> foo = Script::Compile(v8_str("this.foo"))->Run();
4133 CHECK_EQ(14, foo->Int32Value()); 4149 CHECK_EQ(14, foo->Int32Value());
4134 Local<Value> twelve = Script::Compile(v8_str("this[12]"))->Run(); 4150 Local<Value> twelve = Script::Compile(v8_str("this[12]"))->Run();
4135 CHECK_EQ(92, twelve->Int32Value()); 4151 CHECK_EQ(92, twelve->Int32Value());
4136 Local<Value> sixteen = Script::Compile(v8_str("this[16]"))->Run(); 4152 Local<Value> sixteen = Script::Compile(v8_str("this[16]"))->Run();
4137 CHECK_EQ(32, sixteen->Int32Value()); 4153 CHECK_EQ(32, sixteen->Int32Value());
4138 Local<Value> thirteen = Script::Compile(v8_str("this[13]"))->Run(); 4154 Local<Value> thirteen = Script::Compile(v8_str("this[13]"))->Run();
4139 CHECK_EQ(56, thirteen->Int32Value()); 4155 CHECK_EQ(56, thirteen->Int32Value());
4140 CHECK_EQ(92, context->Global()->Get(v8::Integer::New(12))->Int32Value()); 4156 CHECK_EQ(92,
4157 context->Global()->Get(v8::Integer::New(isolate, 12))->Int32Value());
4141 CHECK_EQ(92, context->Global()->Get(v8_str("12"))->Int32Value()); 4158 CHECK_EQ(92, context->Global()->Get(v8_str("12"))->Int32Value());
4142 CHECK_EQ(92, context->Global()->Get(v8_num(12))->Int32Value()); 4159 CHECK_EQ(92, context->Global()->Get(v8_num(12))->Int32Value());
4143 CHECK_EQ(32, context->Global()->Get(v8::Integer::New(16))->Int32Value()); 4160 CHECK_EQ(32,
4161 context->Global()->Get(v8::Integer::New(isolate, 16))->Int32Value());
4144 CHECK_EQ(32, context->Global()->Get(v8_str("16"))->Int32Value()); 4162 CHECK_EQ(32, context->Global()->Get(v8_str("16"))->Int32Value());
4145 CHECK_EQ(32, context->Global()->Get(v8_num(16))->Int32Value()); 4163 CHECK_EQ(32, context->Global()->Get(v8_num(16))->Int32Value());
4146 CHECK_EQ(56, context->Global()->Get(v8::Integer::New(13))->Int32Value()); 4164 CHECK_EQ(56,
4165 context->Global()->Get(v8::Integer::New(isolate, 13))->Int32Value());
4147 CHECK_EQ(56, context->Global()->Get(v8_str("13"))->Int32Value()); 4166 CHECK_EQ(56, context->Global()->Get(v8_str("13"))->Int32Value());
4148 CHECK_EQ(56, context->Global()->Get(v8_num(13))->Int32Value()); 4167 CHECK_EQ(56, context->Global()->Get(v8_num(13))->Int32Value());
4149 } 4168 }
4150 4169
4151 4170
4152 THREADED_TEST(PropertyAttributes) { 4171 THREADED_TEST(PropertyAttributes) {
4153 LocalContext context; 4172 LocalContext context;
4154 v8::HandleScope scope(context->GetIsolate()); 4173 v8::HandleScope scope(context->GetIsolate());
4155 // none 4174 // none
4156 Local<String> prop = v8_str("none"); 4175 Local<String> prop = v8_str("none");
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
4227 Local<v8::Array> result = v8::Array::New(args.GetIsolate(), args.Length()); 4246 Local<v8::Array> result = v8::Array::New(args.GetIsolate(), args.Length());
4228 for (int i = 0; i < args.Length(); i++) 4247 for (int i = 0; i < args.Length(); i++)
4229 result->Set(i, args[i]); 4248 result->Set(i, args[i]);
4230 args.GetReturnValue().Set(scope.Escape(result)); 4249 args.GetReturnValue().Set(scope.Escape(result));
4231 } 4250 }
4232 4251
4233 4252
4234 THREADED_TEST(Vector) { 4253 THREADED_TEST(Vector) {
4235 v8::Isolate* isolate = CcTest::isolate(); 4254 v8::Isolate* isolate = CcTest::isolate();
4236 v8::HandleScope scope(isolate); 4255 v8::HandleScope scope(isolate);
4237 Local<ObjectTemplate> global = ObjectTemplate::New(); 4256 Local<ObjectTemplate> global = ObjectTemplate::New(isolate);
4238 global->Set(v8_str("f"), v8::FunctionTemplate::New(isolate, HandleF)); 4257 global->Set(v8_str("f"), v8::FunctionTemplate::New(isolate, HandleF));
4239 LocalContext context(0, global); 4258 LocalContext context(0, global);
4240 4259
4241 const char* fun = "f()"; 4260 const char* fun = "f()";
4242 Local<v8::Array> a0 = CompileRun(fun).As<v8::Array>(); 4261 Local<v8::Array> a0 = CompileRun(fun).As<v8::Array>();
4243 CHECK_EQ(0, a0->Length()); 4262 CHECK_EQ(0, a0->Length());
4244 4263
4245 const char* fun2 = "f(11)"; 4264 const char* fun2 = "f(11)";
4246 Local<v8::Array> a1 = CompileRun(fun2).As<v8::Array>(); 4265 Local<v8::Array> a1 = CompileRun(fun2).As<v8::Array>();
4247 CHECK_EQ(1, a1->Length()); 4266 CHECK_EQ(1, a1->Length());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
4296 Local<Function> ReturnThisStrict = 4315 Local<Function> ReturnThisStrict =
4297 Local<Function>::Cast(context->Global()->Get(v8_str("ReturnThisStrict"))); 4316 Local<Function>::Cast(context->Global()->Get(v8_str("ReturnThisStrict")));
4298 4317
4299 v8::Handle<Value>* args0 = NULL; 4318 v8::Handle<Value>* args0 = NULL;
4300 Local<v8::Array> a0 = Local<v8::Array>::Cast(Foo->Call(Foo, 0, args0)); 4319 Local<v8::Array> a0 = Local<v8::Array>::Cast(Foo->Call(Foo, 0, args0));
4301 CHECK_EQ(0, a0->Length()); 4320 CHECK_EQ(0, a0->Length());
4302 4321
4303 v8::Handle<Value> args1[] = { v8_num(1.1) }; 4322 v8::Handle<Value> args1[] = { v8_num(1.1) };
4304 Local<v8::Array> a1 = Local<v8::Array>::Cast(Foo->Call(Foo, 1, args1)); 4323 Local<v8::Array> a1 = Local<v8::Array>::Cast(Foo->Call(Foo, 1, args1));
4305 CHECK_EQ(1, a1->Length()); 4324 CHECK_EQ(1, a1->Length());
4306 CHECK_EQ(1.1, a1->Get(v8::Integer::New(0))->NumberValue()); 4325 CHECK_EQ(1.1, a1->Get(v8::Integer::New(isolate, 0))->NumberValue());
4307 4326
4308 v8::Handle<Value> args2[] = { v8_num(2.2), 4327 v8::Handle<Value> args2[] = { v8_num(2.2),
4309 v8_num(3.3) }; 4328 v8_num(3.3) };
4310 Local<v8::Array> a2 = Local<v8::Array>::Cast(Foo->Call(Foo, 2, args2)); 4329 Local<v8::Array> a2 = Local<v8::Array>::Cast(Foo->Call(Foo, 2, args2));
4311 CHECK_EQ(2, a2->Length()); 4330 CHECK_EQ(2, a2->Length());
4312 CHECK_EQ(2.2, a2->Get(v8::Integer::New(0))->NumberValue()); 4331 CHECK_EQ(2.2, a2->Get(v8::Integer::New(isolate, 0))->NumberValue());
4313 CHECK_EQ(3.3, a2->Get(v8::Integer::New(1))->NumberValue()); 4332 CHECK_EQ(3.3, a2->Get(v8::Integer::New(isolate, 1))->NumberValue());
4314 4333
4315 v8::Handle<Value> args3[] = { v8_num(4.4), 4334 v8::Handle<Value> args3[] = { v8_num(4.4),
4316 v8_num(5.5), 4335 v8_num(5.5),
4317 v8_num(6.6) }; 4336 v8_num(6.6) };
4318 Local<v8::Array> a3 = Local<v8::Array>::Cast(Foo->Call(Foo, 3, args3)); 4337 Local<v8::Array> a3 = Local<v8::Array>::Cast(Foo->Call(Foo, 3, args3));
4319 CHECK_EQ(3, a3->Length()); 4338 CHECK_EQ(3, a3->Length());
4320 CHECK_EQ(4.4, a3->Get(v8::Integer::New(0))->NumberValue()); 4339 CHECK_EQ(4.4, a3->Get(v8::Integer::New(isolate, 0))->NumberValue());
4321 CHECK_EQ(5.5, a3->Get(v8::Integer::New(1))->NumberValue()); 4340 CHECK_EQ(5.5, a3->Get(v8::Integer::New(isolate, 1))->NumberValue());
4322 CHECK_EQ(6.6, a3->Get(v8::Integer::New(2))->NumberValue()); 4341 CHECK_EQ(6.6, a3->Get(v8::Integer::New(isolate, 2))->NumberValue());
4323 4342
4324 v8::Handle<Value> args4[] = { v8_num(7.7), 4343 v8::Handle<Value> args4[] = { v8_num(7.7),
4325 v8_num(8.8), 4344 v8_num(8.8),
4326 v8_num(9.9), 4345 v8_num(9.9),
4327 v8_num(10.11) }; 4346 v8_num(10.11) };
4328 Local<v8::Array> a4 = Local<v8::Array>::Cast(Foo->Call(Foo, 4, args4)); 4347 Local<v8::Array> a4 = Local<v8::Array>::Cast(Foo->Call(Foo, 4, args4));
4329 CHECK_EQ(4, a4->Length()); 4348 CHECK_EQ(4, a4->Length());
4330 CHECK_EQ(7.7, a4->Get(v8::Integer::New(0))->NumberValue()); 4349 CHECK_EQ(7.7, a4->Get(v8::Integer::New(isolate, 0))->NumberValue());
4331 CHECK_EQ(8.8, a4->Get(v8::Integer::New(1))->NumberValue()); 4350 CHECK_EQ(8.8, a4->Get(v8::Integer::New(isolate, 1))->NumberValue());
4332 CHECK_EQ(9.9, a4->Get(v8::Integer::New(2))->NumberValue()); 4351 CHECK_EQ(9.9, a4->Get(v8::Integer::New(isolate, 2))->NumberValue());
4333 CHECK_EQ(10.11, a4->Get(v8::Integer::New(3))->NumberValue()); 4352 CHECK_EQ(10.11, a4->Get(v8::Integer::New(isolate, 3))->NumberValue());
4334 4353
4335 Local<v8::Value> r1 = ReturnThisSloppy->Call(v8::Undefined(isolate), 0, NULL); 4354 Local<v8::Value> r1 = ReturnThisSloppy->Call(v8::Undefined(isolate), 0, NULL);
4336 CHECK(r1->StrictEquals(context->Global())); 4355 CHECK(r1->StrictEquals(context->Global()));
4337 Local<v8::Value> r2 = ReturnThisSloppy->Call(v8::Null(isolate), 0, NULL); 4356 Local<v8::Value> r2 = ReturnThisSloppy->Call(v8::Null(isolate), 0, NULL);
4338 CHECK(r2->StrictEquals(context->Global())); 4357 CHECK(r2->StrictEquals(context->Global()));
4339 Local<v8::Value> r3 = ReturnThisSloppy->Call(v8_num(42), 0, NULL); 4358 Local<v8::Value> r3 = ReturnThisSloppy->Call(v8_num(42), 0, NULL);
4340 CHECK(r3->IsNumberObject()); 4359 CHECK(r3->IsNumberObject());
4341 CHECK_EQ(42.0, r3.As<v8::NumberObject>()->ValueOf()); 4360 CHECK_EQ(42.0, r3.As<v8::NumberObject>()->ValueOf());
4342 Local<v8::Value> r4 = ReturnThisSloppy->Call(v8_str("hello"), 0, NULL); 4361 Local<v8::Value> r4 = ReturnThisSloppy->Call(v8_str("hello"), 0, NULL);
4343 CHECK(r4->IsStringObject()); 4362 CHECK(r4->IsStringObject());
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
4407 4426
4408 4427
4409 TEST(OutOfMemoryNested) { 4428 TEST(OutOfMemoryNested) {
4410 // It's not possible to read a snapshot into a heap with different dimensions. 4429 // It's not possible to read a snapshot into a heap with different dimensions.
4411 if (i::Snapshot::IsEnabled()) return; 4430 if (i::Snapshot::IsEnabled()) return;
4412 // Set heap limits. 4431 // Set heap limits.
4413 static const int K = 1024; 4432 static const int K = 1024;
4414 v8::ResourceConstraints constraints; 4433 v8::ResourceConstraints constraints;
4415 constraints.set_max_young_space_size(256 * K); 4434 constraints.set_max_young_space_size(256 * K);
4416 constraints.set_max_old_space_size(5 * K * K); 4435 constraints.set_max_old_space_size(5 * K * K);
4417 v8::SetResourceConstraints(CcTest::isolate(), &constraints); 4436 v8::Isolate* isolate = CcTest::isolate();
4437 v8::SetResourceConstraints(isolate, &constraints);
4418 4438
4419 v8::HandleScope scope(CcTest::isolate()); 4439 v8::HandleScope scope(isolate);
4420 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4440 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
4421 templ->Set(v8_str("ProvokeOutOfMemory"), 4441 templ->Set(v8_str("ProvokeOutOfMemory"),
4422 v8::FunctionTemplate::New(CcTest::isolate(), ProvokeOutOfMemory)); 4442 v8::FunctionTemplate::New(isolate, ProvokeOutOfMemory));
4423 LocalContext context(0, templ); 4443 LocalContext context(0, templ);
4424 v8::V8::IgnoreOutOfMemoryException(); 4444 v8::V8::IgnoreOutOfMemoryException();
4425 Local<Value> result = CompileRun( 4445 Local<Value> result = CompileRun(
4426 "var thrown = false;" 4446 "var thrown = false;"
4427 "try {" 4447 "try {"
4428 " ProvokeOutOfMemory();" 4448 " ProvokeOutOfMemory();"
4429 "} catch (e) {" 4449 "} catch (e) {"
4430 " thrown = true;" 4450 " thrown = true;"
4431 "}"); 4451 "}");
4432 // Check for out of memory state. 4452 // Check for out of memory state.
(...skipping 27 matching lines...) Expand all
4460 CompileRun( 4480 CompileRun(
4461 "var str = Array.prototype.join.call({length: 513}, \"A\").toUpperCase();" 4481 "var str = Array.prototype.join.call({length: 513}, \"A\").toUpperCase();"
4462 "for (var i = 0; i < 22; i++) { str = str + str; }"); 4482 "for (var i = 0; i < 22; i++) { str = str + str; }");
4463 4483
4464 CHECK(false); // Should not return. 4484 CHECK(false); // Should not return.
4465 } 4485 }
4466 4486
4467 4487
4468 THREADED_TEST(ConstructCall) { 4488 THREADED_TEST(ConstructCall) {
4469 LocalContext context; 4489 LocalContext context;
4470 v8::HandleScope scope(context->GetIsolate()); 4490 v8::Isolate* isolate = context->GetIsolate();
4491 v8::HandleScope scope(isolate);
4471 CompileRun( 4492 CompileRun(
4472 "function Foo() {" 4493 "function Foo() {"
4473 " var result = [];" 4494 " var result = [];"
4474 " for (var i = 0; i < arguments.length; i++) {" 4495 " for (var i = 0; i < arguments.length; i++) {"
4475 " result.push(arguments[i]);" 4496 " result.push(arguments[i]);"
4476 " }" 4497 " }"
4477 " return result;" 4498 " return result;"
4478 "}"); 4499 "}");
4479 Local<Function> Foo = 4500 Local<Function> Foo =
4480 Local<Function>::Cast(context->Global()->Get(v8_str("Foo"))); 4501 Local<Function>::Cast(context->Global()->Get(v8_str("Foo")));
4481 4502
4482 v8::Handle<Value>* args0 = NULL; 4503 v8::Handle<Value>* args0 = NULL;
4483 Local<v8::Array> a0 = Local<v8::Array>::Cast(Foo->NewInstance(0, args0)); 4504 Local<v8::Array> a0 = Local<v8::Array>::Cast(Foo->NewInstance(0, args0));
4484 CHECK_EQ(0, a0->Length()); 4505 CHECK_EQ(0, a0->Length());
4485 4506
4486 v8::Handle<Value> args1[] = { v8_num(1.1) }; 4507 v8::Handle<Value> args1[] = { v8_num(1.1) };
4487 Local<v8::Array> a1 = Local<v8::Array>::Cast(Foo->NewInstance(1, args1)); 4508 Local<v8::Array> a1 = Local<v8::Array>::Cast(Foo->NewInstance(1, args1));
4488 CHECK_EQ(1, a1->Length()); 4509 CHECK_EQ(1, a1->Length());
4489 CHECK_EQ(1.1, a1->Get(v8::Integer::New(0))->NumberValue()); 4510 CHECK_EQ(1.1, a1->Get(v8::Integer::New(isolate, 0))->NumberValue());
4490 4511
4491 v8::Handle<Value> args2[] = { v8_num(2.2), 4512 v8::Handle<Value> args2[] = { v8_num(2.2),
4492 v8_num(3.3) }; 4513 v8_num(3.3) };
4493 Local<v8::Array> a2 = Local<v8::Array>::Cast(Foo->NewInstance(2, args2)); 4514 Local<v8::Array> a2 = Local<v8::Array>::Cast(Foo->NewInstance(2, args2));
4494 CHECK_EQ(2, a2->Length()); 4515 CHECK_EQ(2, a2->Length());
4495 CHECK_EQ(2.2, a2->Get(v8::Integer::New(0))->NumberValue()); 4516 CHECK_EQ(2.2, a2->Get(v8::Integer::New(isolate, 0))->NumberValue());
4496 CHECK_EQ(3.3, a2->Get(v8::Integer::New(1))->NumberValue()); 4517 CHECK_EQ(3.3, a2->Get(v8::Integer::New(isolate, 1))->NumberValue());
4497 4518
4498 v8::Handle<Value> args3[] = { v8_num(4.4), 4519 v8::Handle<Value> args3[] = { v8_num(4.4),
4499 v8_num(5.5), 4520 v8_num(5.5),
4500 v8_num(6.6) }; 4521 v8_num(6.6) };
4501 Local<v8::Array> a3 = Local<v8::Array>::Cast(Foo->NewInstance(3, args3)); 4522 Local<v8::Array> a3 = Local<v8::Array>::Cast(Foo->NewInstance(3, args3));
4502 CHECK_EQ(3, a3->Length()); 4523 CHECK_EQ(3, a3->Length());
4503 CHECK_EQ(4.4, a3->Get(v8::Integer::New(0))->NumberValue()); 4524 CHECK_EQ(4.4, a3->Get(v8::Integer::New(isolate, 0))->NumberValue());
4504 CHECK_EQ(5.5, a3->Get(v8::Integer::New(1))->NumberValue()); 4525 CHECK_EQ(5.5, a3->Get(v8::Integer::New(isolate, 1))->NumberValue());
4505 CHECK_EQ(6.6, a3->Get(v8::Integer::New(2))->NumberValue()); 4526 CHECK_EQ(6.6, a3->Get(v8::Integer::New(isolate, 2))->NumberValue());
4506 4527
4507 v8::Handle<Value> args4[] = { v8_num(7.7), 4528 v8::Handle<Value> args4[] = { v8_num(7.7),
4508 v8_num(8.8), 4529 v8_num(8.8),
4509 v8_num(9.9), 4530 v8_num(9.9),
4510 v8_num(10.11) }; 4531 v8_num(10.11) };
4511 Local<v8::Array> a4 = Local<v8::Array>::Cast(Foo->NewInstance(4, args4)); 4532 Local<v8::Array> a4 = Local<v8::Array>::Cast(Foo->NewInstance(4, args4));
4512 CHECK_EQ(4, a4->Length()); 4533 CHECK_EQ(4, a4->Length());
4513 CHECK_EQ(7.7, a4->Get(v8::Integer::New(0))->NumberValue()); 4534 CHECK_EQ(7.7, a4->Get(v8::Integer::New(isolate, 0))->NumberValue());
4514 CHECK_EQ(8.8, a4->Get(v8::Integer::New(1))->NumberValue()); 4535 CHECK_EQ(8.8, a4->Get(v8::Integer::New(isolate, 1))->NumberValue());
4515 CHECK_EQ(9.9, a4->Get(v8::Integer::New(2))->NumberValue()); 4536 CHECK_EQ(9.9, a4->Get(v8::Integer::New(isolate, 2))->NumberValue());
4516 CHECK_EQ(10.11, a4->Get(v8::Integer::New(3))->NumberValue()); 4537 CHECK_EQ(10.11, a4->Get(v8::Integer::New(isolate, 3))->NumberValue());
4517 } 4538 }
4518 4539
4519 4540
4520 static void CheckUncle(v8::TryCatch* try_catch) { 4541 static void CheckUncle(v8::TryCatch* try_catch) {
4521 CHECK(try_catch->HasCaught()); 4542 CHECK(try_catch->HasCaught());
4522 String::Utf8Value str_value(try_catch->Exception()); 4543 String::Utf8Value str_value(try_catch->Exception());
4523 CHECK_EQ(*str_value, "uncle?"); 4544 CHECK_EQ(*str_value, "uncle?");
4524 try_catch->Reset(); 4545 try_catch->Reset();
4525 } 4546 }
4526 4547
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
4692 } 4713 }
4693 v8::HandleScope scope(args.GetIsolate()); 4714 v8::HandleScope scope(args.GetIsolate());
4694 v8::TryCatch try_catch; 4715 v8::TryCatch try_catch;
4695 Local<Value> result = v8::Script::Compile(args[0]->ToString())->Run(); 4716 Local<Value> result = v8::Script::Compile(args[0]->ToString())->Run();
4696 CHECK(!try_catch.HasCaught() || result.IsEmpty()); 4717 CHECK(!try_catch.HasCaught() || result.IsEmpty());
4697 args.GetReturnValue().Set(try_catch.HasCaught()); 4718 args.GetReturnValue().Set(try_catch.HasCaught());
4698 } 4719 }
4699 4720
4700 4721
4701 THREADED_TEST(APICatch) { 4722 THREADED_TEST(APICatch) {
4702 v8::HandleScope scope(CcTest::isolate()); 4723 v8::Isolate* isolate = CcTest::isolate();
4703 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4724 v8::HandleScope scope(isolate);
4725 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
4704 templ->Set(v8_str("ThrowFromC"), 4726 templ->Set(v8_str("ThrowFromC"),
4705 v8::FunctionTemplate::New(CcTest::isolate(), ThrowFromC)); 4727 v8::FunctionTemplate::New(isolate, ThrowFromC));
4706 LocalContext context(0, templ); 4728 LocalContext context(0, templ);
4707 CompileRun( 4729 CompileRun(
4708 "var thrown = false;" 4730 "var thrown = false;"
4709 "try {" 4731 "try {"
4710 " ThrowFromC();" 4732 " ThrowFromC();"
4711 "} catch (e) {" 4733 "} catch (e) {"
4712 " thrown = true;" 4734 " thrown = true;"
4713 "}"); 4735 "}");
4714 Local<Value> thrown = context->Global()->Get(v8_str("thrown")); 4736 Local<Value> thrown = context->Global()->Get(v8_str("thrown"));
4715 CHECK(thrown->BooleanValue()); 4737 CHECK(thrown->BooleanValue());
4716 } 4738 }
4717 4739
4718 4740
4719 THREADED_TEST(APIThrowTryCatch) { 4741 THREADED_TEST(APIThrowTryCatch) {
4720 v8::HandleScope scope(CcTest::isolate()); 4742 v8::Isolate* isolate = CcTest::isolate();
4721 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4743 v8::HandleScope scope(isolate);
4744 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
4722 templ->Set(v8_str("ThrowFromC"), 4745 templ->Set(v8_str("ThrowFromC"),
4723 v8::FunctionTemplate::New(CcTest::isolate(), ThrowFromC)); 4746 v8::FunctionTemplate::New(isolate, ThrowFromC));
4724 LocalContext context(0, templ); 4747 LocalContext context(0, templ);
4725 v8::TryCatch try_catch; 4748 v8::TryCatch try_catch;
4726 CompileRun("ThrowFromC();"); 4749 CompileRun("ThrowFromC();");
4727 CHECK(try_catch.HasCaught()); 4750 CHECK(try_catch.HasCaught());
4728 } 4751 }
4729 4752
4730 4753
4731 // Test that a try-finally block doesn't shadow a try-catch block 4754 // Test that a try-finally block doesn't shadow a try-catch block
4732 // when setting up an external handler. 4755 // when setting up an external handler.
4733 // 4756 //
4734 // BUG(271): Some of the exception propagation does not work on the 4757 // BUG(271): Some of the exception propagation does not work on the
4735 // ARM simulator because the simulator separates the C++ stack and the 4758 // ARM simulator because the simulator separates the C++ stack and the
4736 // JS stack. This test therefore fails on the simulator. The test is 4759 // JS stack. This test therefore fails on the simulator. The test is
4737 // not threaded to allow the threading tests to run on the simulator. 4760 // not threaded to allow the threading tests to run on the simulator.
4738 TEST(TryCatchInTryFinally) { 4761 TEST(TryCatchInTryFinally) {
4739 v8::HandleScope scope(CcTest::isolate()); 4762 v8::Isolate* isolate = CcTest::isolate();
4740 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4763 v8::HandleScope scope(isolate);
4764 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
4741 templ->Set(v8_str("CCatcher"), 4765 templ->Set(v8_str("CCatcher"),
4742 v8::FunctionTemplate::New(CcTest::isolate(), CCatcher)); 4766 v8::FunctionTemplate::New(isolate, CCatcher));
4743 LocalContext context(0, templ); 4767 LocalContext context(0, templ);
4744 Local<Value> result = CompileRun("try {" 4768 Local<Value> result = CompileRun("try {"
4745 " try {" 4769 " try {"
4746 " CCatcher('throw 7;');" 4770 " CCatcher('throw 7;');"
4747 " } finally {" 4771 " } finally {"
4748 " }" 4772 " }"
4749 "} catch (e) {" 4773 "} catch (e) {"
4750 "}"); 4774 "}");
4751 CHECK(result->IsTrue()); 4775 CHECK(result->IsTrue());
4752 } 4776 }
(...skipping 13 matching lines...) Expand all
4766 } 4790 }
4767 4791
4768 4792
4769 // Test that overwritten methods are not invoked on uncaught exception 4793 // Test that overwritten methods are not invoked on uncaught exception
4770 // formatting. However, they are invoked when performing normal error 4794 // formatting. However, they are invoked when performing normal error
4771 // string conversions. 4795 // string conversions.
4772 TEST(APIThrowMessageOverwrittenToString) { 4796 TEST(APIThrowMessageOverwrittenToString) {
4773 v8::Isolate* isolate = CcTest::isolate(); 4797 v8::Isolate* isolate = CcTest::isolate();
4774 v8::HandleScope scope(isolate); 4798 v8::HandleScope scope(isolate);
4775 v8::V8::AddMessageListener(check_reference_error_message); 4799 v8::V8::AddMessageListener(check_reference_error_message);
4776 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4800 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
4777 templ->Set(v8_str("fail"), v8::FunctionTemplate::New(isolate, Fail)); 4801 templ->Set(v8_str("fail"), v8::FunctionTemplate::New(isolate, Fail));
4778 LocalContext context(NULL, templ); 4802 LocalContext context(NULL, templ);
4779 CompileRun("asdf;"); 4803 CompileRun("asdf;");
4780 CompileRun("var limit = {};" 4804 CompileRun("var limit = {};"
4781 "limit.valueOf = fail;" 4805 "limit.valueOf = fail;"
4782 "Error.stackTraceLimit = limit;"); 4806 "Error.stackTraceLimit = limit;");
4783 CompileRun("asdf"); 4807 CompileRun("asdf");
4784 CompileRun("Array.prototype.pop = fail;"); 4808 CompileRun("Array.prototype.pop = fail;");
4785 CompileRun("Object.prototype.hasOwnProperty = fail;"); 4809 CompileRun("Object.prototype.hasOwnProperty = fail;");
4786 CompileRun("Object.prototype.toString = function f() { return 'Yikes'; }"); 4810 CompileRun("Object.prototype.toString = function f() { return 'Yikes'; }");
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
4888 4912
4889 static void receive_message(v8::Handle<v8::Message> message, 4913 static void receive_message(v8::Handle<v8::Message> message,
4890 v8::Handle<v8::Value> data) { 4914 v8::Handle<v8::Value> data) {
4891 message->Get(); 4915 message->Get();
4892 message_received = true; 4916 message_received = true;
4893 } 4917 }
4894 4918
4895 4919
4896 TEST(APIThrowMessage) { 4920 TEST(APIThrowMessage) {
4897 message_received = false; 4921 message_received = false;
4898 v8::HandleScope scope(CcTest::isolate()); 4922 v8::Isolate* isolate = CcTest::isolate();
4923 v8::HandleScope scope(isolate);
4899 v8::V8::AddMessageListener(receive_message); 4924 v8::V8::AddMessageListener(receive_message);
4900 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4925 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
4901 templ->Set(v8_str("ThrowFromC"), 4926 templ->Set(v8_str("ThrowFromC"),
4902 v8::FunctionTemplate::New(CcTest::isolate(), ThrowFromC)); 4927 v8::FunctionTemplate::New(isolate, ThrowFromC));
4903 LocalContext context(0, templ); 4928 LocalContext context(0, templ);
4904 CompileRun("ThrowFromC();"); 4929 CompileRun("ThrowFromC();");
4905 CHECK(message_received); 4930 CHECK(message_received);
4906 v8::V8::RemoveMessageListeners(receive_message); 4931 v8::V8::RemoveMessageListeners(receive_message);
4907 } 4932 }
4908 4933
4909 4934
4910 TEST(APIThrowMessageAndVerboseTryCatch) { 4935 TEST(APIThrowMessageAndVerboseTryCatch) {
4911 message_received = false; 4936 message_received = false;
4912 v8::HandleScope scope(CcTest::isolate()); 4937 v8::Isolate* isolate = CcTest::isolate();
4938 v8::HandleScope scope(isolate);
4913 v8::V8::AddMessageListener(receive_message); 4939 v8::V8::AddMessageListener(receive_message);
4914 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4940 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
4915 templ->Set(v8_str("ThrowFromC"), 4941 templ->Set(v8_str("ThrowFromC"),
4916 v8::FunctionTemplate::New(CcTest::isolate(), ThrowFromC)); 4942 v8::FunctionTemplate::New(isolate, ThrowFromC));
4917 LocalContext context(0, templ); 4943 LocalContext context(0, templ);
4918 v8::TryCatch try_catch; 4944 v8::TryCatch try_catch;
4919 try_catch.SetVerbose(true); 4945 try_catch.SetVerbose(true);
4920 Local<Value> result = CompileRun("ThrowFromC();"); 4946 Local<Value> result = CompileRun("ThrowFromC();");
4921 CHECK(try_catch.HasCaught()); 4947 CHECK(try_catch.HasCaught());
4922 CHECK(result.IsEmpty()); 4948 CHECK(result.IsEmpty());
4923 CHECK(message_received); 4949 CHECK(message_received);
4924 v8::V8::RemoveMessageListeners(receive_message); 4950 v8::V8::RemoveMessageListeners(receive_message);
4925 } 4951 }
4926 4952
4927 4953
4928 TEST(APIStackOverflowAndVerboseTryCatch) { 4954 TEST(APIStackOverflowAndVerboseTryCatch) {
4929 message_received = false; 4955 message_received = false;
4930 LocalContext context; 4956 LocalContext context;
4931 v8::HandleScope scope(context->GetIsolate()); 4957 v8::HandleScope scope(context->GetIsolate());
4932 v8::V8::AddMessageListener(receive_message); 4958 v8::V8::AddMessageListener(receive_message);
4933 v8::TryCatch try_catch; 4959 v8::TryCatch try_catch;
4934 try_catch.SetVerbose(true); 4960 try_catch.SetVerbose(true);
4935 Local<Value> result = CompileRun("function foo() { foo(); } foo();"); 4961 Local<Value> result = CompileRun("function foo() { foo(); } foo();");
4936 CHECK(try_catch.HasCaught()); 4962 CHECK(try_catch.HasCaught());
4937 CHECK(result.IsEmpty()); 4963 CHECK(result.IsEmpty());
4938 CHECK(message_received); 4964 CHECK(message_received);
4939 v8::V8::RemoveMessageListeners(receive_message); 4965 v8::V8::RemoveMessageListeners(receive_message);
4940 } 4966 }
4941 4967
4942 4968
4943 THREADED_TEST(ExternalScriptException) { 4969 THREADED_TEST(ExternalScriptException) {
4944 v8::HandleScope scope(CcTest::isolate()); 4970 v8::Isolate* isolate = CcTest::isolate();
4945 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4971 v8::HandleScope scope(isolate);
4972 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
4946 templ->Set(v8_str("ThrowFromC"), 4973 templ->Set(v8_str("ThrowFromC"),
4947 v8::FunctionTemplate::New(CcTest::isolate(), ThrowFromC)); 4974 v8::FunctionTemplate::New(isolate, ThrowFromC));
4948 LocalContext context(0, templ); 4975 LocalContext context(0, templ);
4949 4976
4950 v8::TryCatch try_catch; 4977 v8::TryCatch try_catch;
4951 Local<Script> script 4978 Local<Script> script
4952 = Script::Compile(v8_str("ThrowFromC(); throw 'panama';")); 4979 = Script::Compile(v8_str("ThrowFromC(); throw 'panama';"));
4953 Local<Value> result = script->Run(); 4980 Local<Value> result = script->Run();
4954 CHECK(result.IsEmpty()); 4981 CHECK(result.IsEmpty());
4955 CHECK(try_catch.HasCaught()); 4982 CHECK(try_catch.HasCaught());
4956 String::Utf8Value exception_value(try_catch.Exception()); 4983 String::Utf8Value exception_value(try_catch.Exception());
4957 CHECK_EQ("konto", *exception_value); 4984 CHECK_EQ("konto", *exception_value);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
5041 // level. Stars identify activations with exception handlers, the @ identifies 5068 // level. Stars identify activations with exception handlers, the @ identifies
5042 // the exception handler that should catch the exception. 5069 // the exception handler that should catch the exception.
5043 // 5070 //
5044 // BUG(271): Some of the exception propagation does not work on the 5071 // BUG(271): Some of the exception propagation does not work on the
5045 // ARM simulator because the simulator separates the C++ stack and the 5072 // ARM simulator because the simulator separates the C++ stack and the
5046 // JS stack. This test therefore fails on the simulator. The test is 5073 // JS stack. This test therefore fails on the simulator. The test is
5047 // not threaded to allow the threading tests to run on the simulator. 5074 // not threaded to allow the threading tests to run on the simulator.
5048 TEST(ExceptionOrder) { 5075 TEST(ExceptionOrder) {
5049 v8::Isolate* isolate = CcTest::isolate(); 5076 v8::Isolate* isolate = CcTest::isolate();
5050 v8::HandleScope scope(isolate); 5077 v8::HandleScope scope(isolate);
5051 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5078 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5052 templ->Set(v8_str("check"), v8::FunctionTemplate::New(isolate, JSCheck)); 5079 templ->Set(v8_str("check"), v8::FunctionTemplate::New(isolate, JSCheck));
5053 templ->Set(v8_str("CThrowCountDown"), 5080 templ->Set(v8_str("CThrowCountDown"),
5054 v8::FunctionTemplate::New(isolate, CThrowCountDown)); 5081 v8::FunctionTemplate::New(isolate, CThrowCountDown));
5055 LocalContext context(0, templ); 5082 LocalContext context(0, templ);
5056 CompileRun( 5083 CompileRun(
5057 "function JSThrowCountDown(count, jsInterval, cInterval, expected) {" 5084 "function JSThrowCountDown(count, jsInterval, cInterval, expected) {"
5058 " if (count == 0) throw 'FromJS';" 5085 " if (count == 0) throw 'FromJS';"
5059 " if (count % jsInterval == 0) {" 5086 " if (count % jsInterval == 0) {"
5060 " try {" 5087 " try {"
5061 " var value = CThrowCountDown(count - 1," 5088 " var value = CThrowCountDown(count - 1,"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
5106 void ThrowValue(const v8::FunctionCallbackInfo<v8::Value>& args) { 5133 void ThrowValue(const v8::FunctionCallbackInfo<v8::Value>& args) {
5107 ApiTestFuzzer::Fuzz(); 5134 ApiTestFuzzer::Fuzz();
5108 CHECK_EQ(1, args.Length()); 5135 CHECK_EQ(1, args.Length());
5109 args.GetIsolate()->ThrowException(args[0]); 5136 args.GetIsolate()->ThrowException(args[0]);
5110 } 5137 }
5111 5138
5112 5139
5113 THREADED_TEST(ThrowValues) { 5140 THREADED_TEST(ThrowValues) {
5114 v8::Isolate* isolate = CcTest::isolate(); 5141 v8::Isolate* isolate = CcTest::isolate();
5115 v8::HandleScope scope(isolate); 5142 v8::HandleScope scope(isolate);
5116 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5143 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5117 templ->Set(v8_str("Throw"), v8::FunctionTemplate::New(isolate, ThrowValue)); 5144 templ->Set(v8_str("Throw"), v8::FunctionTemplate::New(isolate, ThrowValue));
5118 LocalContext context(0, templ); 5145 LocalContext context(0, templ);
5119 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( 5146 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun(
5120 "function Run(obj) {" 5147 "function Run(obj) {"
5121 " try {" 5148 " try {"
5122 " Throw(obj);" 5149 " Throw(obj);"
5123 " } catch (e) {" 5150 " } catch (e) {"
5124 " return e;" 5151 " return e;"
5125 " }" 5152 " }"
5126 " return 'no exception';" 5153 " return 'no exception';"
5127 "}" 5154 "}"
5128 "[Run('str'), Run(1), Run(0), Run(null), Run(void 0)];")); 5155 "[Run('str'), Run(1), Run(0), Run(null), Run(void 0)];"));
5129 CHECK_EQ(5, result->Length()); 5156 CHECK_EQ(5, result->Length());
5130 CHECK(result->Get(v8::Integer::New(0))->IsString()); 5157 CHECK(result->Get(v8::Integer::New(isolate, 0))->IsString());
5131 CHECK(result->Get(v8::Integer::New(1))->IsNumber()); 5158 CHECK(result->Get(v8::Integer::New(isolate, 1))->IsNumber());
5132 CHECK_EQ(1, result->Get(v8::Integer::New(1))->Int32Value()); 5159 CHECK_EQ(1, result->Get(v8::Integer::New(isolate, 1))->Int32Value());
5133 CHECK(result->Get(v8::Integer::New(2))->IsNumber()); 5160 CHECK(result->Get(v8::Integer::New(isolate, 2))->IsNumber());
5134 CHECK_EQ(0, result->Get(v8::Integer::New(2))->Int32Value()); 5161 CHECK_EQ(0, result->Get(v8::Integer::New(isolate, 2))->Int32Value());
5135 CHECK(result->Get(v8::Integer::New(3))->IsNull()); 5162 CHECK(result->Get(v8::Integer::New(isolate, 3))->IsNull());
5136 CHECK(result->Get(v8::Integer::New(4))->IsUndefined()); 5163 CHECK(result->Get(v8::Integer::New(isolate, 4))->IsUndefined());
5137 } 5164 }
5138 5165
5139 5166
5140 THREADED_TEST(CatchZero) { 5167 THREADED_TEST(CatchZero) {
5141 LocalContext context; 5168 LocalContext context;
5142 v8::HandleScope scope(context->GetIsolate()); 5169 v8::HandleScope scope(context->GetIsolate());
5143 v8::TryCatch try_catch; 5170 v8::TryCatch try_catch;
5144 CHECK(!try_catch.HasCaught()); 5171 CHECK(!try_catch.HasCaught());
5145 Script::Compile(v8_str("throw 10"))->Run(); 5172 Script::Compile(v8_str("throw 10"))->Run();
5146 CHECK(try_catch.HasCaught()); 5173 CHECK(try_catch.HasCaught());
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
5248 // This test ensures that an outer TryCatch in the following situation: 5275 // This test ensures that an outer TryCatch in the following situation:
5249 // C++/TryCatch -> JS -> C++/TryCatch -> JS w/ SyntaxError 5276 // C++/TryCatch -> JS -> C++/TryCatch -> JS w/ SyntaxError
5250 // does not clobber the Message object generated for the inner TryCatch. 5277 // does not clobber the Message object generated for the inner TryCatch.
5251 // This exercises the ability of TryCatch.ReThrow() to restore the 5278 // This exercises the ability of TryCatch.ReThrow() to restore the
5252 // inner pending Message before throwing the exception again. 5279 // inner pending Message before throwing the exception again.
5253 TEST(TryCatchMixedNesting) { 5280 TEST(TryCatchMixedNesting) {
5254 v8::Isolate* isolate = CcTest::isolate(); 5281 v8::Isolate* isolate = CcTest::isolate();
5255 v8::HandleScope scope(isolate); 5282 v8::HandleScope scope(isolate);
5256 v8::V8::Initialize(); 5283 v8::V8::Initialize();
5257 v8::TryCatch try_catch; 5284 v8::TryCatch try_catch;
5258 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5285 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5259 templ->Set(v8_str("TryCatchMixedNestingHelper"), 5286 templ->Set(v8_str("TryCatchMixedNestingHelper"),
5260 v8::FunctionTemplate::New(isolate, TryCatchMixedNestingHelper)); 5287 v8::FunctionTemplate::New(isolate, TryCatchMixedNestingHelper));
5261 LocalContext context(0, templ); 5288 LocalContext context(0, templ);
5262 CompileRunWithOrigin("TryCatchMixedNestingHelper();\n", "outer", 1, 1); 5289 CompileRunWithOrigin("TryCatchMixedNestingHelper();\n", "outer", 1, 1);
5263 TryCatchMixedNestingCheck(&try_catch); 5290 TryCatchMixedNestingCheck(&try_catch);
5264 } 5291 }
5265 5292
5266 5293
5267 THREADED_TEST(Equality) { 5294 THREADED_TEST(Equality) {
5268 LocalContext context; 5295 LocalContext context;
(...skipping 14 matching lines...) Expand all
5283 CHECK(!v8_str("a")->StrictEquals(v8_str("b"))); 5310 CHECK(!v8_str("a")->StrictEquals(v8_str("b")));
5284 CHECK(!v8_str("5")->StrictEquals(v8_num(5))); 5311 CHECK(!v8_str("5")->StrictEquals(v8_num(5)));
5285 CHECK(v8_num(1)->StrictEquals(v8_num(1))); 5312 CHECK(v8_num(1)->StrictEquals(v8_num(1)));
5286 CHECK(!v8_num(1)->StrictEquals(v8_num(2))); 5313 CHECK(!v8_num(1)->StrictEquals(v8_num(2)));
5287 CHECK(v8_num(0.0)->StrictEquals(v8_num(-0.0))); 5314 CHECK(v8_num(0.0)->StrictEquals(v8_num(-0.0)));
5288 Local<Value> not_a_number = v8_num(i::OS::nan_value()); 5315 Local<Value> not_a_number = v8_num(i::OS::nan_value());
5289 CHECK(!not_a_number->StrictEquals(not_a_number)); 5316 CHECK(!not_a_number->StrictEquals(not_a_number));
5290 CHECK(v8::False(isolate)->StrictEquals(v8::False(isolate))); 5317 CHECK(v8::False(isolate)->StrictEquals(v8::False(isolate)));
5291 CHECK(!v8::False(isolate)->StrictEquals(v8::Undefined(isolate))); 5318 CHECK(!v8::False(isolate)->StrictEquals(v8::Undefined(isolate)));
5292 5319
5293 v8::Handle<v8::Object> obj = v8::Object::New(); 5320 v8::Handle<v8::Object> obj = v8::Object::New(isolate);
5294 v8::Persistent<v8::Object> alias(isolate, obj); 5321 v8::Persistent<v8::Object> alias(isolate, obj);
5295 CHECK(v8::Local<v8::Object>::New(isolate, alias)->StrictEquals(obj)); 5322 CHECK(v8::Local<v8::Object>::New(isolate, alias)->StrictEquals(obj));
5296 alias.Reset(); 5323 alias.Reset();
5297 5324
5298 CHECK(v8_str("a")->SameValue(v8_str("a"))); 5325 CHECK(v8_str("a")->SameValue(v8_str("a")));
5299 CHECK(!v8_str("a")->SameValue(v8_str("b"))); 5326 CHECK(!v8_str("a")->SameValue(v8_str("b")));
5300 CHECK(!v8_str("5")->SameValue(v8_num(5))); 5327 CHECK(!v8_str("5")->SameValue(v8_num(5)));
5301 CHECK(v8_num(1)->SameValue(v8_num(1))); 5328 CHECK(v8_num(1)->SameValue(v8_num(1)));
5302 CHECK(!v8_num(1)->SameValue(v8_num(2))); 5329 CHECK(!v8_num(1)->SameValue(v8_num(2)));
5303 CHECK(!v8_num(0.0)->SameValue(v8_num(-0.0))); 5330 CHECK(!v8_num(0.0)->SameValue(v8_num(-0.0)));
(...skipping 16 matching lines...) Expand all
5320 const v8::PropertyCallbackInfo<v8::Value>& info) { 5347 const v8::PropertyCallbackInfo<v8::Value>& info) {
5321 ApiTestFuzzer::Fuzz(); 5348 ApiTestFuzzer::Fuzz();
5322 CHECK_EQ(info.Data(), v8_str("donut")); 5349 CHECK_EQ(info.Data(), v8_str("donut"));
5323 CHECK_EQ(name, v8_str("x")); 5350 CHECK_EQ(name, v8_str("x"));
5324 info.GetReturnValue().Set(name); 5351 info.GetReturnValue().Set(name);
5325 } 5352 }
5326 5353
5327 5354
5328 THREADED_TEST(SimplePropertyRead) { 5355 THREADED_TEST(SimplePropertyRead) {
5329 LocalContext context; 5356 LocalContext context;
5330 v8::HandleScope scope(context->GetIsolate()); 5357 v8::Isolate* isolate = context->GetIsolate();
5331 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5358 v8::HandleScope scope(isolate);
5359 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5332 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); 5360 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"));
5333 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 5361 context->Global()->Set(v8_str("obj"), templ->NewInstance());
5334 Local<Script> script = Script::Compile(v8_str("obj.x")); 5362 Local<Script> script = Script::Compile(v8_str("obj.x"));
5335 for (int i = 0; i < 10; i++) { 5363 for (int i = 0; i < 10; i++) {
5336 Local<Value> result = script->Run(); 5364 Local<Value> result = script->Run();
5337 CHECK_EQ(result, v8_str("x")); 5365 CHECK_EQ(result, v8_str("x"));
5338 } 5366 }
5339 } 5367 }
5340 5368
5341 5369
5342 THREADED_TEST(DefinePropertyOnAPIAccessor) { 5370 THREADED_TEST(DefinePropertyOnAPIAccessor) {
5343 LocalContext context; 5371 LocalContext context;
5344 v8::HandleScope scope(context->GetIsolate()); 5372 v8::Isolate* isolate = context->GetIsolate();
5345 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5373 v8::HandleScope scope(isolate);
5374 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5346 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); 5375 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"));
5347 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 5376 context->Global()->Set(v8_str("obj"), templ->NewInstance());
5348 5377
5349 // Uses getOwnPropertyDescriptor to check the configurable status 5378 // Uses getOwnPropertyDescriptor to check the configurable status
5350 Local<Script> script_desc 5379 Local<Script> script_desc
5351 = Script::Compile(v8_str("var prop = Object.getOwnPropertyDescriptor( " 5380 = Script::Compile(v8_str("var prop = Object.getOwnPropertyDescriptor( "
5352 "obj, 'x');" 5381 "obj, 'x');"
5353 "prop.configurable;")); 5382 "prop.configurable;"));
5354 Local<Value> result = script_desc->Run(); 5383 Local<Value> result = script_desc->Run();
5355 CHECK_EQ(result->BooleanValue(), true); 5384 CHECK_EQ(result->BooleanValue(), true);
(...skipping 25 matching lines...) Expand all
5381 // Make sure that it is not possible to redefine again 5410 // Make sure that it is not possible to redefine again
5382 v8::TryCatch try_catch; 5411 v8::TryCatch try_catch;
5383 result = script_define->Run(); 5412 result = script_define->Run();
5384 CHECK(try_catch.HasCaught()); 5413 CHECK(try_catch.HasCaught());
5385 String::Utf8Value exception_value(try_catch.Exception()); 5414 String::Utf8Value exception_value(try_catch.Exception());
5386 CHECK_EQ(*exception_value, "TypeError: Cannot redefine property: x"); 5415 CHECK_EQ(*exception_value, "TypeError: Cannot redefine property: x");
5387 } 5416 }
5388 5417
5389 5418
5390 THREADED_TEST(DefinePropertyOnDefineGetterSetter) { 5419 THREADED_TEST(DefinePropertyOnDefineGetterSetter) {
5391 v8::HandleScope scope(CcTest::isolate()); 5420 v8::Isolate* isolate = CcTest::isolate();
5392 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5421 v8::HandleScope scope(isolate);
5422 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5393 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); 5423 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"));
5394 LocalContext context; 5424 LocalContext context;
5395 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 5425 context->Global()->Set(v8_str("obj"), templ->NewInstance());
5396 5426
5397 Local<Script> script_desc = Script::Compile(v8_str("var prop =" 5427 Local<Script> script_desc = Script::Compile(v8_str("var prop ="
5398 "Object.getOwnPropertyDescriptor( " 5428 "Object.getOwnPropertyDescriptor( "
5399 "obj, 'x');" 5429 "obj, 'x');"
5400 "prop.configurable;")); 5430 "prop.configurable;"));
5401 Local<Value> result = script_desc->Run(); 5431 Local<Value> result = script_desc->Run();
5402 CHECK_EQ(result->BooleanValue(), true); 5432 CHECK_EQ(result->BooleanValue(), true);
(...skipping 30 matching lines...) Expand all
5433 } 5463 }
5434 5464
5435 5465
5436 static v8::Handle<v8::Object> GetGlobalProperty(LocalContext* context, 5466 static v8::Handle<v8::Object> GetGlobalProperty(LocalContext* context,
5437 char const* name) { 5467 char const* name) {
5438 return v8::Handle<v8::Object>::Cast((*context)->Global()->Get(v8_str(name))); 5468 return v8::Handle<v8::Object>::Cast((*context)->Global()->Get(v8_str(name)));
5439 } 5469 }
5440 5470
5441 5471
5442 THREADED_TEST(DefineAPIAccessorOnObject) { 5472 THREADED_TEST(DefineAPIAccessorOnObject) {
5443 v8::HandleScope scope(CcTest::isolate()); 5473 v8::Isolate* isolate = CcTest::isolate();
5444 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5474 v8::HandleScope scope(isolate);
5475 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5445 LocalContext context; 5476 LocalContext context;
5446 5477
5447 context->Global()->Set(v8_str("obj1"), templ->NewInstance()); 5478 context->Global()->Set(v8_str("obj1"), templ->NewInstance());
5448 CompileRun("var obj2 = {};"); 5479 CompileRun("var obj2 = {};");
5449 5480
5450 CHECK(CompileRun("obj1.x")->IsUndefined()); 5481 CHECK(CompileRun("obj1.x")->IsUndefined());
5451 CHECK(CompileRun("obj2.x")->IsUndefined()); 5482 CHECK(CompileRun("obj2.x")->IsUndefined());
5452 5483
5453 CHECK(GetGlobalProperty(&context, "obj1")-> 5484 CHECK(GetGlobalProperty(&context, "obj1")->
5454 SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"))); 5485 SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")));
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
5507 SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"))); 5538 SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")));
5508 CHECK(!GetGlobalProperty(&context, "obj2")-> 5539 CHECK(!GetGlobalProperty(&context, "obj2")->
5509 SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"))); 5540 SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")));
5510 5541
5511 ExpectString("obj1.x", "z"); 5542 ExpectString("obj1.x", "z");
5512 ExpectString("obj2.x", "z"); 5543 ExpectString("obj2.x", "z");
5513 } 5544 }
5514 5545
5515 5546
5516 THREADED_TEST(DontDeleteAPIAccessorsCannotBeOverriden) { 5547 THREADED_TEST(DontDeleteAPIAccessorsCannotBeOverriden) {
5517 v8::HandleScope scope(CcTest::isolate()); 5548 v8::Isolate* isolate = CcTest::isolate();
5518 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5549 v8::HandleScope scope(isolate);
5550 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5519 LocalContext context; 5551 LocalContext context;
5520 5552
5521 context->Global()->Set(v8_str("obj1"), templ->NewInstance()); 5553 context->Global()->Set(v8_str("obj1"), templ->NewInstance());
5522 CompileRun("var obj2 = {};"); 5554 CompileRun("var obj2 = {};");
5523 5555
5524 CHECK(GetGlobalProperty(&context, "obj1")->SetAccessor( 5556 CHECK(GetGlobalProperty(&context, "obj1")->SetAccessor(
5525 v8_str("x"), 5557 v8_str("x"),
5526 GetXValue, NULL, 5558 GetXValue, NULL,
5527 v8_str("donut"), v8::DEFAULT, v8::DontDelete)); 5559 v8_str("donut"), v8::DEFAULT, v8::DontDelete));
5528 CHECK(GetGlobalProperty(&context, "obj2")->SetAccessor( 5560 CHECK(GetGlobalProperty(&context, "obj2")->SetAccessor(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
5563 static void Get239Value(Local<String> name, 5595 static void Get239Value(Local<String> name,
5564 const v8::PropertyCallbackInfo<v8::Value>& info) { 5596 const v8::PropertyCallbackInfo<v8::Value>& info) {
5565 ApiTestFuzzer::Fuzz(); 5597 ApiTestFuzzer::Fuzz();
5566 CHECK_EQ(info.Data(), v8_str("donut")); 5598 CHECK_EQ(info.Data(), v8_str("donut"));
5567 CHECK_EQ(name, v8_str("239")); 5599 CHECK_EQ(name, v8_str("239"));
5568 info.GetReturnValue().Set(name); 5600 info.GetReturnValue().Set(name);
5569 } 5601 }
5570 5602
5571 5603
5572 THREADED_TEST(ElementAPIAccessor) { 5604 THREADED_TEST(ElementAPIAccessor) {
5573 v8::HandleScope scope(CcTest::isolate()); 5605 v8::Isolate* isolate = CcTest::isolate();
5574 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5606 v8::HandleScope scope(isolate);
5607 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5575 LocalContext context; 5608 LocalContext context;
5576 5609
5577 context->Global()->Set(v8_str("obj1"), templ->NewInstance()); 5610 context->Global()->Set(v8_str("obj1"), templ->NewInstance());
5578 CompileRun("var obj2 = {};"); 5611 CompileRun("var obj2 = {};");
5579 5612
5580 CHECK(GetGlobalProperty(&context, "obj1")->SetAccessor( 5613 CHECK(GetGlobalProperty(&context, "obj1")->SetAccessor(
5581 v8_str("239"), 5614 v8_str("239"),
5582 Get239Value, NULL, 5615 Get239Value, NULL,
5583 v8_str("donut"))); 5616 v8_str("donut")));
5584 CHECK(GetGlobalProperty(&context, "obj2")->SetAccessor( 5617 CHECK(GetGlobalProperty(&context, "obj2")->SetAccessor(
(...skipping 16 matching lines...) Expand all
5601 const v8::PropertyCallbackInfo<void>& info) { 5634 const v8::PropertyCallbackInfo<void>& info) {
5602 CHECK_EQ(value, v8_num(4)); 5635 CHECK_EQ(value, v8_num(4));
5603 CHECK_EQ(info.Data(), v8_str("donut")); 5636 CHECK_EQ(info.Data(), v8_str("donut"));
5604 CHECK_EQ(name, v8_str("x")); 5637 CHECK_EQ(name, v8_str("x"));
5605 CHECK(xValue.IsEmpty()); 5638 CHECK(xValue.IsEmpty());
5606 xValue.Reset(info.GetIsolate(), value); 5639 xValue.Reset(info.GetIsolate(), value);
5607 } 5640 }
5608 5641
5609 5642
5610 THREADED_TEST(SimplePropertyWrite) { 5643 THREADED_TEST(SimplePropertyWrite) {
5611 v8::HandleScope scope(CcTest::isolate()); 5644 v8::Isolate* isolate = CcTest::isolate();
5612 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5645 v8::HandleScope scope(isolate);
5646 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5613 templ->SetAccessor(v8_str("x"), GetXValue, SetXValue, v8_str("donut")); 5647 templ->SetAccessor(v8_str("x"), GetXValue, SetXValue, v8_str("donut"));
5614 LocalContext context; 5648 LocalContext context;
5615 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 5649 context->Global()->Set(v8_str("obj"), templ->NewInstance());
5616 Local<Script> script = Script::Compile(v8_str("obj.x = 4")); 5650 Local<Script> script = Script::Compile(v8_str("obj.x = 4"));
5617 for (int i = 0; i < 10; i++) { 5651 for (int i = 0; i < 10; i++) {
5618 CHECK(xValue.IsEmpty()); 5652 CHECK(xValue.IsEmpty());
5619 script->Run(); 5653 script->Run();
5620 CHECK_EQ(v8_num(4), Local<Value>::New(CcTest::isolate(), xValue)); 5654 CHECK_EQ(v8_num(4), Local<Value>::New(CcTest::isolate(), xValue));
5621 xValue.Reset(); 5655 xValue.Reset();
5622 } 5656 }
5623 } 5657 }
5624 5658
5625 5659
5626 THREADED_TEST(SetterOnly) { 5660 THREADED_TEST(SetterOnly) {
5627 v8::HandleScope scope(CcTest::isolate()); 5661 v8::Isolate* isolate = CcTest::isolate();
5628 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5662 v8::HandleScope scope(isolate);
5663 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5629 templ->SetAccessor(v8_str("x"), NULL, SetXValue, v8_str("donut")); 5664 templ->SetAccessor(v8_str("x"), NULL, SetXValue, v8_str("donut"));
5630 LocalContext context; 5665 LocalContext context;
5631 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 5666 context->Global()->Set(v8_str("obj"), templ->NewInstance());
5632 Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x")); 5667 Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x"));
5633 for (int i = 0; i < 10; i++) { 5668 for (int i = 0; i < 10; i++) {
5634 CHECK(xValue.IsEmpty()); 5669 CHECK(xValue.IsEmpty());
5635 script->Run(); 5670 script->Run();
5636 CHECK_EQ(v8_num(4), Local<Value>::New(CcTest::isolate(), xValue)); 5671 CHECK_EQ(v8_num(4), Local<Value>::New(CcTest::isolate(), xValue));
5637 xValue.Reset(); 5672 xValue.Reset();
5638 } 5673 }
5639 } 5674 }
5640 5675
5641 5676
5642 THREADED_TEST(NoAccessors) { 5677 THREADED_TEST(NoAccessors) {
5643 v8::HandleScope scope(CcTest::isolate()); 5678 v8::Isolate* isolate = CcTest::isolate();
5644 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5679 v8::HandleScope scope(isolate);
5680 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5645 templ->SetAccessor(v8_str("x"), 5681 templ->SetAccessor(v8_str("x"),
5646 static_cast<v8::AccessorGetterCallback>(NULL), 5682 static_cast<v8::AccessorGetterCallback>(NULL),
5647 NULL, 5683 NULL,
5648 v8_str("donut")); 5684 v8_str("donut"));
5649 LocalContext context; 5685 LocalContext context;
5650 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 5686 context->Global()->Set(v8_str("obj"), templ->NewInstance());
5651 Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x")); 5687 Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x"));
5652 for (int i = 0; i < 10; i++) { 5688 for (int i = 0; i < 10; i++) {
5653 script->Run(); 5689 script->Run();
5654 } 5690 }
5655 } 5691 }
5656 5692
5657 5693
5658 static void XPropertyGetter(Local<String> property, 5694 static void XPropertyGetter(Local<String> property,
5659 const v8::PropertyCallbackInfo<v8::Value>& info) { 5695 const v8::PropertyCallbackInfo<v8::Value>& info) {
5660 ApiTestFuzzer::Fuzz(); 5696 ApiTestFuzzer::Fuzz();
5661 CHECK(info.Data()->IsUndefined()); 5697 CHECK(info.Data()->IsUndefined());
5662 info.GetReturnValue().Set(property); 5698 info.GetReturnValue().Set(property);
5663 } 5699 }
5664 5700
5665 5701
5666 THREADED_TEST(NamedInterceptorPropertyRead) { 5702 THREADED_TEST(NamedInterceptorPropertyRead) {
5667 v8::HandleScope scope(CcTest::isolate()); 5703 v8::Isolate* isolate = CcTest::isolate();
5668 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5704 v8::HandleScope scope(isolate);
5705 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5669 templ->SetNamedPropertyHandler(XPropertyGetter); 5706 templ->SetNamedPropertyHandler(XPropertyGetter);
5670 LocalContext context; 5707 LocalContext context;
5671 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 5708 context->Global()->Set(v8_str("obj"), templ->NewInstance());
5672 Local<Script> script = Script::Compile(v8_str("obj.x")); 5709 Local<Script> script = Script::Compile(v8_str("obj.x"));
5673 for (int i = 0; i < 10; i++) { 5710 for (int i = 0; i < 10; i++) {
5674 Local<Value> result = script->Run(); 5711 Local<Value> result = script->Run();
5675 CHECK_EQ(result, v8_str("x")); 5712 CHECK_EQ(result, v8_str("x"));
5676 } 5713 }
5677 } 5714 }
5678 5715
5679 5716
5680 THREADED_TEST(NamedInterceptorDictionaryIC) { 5717 THREADED_TEST(NamedInterceptorDictionaryIC) {
5681 v8::HandleScope scope(CcTest::isolate()); 5718 v8::Isolate* isolate = CcTest::isolate();
5682 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5719 v8::HandleScope scope(isolate);
5720 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5683 templ->SetNamedPropertyHandler(XPropertyGetter); 5721 templ->SetNamedPropertyHandler(XPropertyGetter);
5684 LocalContext context; 5722 LocalContext context;
5685 // Create an object with a named interceptor. 5723 // Create an object with a named interceptor.
5686 context->Global()->Set(v8_str("interceptor_obj"), templ->NewInstance()); 5724 context->Global()->Set(v8_str("interceptor_obj"), templ->NewInstance());
5687 Local<Script> script = Script::Compile(v8_str("interceptor_obj.x")); 5725 Local<Script> script = Script::Compile(v8_str("interceptor_obj.x"));
5688 for (int i = 0; i < 10; i++) { 5726 for (int i = 0; i < 10; i++) {
5689 Local<Value> result = script->Run(); 5727 Local<Value> result = script->Run();
5690 CHECK_EQ(result, v8_str("x")); 5728 CHECK_EQ(result, v8_str("x"));
5691 } 5729 }
5692 // Create a slow case object and a function accessing a property in 5730 // Create a slow case object and a function accessing a property in
(...skipping 13 matching lines...) Expand all
5706 CHECK_EQ(result, v8_str("x")); 5744 CHECK_EQ(result, v8_str("x"));
5707 } 5745 }
5708 5746
5709 5747
5710 THREADED_TEST(NamedInterceptorDictionaryICMultipleContext) { 5748 THREADED_TEST(NamedInterceptorDictionaryICMultipleContext) {
5711 v8::Isolate* isolate = CcTest::isolate(); 5749 v8::Isolate* isolate = CcTest::isolate();
5712 v8::HandleScope scope(isolate); 5750 v8::HandleScope scope(isolate);
5713 v8::Local<Context> context1 = Context::New(isolate); 5751 v8::Local<Context> context1 = Context::New(isolate);
5714 5752
5715 context1->Enter(); 5753 context1->Enter();
5716 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5754 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5717 templ->SetNamedPropertyHandler(XPropertyGetter); 5755 templ->SetNamedPropertyHandler(XPropertyGetter);
5718 // Create an object with a named interceptor. 5756 // Create an object with a named interceptor.
5719 v8::Local<v8::Object> object = templ->NewInstance(); 5757 v8::Local<v8::Object> object = templ->NewInstance();
5720 context1->Global()->Set(v8_str("interceptor_obj"), object); 5758 context1->Global()->Set(v8_str("interceptor_obj"), object);
5721 5759
5722 // Force the object into the slow case. 5760 // Force the object into the slow case.
5723 CompileRun("interceptor_obj.y = 0;" 5761 CompileRun("interceptor_obj.y = 0;"
5724 "delete interceptor_obj.y;"); 5762 "delete interceptor_obj.y;");
5725 context1->Exit(); 5763 context1->Exit();
5726 5764
(...skipping 19 matching lines...) Expand all
5746 CompileRun("var obj = { x : 0 }; delete obj.x;"); 5784 CompileRun("var obj = { x : 0 }; delete obj.x;");
5747 context1->Exit(); 5785 context1->Exit();
5748 } 5786 }
5749 5787
5750 5788
5751 static void SetXOnPrototypeGetter( 5789 static void SetXOnPrototypeGetter(
5752 Local<String> property, 5790 Local<String> property,
5753 const v8::PropertyCallbackInfo<v8::Value>& info) { 5791 const v8::PropertyCallbackInfo<v8::Value>& info) {
5754 // Set x on the prototype object and do not handle the get request. 5792 // Set x on the prototype object and do not handle the get request.
5755 v8::Handle<v8::Value> proto = info.Holder()->GetPrototype(); 5793 v8::Handle<v8::Value> proto = info.Holder()->GetPrototype();
5756 proto.As<v8::Object>()->Set(v8_str("x"), v8::Integer::New(23)); 5794 proto.As<v8::Object>()->Set(v8_str("x"),
5795 v8::Integer::New(info.GetIsolate(), 23));
5757 } 5796 }
5758 5797
5759 5798
5760 // This is a regression test for http://crbug.com/20104. Map 5799 // This is a regression test for http://crbug.com/20104. Map
5761 // transitions should not interfere with post interceptor lookup. 5800 // transitions should not interfere with post interceptor lookup.
5762 THREADED_TEST(NamedInterceptorMapTransitionRead) { 5801 THREADED_TEST(NamedInterceptorMapTransitionRead) {
5763 v8::Isolate* isolate = CcTest::isolate(); 5802 v8::Isolate* isolate = CcTest::isolate();
5764 v8::HandleScope scope(isolate); 5803 v8::HandleScope scope(isolate);
5765 Local<v8::FunctionTemplate> function_template = 5804 Local<v8::FunctionTemplate> function_template =
5766 v8::FunctionTemplate::New(isolate); 5805 v8::FunctionTemplate::New(isolate);
(...skipping 25 matching lines...) Expand all
5792 Local<Value> value, 5831 Local<Value> value,
5793 const v8::PropertyCallbackInfo<v8::Value>& info) { 5832 const v8::PropertyCallbackInfo<v8::Value>& info) {
5794 ApiTestFuzzer::Fuzz(); 5833 ApiTestFuzzer::Fuzz();
5795 if (index == 39) { 5834 if (index == 39) {
5796 info.GetReturnValue().Set(value); 5835 info.GetReturnValue().Set(value);
5797 } 5836 }
5798 } 5837 }
5799 5838
5800 5839
5801 THREADED_TEST(IndexedInterceptorWithIndexedAccessor) { 5840 THREADED_TEST(IndexedInterceptorWithIndexedAccessor) {
5802 v8::HandleScope scope(CcTest::isolate()); 5841 v8::Isolate* isolate = CcTest::isolate();
5803 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5842 v8::HandleScope scope(isolate);
5843 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5804 templ->SetIndexedPropertyHandler(IndexedPropertyGetter, 5844 templ->SetIndexedPropertyHandler(IndexedPropertyGetter,
5805 IndexedPropertySetter); 5845 IndexedPropertySetter);
5806 LocalContext context; 5846 LocalContext context;
5807 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 5847 context->Global()->Set(v8_str("obj"), templ->NewInstance());
5808 Local<Script> getter_script = Script::Compile(v8_str( 5848 Local<Script> getter_script = Script::Compile(v8_str(
5809 "obj.__defineGetter__(\"3\", function(){return 5;});obj[3];")); 5849 "obj.__defineGetter__(\"3\", function(){return 5;});obj[3];"));
5810 Local<Script> setter_script = Script::Compile(v8_str( 5850 Local<Script> setter_script = Script::Compile(v8_str(
5811 "obj.__defineSetter__(\"17\", function(val){this.foo = val;});" 5851 "obj.__defineSetter__(\"17\", function(val){this.foo = val;});"
5812 "obj[17] = 23;" 5852 "obj[17] = 23;"
5813 "obj.foo;")); 5853 "obj.foo;"));
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
5857 "for(i = 0; i < 80000; i++) { keys[i] = i; };" 5897 "for(i = 0; i < 80000; i++) { keys[i] = i; };"
5858 "keys.length = 25; keys;")); 5898 "keys.length = 25; keys;"));
5859 Local<Value> result = indexed_property_names_script->Run(); 5899 Local<Value> result = indexed_property_names_script->Run();
5860 info.GetReturnValue().Set(Local<v8::Array>::Cast(result)); 5900 info.GetReturnValue().Set(Local<v8::Array>::Cast(result));
5861 } 5901 }
5862 5902
5863 5903
5864 // Make sure that the the interceptor code in the runtime properly handles 5904 // Make sure that the the interceptor code in the runtime properly handles
5865 // merging property name lists for double-array-backed arrays. 5905 // merging property name lists for double-array-backed arrays.
5866 THREADED_TEST(IndexedInterceptorUnboxedDoubleWithIndexedAccessor) { 5906 THREADED_TEST(IndexedInterceptorUnboxedDoubleWithIndexedAccessor) {
5867 v8::HandleScope scope(CcTest::isolate()); 5907 v8::Isolate* isolate = CcTest::isolate();
5868 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5908 v8::HandleScope scope(isolate);
5909 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5869 templ->SetIndexedPropertyHandler(UnboxedDoubleIndexedPropertyGetter, 5910 templ->SetIndexedPropertyHandler(UnboxedDoubleIndexedPropertyGetter,
5870 UnboxedDoubleIndexedPropertySetter, 5911 UnboxedDoubleIndexedPropertySetter,
5871 0, 5912 0,
5872 0, 5913 0,
5873 UnboxedDoubleIndexedPropertyEnumerator); 5914 UnboxedDoubleIndexedPropertyEnumerator);
5874 LocalContext context; 5915 LocalContext context;
5875 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 5916 context->Global()->Set(v8_str("obj"), templ->NewInstance());
5876 // When obj is created, force it to be Stored in a FastDoubleArray. 5917 // When obj is created, force it to be Stored in a FastDoubleArray.
5877 Local<Script> create_unboxed_double_script = Script::Compile(v8_str( 5918 Local<Script> create_unboxed_double_script = Script::Compile(v8_str(
5878 "obj[125000] = 1; for(i = 0; i < 80000; i+=2) { obj[i] = i; } " 5919 "obj[125000] = 1; for(i = 0; i < 80000; i+=2) { obj[i] = i; } "
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
5913 ApiTestFuzzer::Fuzz(); 5954 ApiTestFuzzer::Fuzz();
5914 if (index < 4) { 5955 if (index < 4) {
5915 info.GetReturnValue().Set(v8_num(index)); 5956 info.GetReturnValue().Set(v8_num(index));
5916 } 5957 }
5917 } 5958 }
5918 5959
5919 5960
5920 // Make sure that the the interceptor code in the runtime properly handles 5961 // Make sure that the the interceptor code in the runtime properly handles
5921 // merging property name lists for non-string arguments arrays. 5962 // merging property name lists for non-string arguments arrays.
5922 THREADED_TEST(IndexedInterceptorNonStrictArgsWithIndexedAccessor) { 5963 THREADED_TEST(IndexedInterceptorNonStrictArgsWithIndexedAccessor) {
5923 v8::HandleScope scope(CcTest::isolate()); 5964 v8::Isolate* isolate = CcTest::isolate();
5924 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5965 v8::HandleScope scope(isolate);
5966 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5925 templ->SetIndexedPropertyHandler(NonStrictIndexedPropertyGetter, 5967 templ->SetIndexedPropertyHandler(NonStrictIndexedPropertyGetter,
5926 0, 5968 0,
5927 0, 5969 0,
5928 0, 5970 0,
5929 NonStrictArgsIndexedPropertyEnumerator); 5971 NonStrictArgsIndexedPropertyEnumerator);
5930 LocalContext context; 5972 LocalContext context;
5931 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 5973 context->Global()->Set(v8_str("obj"), templ->NewInstance());
5932 Local<Script> create_args_script = 5974 Local<Script> create_args_script =
5933 Script::Compile(v8_str( 5975 Script::Compile(v8_str(
5934 "var key_count = 0;" 5976 "var key_count = 0;"
5935 "for (x in obj) {key_count++;} key_count;")); 5977 "for (x in obj) {key_count++;} key_count;"));
5936 Local<Value> result = create_args_script->Run(); 5978 Local<Value> result = create_args_script->Run();
5937 CHECK_EQ(v8_num(4), result); 5979 CHECK_EQ(v8_num(4), result);
5938 } 5980 }
5939 5981
5940 5982
5941 static void IdentityIndexedPropertyGetter( 5983 static void IdentityIndexedPropertyGetter(
5942 uint32_t index, 5984 uint32_t index,
5943 const v8::PropertyCallbackInfo<v8::Value>& info) { 5985 const v8::PropertyCallbackInfo<v8::Value>& info) {
5944 info.GetReturnValue().Set(index); 5986 info.GetReturnValue().Set(index);
5945 } 5987 }
5946 5988
5947 5989
5948 THREADED_TEST(IndexedInterceptorWithGetOwnPropertyDescriptor) { 5990 THREADED_TEST(IndexedInterceptorWithGetOwnPropertyDescriptor) {
5949 v8::HandleScope scope(CcTest::isolate()); 5991 v8::Isolate* isolate = CcTest::isolate();
5950 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5992 v8::HandleScope scope(isolate);
5993 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5951 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); 5994 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
5952 5995
5953 LocalContext context; 5996 LocalContext context;
5954 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 5997 context->Global()->Set(v8_str("obj"), templ->NewInstance());
5955 5998
5956 // Check fast object case. 5999 // Check fast object case.
5957 const char* fast_case_code = 6000 const char* fast_case_code =
5958 "Object.getOwnPropertyDescriptor(obj, 0).value.toString()"; 6001 "Object.getOwnPropertyDescriptor(obj, 0).value.toString()";
5959 ExpectString(fast_case_code, "0"); 6002 ExpectString(fast_case_code, "0");
5960 6003
5961 // Check slow case. 6004 // Check slow case.
5962 const char* slow_case_code = 6005 const char* slow_case_code =
5963 "obj.x = 1; delete obj.x;" 6006 "obj.x = 1; delete obj.x;"
5964 "Object.getOwnPropertyDescriptor(obj, 1).value.toString()"; 6007 "Object.getOwnPropertyDescriptor(obj, 1).value.toString()";
5965 ExpectString(slow_case_code, "1"); 6008 ExpectString(slow_case_code, "1");
5966 } 6009 }
5967 6010
5968 6011
5969 THREADED_TEST(IndexedInterceptorWithNoSetter) { 6012 THREADED_TEST(IndexedInterceptorWithNoSetter) {
5970 v8::HandleScope scope(CcTest::isolate()); 6013 v8::Isolate* isolate = CcTest::isolate();
5971 Local<ObjectTemplate> templ = ObjectTemplate::New(); 6014 v8::HandleScope scope(isolate);
6015 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5972 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); 6016 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
5973 6017
5974 LocalContext context; 6018 LocalContext context;
5975 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 6019 context->Global()->Set(v8_str("obj"), templ->NewInstance());
5976 6020
5977 const char* code = 6021 const char* code =
5978 "try {" 6022 "try {"
5979 " obj[0] = 239;" 6023 " obj[0] = 239;"
5980 " for (var i = 0; i < 100; i++) {" 6024 " for (var i = 0; i < 100; i++) {"
5981 " var v = obj[0];" 6025 " var v = obj[0];"
5982 " if (v != 0) throw 'Wrong value ' + v + ' at iteration ' + i;" 6026 " if (v != 0) throw 'Wrong value ' + v + ' at iteration ' + i;"
5983 " }" 6027 " }"
5984 " 'PASSED'" 6028 " 'PASSED'"
5985 "} catch(e) {" 6029 "} catch(e) {"
5986 " e" 6030 " e"
5987 "}"; 6031 "}";
5988 ExpectString(code, "PASSED"); 6032 ExpectString(code, "PASSED");
5989 } 6033 }
5990 6034
5991 6035
5992 THREADED_TEST(IndexedInterceptorWithAccessorCheck) { 6036 THREADED_TEST(IndexedInterceptorWithAccessorCheck) {
5993 v8::HandleScope scope(CcTest::isolate()); 6037 v8::Isolate* isolate = CcTest::isolate();
5994 Local<ObjectTemplate> templ = ObjectTemplate::New(); 6038 v8::HandleScope scope(isolate);
6039 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5995 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); 6040 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
5996 6041
5997 LocalContext context; 6042 LocalContext context;
5998 Local<v8::Object> obj = templ->NewInstance(); 6043 Local<v8::Object> obj = templ->NewInstance();
5999 obj->TurnOnAccessCheck(); 6044 obj->TurnOnAccessCheck();
6000 context->Global()->Set(v8_str("obj"), obj); 6045 context->Global()->Set(v8_str("obj"), obj);
6001 6046
6002 const char* code = 6047 const char* code =
6003 "try {" 6048 "try {"
6004 " for (var i = 0; i < 100; i++) {" 6049 " for (var i = 0; i < 100; i++) {"
6005 " var v = obj[0];" 6050 " var v = obj[0];"
6006 " if (v != undefined) throw 'Wrong value ' + v + ' at iteration ' + i;" 6051 " if (v != undefined) throw 'Wrong value ' + v + ' at iteration ' + i;"
6007 " }" 6052 " }"
6008 " 'PASSED'" 6053 " 'PASSED'"
6009 "} catch(e) {" 6054 "} catch(e) {"
6010 " e" 6055 " e"
6011 "}"; 6056 "}";
6012 ExpectString(code, "PASSED"); 6057 ExpectString(code, "PASSED");
6013 } 6058 }
6014 6059
6015 6060
6016 THREADED_TEST(IndexedInterceptorWithAccessorCheckSwitchedOn) { 6061 THREADED_TEST(IndexedInterceptorWithAccessorCheckSwitchedOn) {
6017 i::FLAG_allow_natives_syntax = true; 6062 i::FLAG_allow_natives_syntax = true;
6018 v8::HandleScope scope(CcTest::isolate()); 6063 v8::Isolate* isolate = CcTest::isolate();
6019 Local<ObjectTemplate> templ = ObjectTemplate::New(); 6064 v8::HandleScope scope(isolate);
6065 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
6020 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); 6066 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
6021 6067
6022 LocalContext context; 6068 LocalContext context;
6023 Local<v8::Object> obj = templ->NewInstance(); 6069 Local<v8::Object> obj = templ->NewInstance();
6024 context->Global()->Set(v8_str("obj"), obj); 6070 context->Global()->Set(v8_str("obj"), obj);
6025 6071
6026 const char* code = 6072 const char* code =
6027 "try {" 6073 "try {"
6028 " for (var i = 0; i < 100; i++) {" 6074 " for (var i = 0; i < 100; i++) {"
6029 " var expected = i;" 6075 " var expected = i;"
6030 " if (i == 5) {" 6076 " if (i == 5) {"
6031 " %EnableAccessChecks(obj);" 6077 " %EnableAccessChecks(obj);"
6032 " expected = undefined;" 6078 " expected = undefined;"
6033 " }" 6079 " }"
6034 " var v = obj[i];" 6080 " var v = obj[i];"
6035 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;" 6081 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;"
6036 " if (i == 5) %DisableAccessChecks(obj);" 6082 " if (i == 5) %DisableAccessChecks(obj);"
6037 " }" 6083 " }"
6038 " 'PASSED'" 6084 " 'PASSED'"
6039 "} catch(e) {" 6085 "} catch(e) {"
6040 " e" 6086 " e"
6041 "}"; 6087 "}";
6042 ExpectString(code, "PASSED"); 6088 ExpectString(code, "PASSED");
6043 } 6089 }
6044 6090
6045 6091
6046 THREADED_TEST(IndexedInterceptorWithDifferentIndices) { 6092 THREADED_TEST(IndexedInterceptorWithDifferentIndices) {
6047 v8::HandleScope scope(CcTest::isolate()); 6093 v8::Isolate* isolate = CcTest::isolate();
6048 Local<ObjectTemplate> templ = ObjectTemplate::New(); 6094 v8::HandleScope scope(isolate);
6095 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
6049 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); 6096 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
6050 6097
6051 LocalContext context; 6098 LocalContext context;
6052 Local<v8::Object> obj = templ->NewInstance(); 6099 Local<v8::Object> obj = templ->NewInstance();
6053 context->Global()->Set(v8_str("obj"), obj); 6100 context->Global()->Set(v8_str("obj"), obj);
6054 6101
6055 const char* code = 6102 const char* code =
6056 "try {" 6103 "try {"
6057 " for (var i = 0; i < 100; i++) {" 6104 " for (var i = 0; i < 100; i++) {"
6058 " var v = obj[i];" 6105 " var v = obj[i];"
6059 " if (v != i) throw 'Wrong value ' + v + ' at iteration ' + i;" 6106 " if (v != i) throw 'Wrong value ' + v + ' at iteration ' + i;"
6060 " }" 6107 " }"
6061 " 'PASSED'" 6108 " 'PASSED'"
6062 "} catch(e) {" 6109 "} catch(e) {"
6063 " e" 6110 " e"
6064 "}"; 6111 "}";
6065 ExpectString(code, "PASSED"); 6112 ExpectString(code, "PASSED");
6066 } 6113 }
6067 6114
6068 6115
6069 THREADED_TEST(IndexedInterceptorWithNegativeIndices) { 6116 THREADED_TEST(IndexedInterceptorWithNegativeIndices) {
6070 v8::HandleScope scope(CcTest::isolate()); 6117 v8::Isolate* isolate = CcTest::isolate();
6071 Local<ObjectTemplate> templ = ObjectTemplate::New(); 6118 v8::HandleScope scope(isolate);
6119 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
6072 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); 6120 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
6073 6121
6074 LocalContext context; 6122 LocalContext context;
6075 Local<v8::Object> obj = templ->NewInstance(); 6123 Local<v8::Object> obj = templ->NewInstance();
6076 context->Global()->Set(v8_str("obj"), obj); 6124 context->Global()->Set(v8_str("obj"), obj);
6077 6125
6078 const char* code = 6126 const char* code =
6079 "try {" 6127 "try {"
6080 " for (var i = 0; i < 100; i++) {" 6128 " for (var i = 0; i < 100; i++) {"
6081 " var expected = i;" 6129 " var expected = i;"
(...skipping 17 matching lines...) Expand all
6099 " }" 6147 " }"
6100 " 'PASSED'" 6148 " 'PASSED'"
6101 "} catch(e) {" 6149 "} catch(e) {"
6102 " e" 6150 " e"
6103 "}"; 6151 "}";
6104 ExpectString(code, "PASSED"); 6152 ExpectString(code, "PASSED");
6105 } 6153 }
6106 6154
6107 6155
6108 THREADED_TEST(IndexedInterceptorWithNotSmiLookup) { 6156 THREADED_TEST(IndexedInterceptorWithNotSmiLookup) {
6109 v8::HandleScope scope(CcTest::isolate()); 6157 v8::Isolate* isolate = CcTest::isolate();
6110 Local<ObjectTemplate> templ = ObjectTemplate::New(); 6158 v8::HandleScope scope(isolate);
6159 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
6111 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); 6160 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
6112 6161
6113 LocalContext context; 6162 LocalContext context;
6114 Local<v8::Object> obj = templ->NewInstance(); 6163 Local<v8::Object> obj = templ->NewInstance();
6115 context->Global()->Set(v8_str("obj"), obj); 6164 context->Global()->Set(v8_str("obj"), obj);
6116 6165
6117 const char* code = 6166 const char* code =
6118 "try {" 6167 "try {"
6119 " for (var i = 0; i < 100; i++) {" 6168 " for (var i = 0; i < 100; i++) {"
6120 " var expected = i;" 6169 " var expected = i;"
6121 " var key = i;" 6170 " var key = i;"
6122 " if (i == 50) {" 6171 " if (i == 50) {"
6123 " key = 'foobar';" 6172 " key = 'foobar';"
6124 " expected = undefined;" 6173 " expected = undefined;"
6125 " }" 6174 " }"
6126 " var v = obj[key];" 6175 " var v = obj[key];"
6127 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;" 6176 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;"
6128 " }" 6177 " }"
6129 " 'PASSED'" 6178 " 'PASSED'"
6130 "} catch(e) {" 6179 "} catch(e) {"
6131 " e" 6180 " e"
6132 "}"; 6181 "}";
6133 ExpectString(code, "PASSED"); 6182 ExpectString(code, "PASSED");
6134 } 6183 }
6135 6184
6136 6185
6137 THREADED_TEST(IndexedInterceptorGoingMegamorphic) { 6186 THREADED_TEST(IndexedInterceptorGoingMegamorphic) {
6138 v8::HandleScope scope(CcTest::isolate()); 6187 v8::Isolate* isolate = CcTest::isolate();
6139 Local<ObjectTemplate> templ = ObjectTemplate::New(); 6188 v8::HandleScope scope(isolate);
6189 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
6140 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); 6190 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
6141 6191
6142 LocalContext context; 6192 LocalContext context;
6143 Local<v8::Object> obj = templ->NewInstance(); 6193 Local<v8::Object> obj = templ->NewInstance();
6144 context->Global()->Set(v8_str("obj"), obj); 6194 context->Global()->Set(v8_str("obj"), obj);
6145 6195
6146 const char* code = 6196 const char* code =
6147 "var original = obj;" 6197 "var original = obj;"
6148 "try {" 6198 "try {"
6149 " for (var i = 0; i < 100; i++) {" 6199 " for (var i = 0; i < 100; i++) {"
6150 " var expected = i;" 6200 " var expected = i;"
6151 " if (i == 50) {" 6201 " if (i == 50) {"
6152 " obj = {50: 'foobar'};" 6202 " obj = {50: 'foobar'};"
6153 " expected = 'foobar';" 6203 " expected = 'foobar';"
6154 " }" 6204 " }"
6155 " var v = obj[i];" 6205 " var v = obj[i];"
6156 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;" 6206 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;"
6157 " if (i == 50) obj = original;" 6207 " if (i == 50) obj = original;"
6158 " }" 6208 " }"
6159 " 'PASSED'" 6209 " 'PASSED'"
6160 "} catch(e) {" 6210 "} catch(e) {"
6161 " e" 6211 " e"
6162 "}"; 6212 "}";
6163 ExpectString(code, "PASSED"); 6213 ExpectString(code, "PASSED");
6164 } 6214 }
6165 6215
6166 6216
6167 THREADED_TEST(IndexedInterceptorReceiverTurningSmi) { 6217 THREADED_TEST(IndexedInterceptorReceiverTurningSmi) {
6168 v8::HandleScope scope(CcTest::isolate()); 6218 v8::Isolate* isolate = CcTest::isolate();
6169 Local<ObjectTemplate> templ = ObjectTemplate::New(); 6219 v8::HandleScope scope(isolate);
6220 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
6170 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); 6221 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
6171 6222
6172 LocalContext context; 6223 LocalContext context;
6173 Local<v8::Object> obj = templ->NewInstance(); 6224 Local<v8::Object> obj = templ->NewInstance();
6174 context->Global()->Set(v8_str("obj"), obj); 6225 context->Global()->Set(v8_str("obj"), obj);
6175 6226
6176 const char* code = 6227 const char* code =
6177 "var original = obj;" 6228 "var original = obj;"
6178 "try {" 6229 "try {"
6179 " for (var i = 0; i < 100; i++) {" 6230 " for (var i = 0; i < 100; i++) {"
6180 " var expected = i;" 6231 " var expected = i;"
6181 " if (i == 5) {" 6232 " if (i == 5) {"
6182 " obj = 239;" 6233 " obj = 239;"
6183 " expected = undefined;" 6234 " expected = undefined;"
6184 " }" 6235 " }"
6185 " var v = obj[i];" 6236 " var v = obj[i];"
6186 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;" 6237 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;"
6187 " if (i == 5) obj = original;" 6238 " if (i == 5) obj = original;"
6188 " }" 6239 " }"
6189 " 'PASSED'" 6240 " 'PASSED'"
6190 "} catch(e) {" 6241 "} catch(e) {"
6191 " e" 6242 " e"
6192 "}"; 6243 "}";
6193 ExpectString(code, "PASSED"); 6244 ExpectString(code, "PASSED");
6194 } 6245 }
6195 6246
6196 6247
6197 THREADED_TEST(IndexedInterceptorOnProto) { 6248 THREADED_TEST(IndexedInterceptorOnProto) {
6198 v8::HandleScope scope(CcTest::isolate()); 6249 v8::Isolate* isolate = CcTest::isolate();
6199 Local<ObjectTemplate> templ = ObjectTemplate::New(); 6250 v8::HandleScope scope(isolate);
6251 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
6200 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); 6252 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
6201 6253
6202 LocalContext context; 6254 LocalContext context;
6203 Local<v8::Object> obj = templ->NewInstance(); 6255 Local<v8::Object> obj = templ->NewInstance();
6204 context->Global()->Set(v8_str("obj"), obj); 6256 context->Global()->Set(v8_str("obj"), obj);
6205 6257
6206 const char* code = 6258 const char* code =
6207 "var o = {__proto__: obj};" 6259 "var o = {__proto__: obj};"
6208 "try {" 6260 "try {"
6209 " for (var i = 0; i < 100; i++) {" 6261 " for (var i = 0; i < 100; i++) {"
6210 " var v = o[i];" 6262 " var v = o[i];"
6211 " if (v != i) throw 'Wrong value ' + v + ' at iteration ' + i;" 6263 " if (v != i) throw 'Wrong value ' + v + ' at iteration ' + i;"
6212 " }" 6264 " }"
6213 " 'PASSED'" 6265 " 'PASSED'"
6214 "} catch(e) {" 6266 "} catch(e) {"
6215 " e" 6267 " e"
6216 "}"; 6268 "}";
6217 ExpectString(code, "PASSED"); 6269 ExpectString(code, "PASSED");
6218 } 6270 }
6219 6271
6220 6272
6221 THREADED_TEST(MultiContexts) { 6273 THREADED_TEST(MultiContexts) {
6222 v8::Isolate* isolate = CcTest::isolate(); 6274 v8::Isolate* isolate = CcTest::isolate();
6223 v8::HandleScope scope(isolate); 6275 v8::HandleScope scope(isolate);
6224 v8::Handle<ObjectTemplate> templ = ObjectTemplate::New(); 6276 v8::Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate);
6225 templ->Set(v8_str("dummy"), v8::FunctionTemplate::New(isolate, 6277 templ->Set(v8_str("dummy"), v8::FunctionTemplate::New(isolate,
6226 DummyCallHandler)); 6278 DummyCallHandler));
6227 6279
6228 Local<String> password = v8_str("Password"); 6280 Local<String> password = v8_str("Password");
6229 6281
6230 // Create an environment 6282 // Create an environment
6231 LocalContext context0(0, templ); 6283 LocalContext context0(0, templ);
6232 context0->SetSecurityToken(password); 6284 context0->SetSecurityToken(password);
6233 v8::Handle<v8::Object> global0 = context0->Global(); 6285 v8::Handle<v8::Object> global0 = context0->Global();
6234 global0->Set(v8_str("custom"), v8_num(1234)); 6286 global0->Set(v8_str("custom"), v8_num(1234));
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
6403 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable 6455 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable
6404 6456
6405 Local<v8::Object> obj = desc->GetFunction()->NewInstance(); 6457 Local<v8::Object> obj = desc->GetFunction()->NewInstance();
6406 env->Global()->Set(v8_str("undetectable"), obj); 6458 env->Global()->Set(v8_str("undetectable"), obj);
6407 6459
6408 Local<String> source = v8_str("undetectable.x = 42;" 6460 Local<String> source = v8_str("undetectable.x = 42;"
6409 "undetectable.x"); 6461 "undetectable.x");
6410 6462
6411 Local<Script> script = Script::Compile(source); 6463 Local<Script> script = Script::Compile(source);
6412 6464
6413 CHECK_EQ(v8::Integer::New(42), script->Run()); 6465 CHECK_EQ(v8::Integer::New(isolate, 42), script->Run());
6414 6466
6415 ExpectBoolean("Object.isExtensible(undetectable)", true); 6467 ExpectBoolean("Object.isExtensible(undetectable)", true);
6416 6468
6417 source = v8_str("Object.preventExtensions(undetectable);"); 6469 source = v8_str("Object.preventExtensions(undetectable);");
6418 script = Script::Compile(source); 6470 script = Script::Compile(source);
6419 script->Run(); 6471 script->Run();
6420 ExpectBoolean("Object.isExtensible(undetectable)", false); 6472 ExpectBoolean("Object.isExtensible(undetectable)", false);
6421 6473
6422 source = v8_str("undetectable.y = 2000;"); 6474 source = v8_str("undetectable.y = 2000;");
6423 script = Script::Compile(source); 6475 script = Script::Compile(source);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
6509 TEST(PersistentHandles) { 6561 TEST(PersistentHandles) {
6510 LocalContext env; 6562 LocalContext env;
6511 v8::Isolate* isolate = CcTest::isolate(); 6563 v8::Isolate* isolate = CcTest::isolate();
6512 v8::HandleScope scope(isolate); 6564 v8::HandleScope scope(isolate);
6513 Local<String> str = v8_str("foo"); 6565 Local<String> str = v8_str("foo");
6514 v8::Persistent<String> p_str(isolate, str); 6566 v8::Persistent<String> p_str(isolate, str);
6515 p_str.Reset(); 6567 p_str.Reset();
6516 Local<Script> scr = Script::Compile(v8_str("")); 6568 Local<Script> scr = Script::Compile(v8_str(""));
6517 v8::Persistent<Script> p_scr(isolate, scr); 6569 v8::Persistent<Script> p_scr(isolate, scr);
6518 p_scr.Reset(); 6570 p_scr.Reset();
6519 Local<ObjectTemplate> templ = ObjectTemplate::New(); 6571 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
6520 v8::Persistent<ObjectTemplate> p_templ(isolate, templ); 6572 v8::Persistent<ObjectTemplate> p_templ(isolate, templ);
6521 p_templ.Reset(); 6573 p_templ.Reset();
6522 } 6574 }
6523 6575
6524 6576
6525 static void HandleLogDelegator( 6577 static void HandleLogDelegator(
6526 const v8::FunctionCallbackInfo<v8::Value>& args) { 6578 const v8::FunctionCallbackInfo<v8::Value>& args) {
6527 ApiTestFuzzer::Fuzz(); 6579 ApiTestFuzzer::Fuzz();
6528 } 6580 }
6529 6581
6530 6582
6531 THREADED_TEST(GlobalObjectTemplate) { 6583 THREADED_TEST(GlobalObjectTemplate) {
6532 v8::Isolate* isolate = CcTest::isolate(); 6584 v8::Isolate* isolate = CcTest::isolate();
6533 v8::HandleScope handle_scope(isolate); 6585 v8::HandleScope handle_scope(isolate);
6534 Local<ObjectTemplate> global_template = ObjectTemplate::New(); 6586 Local<ObjectTemplate> global_template = ObjectTemplate::New(isolate);
6535 global_template->Set(v8_str("JSNI_Log"), 6587 global_template->Set(v8_str("JSNI_Log"),
6536 v8::FunctionTemplate::New(isolate, HandleLogDelegator)); 6588 v8::FunctionTemplate::New(isolate, HandleLogDelegator));
6537 v8::Local<Context> context = Context::New(isolate, 0, global_template); 6589 v8::Local<Context> context = Context::New(isolate, 0, global_template);
6538 Context::Scope context_scope(context); 6590 Context::Scope context_scope(context);
6539 Script::Compile(v8_str("JSNI_Log('LOG')"))->Run(); 6591 Script::Compile(v8_str("JSNI_Log('LOG')"))->Run();
6540 } 6592 }
6541 6593
6542 6594
6543 static const char* kSimpleExtensionSource = 6595 static const char* kSimpleExtensionSource =
6544 "function Foo() {" 6596 "function Foo() {"
6545 " return 4;" 6597 " return 4;"
6546 "}"; 6598 "}";
6547 6599
6548 6600
6549 THREADED_TEST(SimpleExtensions) { 6601 THREADED_TEST(SimpleExtensions) {
6550 v8::HandleScope handle_scope(CcTest::isolate()); 6602 v8::HandleScope handle_scope(CcTest::isolate());
6551 v8::RegisterExtension(new Extension("simpletest", kSimpleExtensionSource)); 6603 v8::RegisterExtension(new Extension("simpletest", kSimpleExtensionSource));
6552 const char* extension_names[] = { "simpletest" }; 6604 const char* extension_names[] = { "simpletest" };
6553 v8::ExtensionConfiguration extensions(1, extension_names); 6605 v8::ExtensionConfiguration extensions(1, extension_names);
6554 v8::Handle<Context> context = 6606 v8::Handle<Context> context =
6555 Context::New(CcTest::isolate(), &extensions); 6607 Context::New(CcTest::isolate(), &extensions);
6556 Context::Scope lock(context); 6608 Context::Scope lock(context);
6557 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run(); 6609 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run();
6558 CHECK_EQ(result, v8::Integer::New(4)); 6610 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 4));
6559 } 6611 }
6560 6612
6561 6613
6562 THREADED_TEST(NullExtensions) { 6614 THREADED_TEST(NullExtensions) {
6563 v8::HandleScope handle_scope(CcTest::isolate()); 6615 v8::HandleScope handle_scope(CcTest::isolate());
6564 v8::RegisterExtension(new Extension("nulltest", NULL)); 6616 v8::RegisterExtension(new Extension("nulltest", NULL));
6565 const char* extension_names[] = { "nulltest" }; 6617 const char* extension_names[] = { "nulltest" };
6566 v8::ExtensionConfiguration extensions(1, extension_names); 6618 v8::ExtensionConfiguration extensions(1, extension_names);
6567 v8::Handle<Context> context = 6619 v8::Handle<Context> context =
6568 Context::New(CcTest::isolate(), &extensions); 6620 Context::New(CcTest::isolate(), &extensions);
6569 Context::Scope lock(context); 6621 Context::Scope lock(context);
6570 v8::Handle<Value> result = Script::Compile(v8_str("1+3"))->Run(); 6622 v8::Handle<Value> result = Script::Compile(v8_str("1+3"))->Run();
6571 CHECK_EQ(result, v8::Integer::New(4)); 6623 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 4));
6572 } 6624 }
6573 6625
6574 6626
6575 static const char* kEmbeddedExtensionSource = 6627 static const char* kEmbeddedExtensionSource =
6576 "function Ret54321(){return 54321;}~~@@$" 6628 "function Ret54321(){return 54321;}~~@@$"
6577 "$%% THIS IS A SERIES OF NON-NULL-TERMINATED STRINGS."; 6629 "$%% THIS IS A SERIES OF NON-NULL-TERMINATED STRINGS.";
6578 static const int kEmbeddedExtensionSourceValidLen = 34; 6630 static const int kEmbeddedExtensionSourceValidLen = 34;
6579 6631
6580 6632
6581 THREADED_TEST(ExtensionMissingSourceLength) { 6633 THREADED_TEST(ExtensionMissingSourceLength) {
(...skipping 17 matching lines...) Expand all
6599 v8::RegisterExtension(new Extension(extension_name.start(), 6651 v8::RegisterExtension(new Extension(extension_name.start(),
6600 kEmbeddedExtensionSource, 0, 0, 6652 kEmbeddedExtensionSource, 0, 0,
6601 source_len)); 6653 source_len));
6602 const char* extension_names[1] = { extension_name.start() }; 6654 const char* extension_names[1] = { extension_name.start() };
6603 v8::ExtensionConfiguration extensions(1, extension_names); 6655 v8::ExtensionConfiguration extensions(1, extension_names);
6604 v8::Handle<Context> context = 6656 v8::Handle<Context> context =
6605 Context::New(CcTest::isolate(), &extensions); 6657 Context::New(CcTest::isolate(), &extensions);
6606 if (source_len == kEmbeddedExtensionSourceValidLen) { 6658 if (source_len == kEmbeddedExtensionSourceValidLen) {
6607 Context::Scope lock(context); 6659 Context::Scope lock(context);
6608 v8::Handle<Value> result = Script::Compile(v8_str("Ret54321()"))->Run(); 6660 v8::Handle<Value> result = Script::Compile(v8_str("Ret54321()"))->Run();
6609 CHECK_EQ(v8::Integer::New(54321), result); 6661 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 54321), result);
6610 } else { 6662 } else {
6611 // Anything but exactly the right length should fail to compile. 6663 // Anything but exactly the right length should fail to compile.
6612 CHECK_EQ(0, *context); 6664 CHECK_EQ(0, *context);
6613 } 6665 }
6614 } 6666 }
6615 } 6667 }
6616 6668
6617 6669
6618 static const char* kEvalExtensionSource1 = 6670 static const char* kEvalExtensionSource1 =
6619 "function UseEval1() {" 6671 "function UseEval1() {"
(...skipping 15 matching lines...) Expand all
6635 THREADED_TEST(UseEvalFromExtension) { 6687 THREADED_TEST(UseEvalFromExtension) {
6636 v8::HandleScope handle_scope(CcTest::isolate()); 6688 v8::HandleScope handle_scope(CcTest::isolate());
6637 v8::RegisterExtension(new Extension("evaltest1", kEvalExtensionSource1)); 6689 v8::RegisterExtension(new Extension("evaltest1", kEvalExtensionSource1));
6638 v8::RegisterExtension(new Extension("evaltest2", kEvalExtensionSource2)); 6690 v8::RegisterExtension(new Extension("evaltest2", kEvalExtensionSource2));
6639 const char* extension_names[] = { "evaltest1", "evaltest2" }; 6691 const char* extension_names[] = { "evaltest1", "evaltest2" };
6640 v8::ExtensionConfiguration extensions(2, extension_names); 6692 v8::ExtensionConfiguration extensions(2, extension_names);
6641 v8::Handle<Context> context = 6693 v8::Handle<Context> context =
6642 Context::New(CcTest::isolate(), &extensions); 6694 Context::New(CcTest::isolate(), &extensions);
6643 Context::Scope lock(context); 6695 Context::Scope lock(context);
6644 v8::Handle<Value> result = Script::Compile(v8_str("UseEval1()"))->Run(); 6696 v8::Handle<Value> result = Script::Compile(v8_str("UseEval1()"))->Run();
6645 CHECK_EQ(result, v8::Integer::New(42)); 6697 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 42));
6646 result = Script::Compile(v8_str("UseEval2()"))->Run(); 6698 result = Script::Compile(v8_str("UseEval2()"))->Run();
6647 CHECK_EQ(result, v8::Integer::New(42)); 6699 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 42));
6648 } 6700 }
6649 6701
6650 6702
6651 static const char* kWithExtensionSource1 = 6703 static const char* kWithExtensionSource1 =
6652 "function UseWith1() {" 6704 "function UseWith1() {"
6653 " var x = 42;" 6705 " var x = 42;"
6654 " with({x:87}) { return x; }" 6706 " with({x:87}) { return x; }"
6655 "}"; 6707 "}";
6656 6708
6657 6709
(...skipping 11 matching lines...) Expand all
6669 THREADED_TEST(UseWithFromExtension) { 6721 THREADED_TEST(UseWithFromExtension) {
6670 v8::HandleScope handle_scope(CcTest::isolate()); 6722 v8::HandleScope handle_scope(CcTest::isolate());
6671 v8::RegisterExtension(new Extension("withtest1", kWithExtensionSource1)); 6723 v8::RegisterExtension(new Extension("withtest1", kWithExtensionSource1));
6672 v8::RegisterExtension(new Extension("withtest2", kWithExtensionSource2)); 6724 v8::RegisterExtension(new Extension("withtest2", kWithExtensionSource2));
6673 const char* extension_names[] = { "withtest1", "withtest2" }; 6725 const char* extension_names[] = { "withtest1", "withtest2" };
6674 v8::ExtensionConfiguration extensions(2, extension_names); 6726 v8::ExtensionConfiguration extensions(2, extension_names);
6675 v8::Handle<Context> context = 6727 v8::Handle<Context> context =
6676 Context::New(CcTest::isolate(), &extensions); 6728 Context::New(CcTest::isolate(), &extensions);
6677 Context::Scope lock(context); 6729 Context::Scope lock(context);
6678 v8::Handle<Value> result = Script::Compile(v8_str("UseWith1()"))->Run(); 6730 v8::Handle<Value> result = Script::Compile(v8_str("UseWith1()"))->Run();
6679 CHECK_EQ(result, v8::Integer::New(87)); 6731 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 87));
6680 result = Script::Compile(v8_str("UseWith2()"))->Run(); 6732 result = Script::Compile(v8_str("UseWith2()"))->Run();
6681 CHECK_EQ(result, v8::Integer::New(87)); 6733 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 87));
6682 } 6734 }
6683 6735
6684 6736
6685 THREADED_TEST(AutoExtensions) { 6737 THREADED_TEST(AutoExtensions) {
6686 v8::HandleScope handle_scope(CcTest::isolate()); 6738 v8::HandleScope handle_scope(CcTest::isolate());
6687 Extension* extension = new Extension("autotest", kSimpleExtensionSource); 6739 Extension* extension = new Extension("autotest", kSimpleExtensionSource);
6688 extension->set_auto_enable(true); 6740 extension->set_auto_enable(true);
6689 v8::RegisterExtension(extension); 6741 v8::RegisterExtension(extension);
6690 v8::Handle<Context> context = 6742 v8::Handle<Context> context =
6691 Context::New(CcTest::isolate()); 6743 Context::New(CcTest::isolate());
6692 Context::Scope lock(context); 6744 Context::Scope lock(context);
6693 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run(); 6745 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run();
6694 CHECK_EQ(result, v8::Integer::New(4)); 6746 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 4));
6695 } 6747 }
6696 6748
6697 6749
6698 static const char* kSyntaxErrorInExtensionSource = 6750 static const char* kSyntaxErrorInExtensionSource =
6699 "["; 6751 "[";
6700 6752
6701 6753
6702 // Test that a syntax error in an extension does not cause a fatal 6754 // Test that a syntax error in an extension does not cause a fatal
6703 // error but results in an empty context. 6755 // error but results in an empty context.
6704 THREADED_TEST(SyntaxErrorExtensions) { 6756 THREADED_TEST(SyntaxErrorExtensions) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
6744 THREADED_TEST(NativeCallInExtensions) { 6796 THREADED_TEST(NativeCallInExtensions) {
6745 v8::HandleScope handle_scope(CcTest::isolate()); 6797 v8::HandleScope handle_scope(CcTest::isolate());
6746 v8::RegisterExtension(new Extension("nativecall", 6798 v8::RegisterExtension(new Extension("nativecall",
6747 kNativeCallInExtensionSource)); 6799 kNativeCallInExtensionSource));
6748 const char* extension_names[] = { "nativecall" }; 6800 const char* extension_names[] = { "nativecall" };
6749 v8::ExtensionConfiguration extensions(1, extension_names); 6801 v8::ExtensionConfiguration extensions(1, extension_names);
6750 v8::Handle<Context> context = 6802 v8::Handle<Context> context =
6751 Context::New(CcTest::isolate(), &extensions); 6803 Context::New(CcTest::isolate(), &extensions);
6752 Context::Scope lock(context); 6804 Context::Scope lock(context);
6753 v8::Handle<Value> result = Script::Compile(v8_str(kNativeCallTest))->Run(); 6805 v8::Handle<Value> result = Script::Compile(v8_str(kNativeCallTest))->Run();
6754 CHECK_EQ(result, v8::Integer::New(3)); 6806 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 3));
6755 } 6807 }
6756 6808
6757 6809
6758 class NativeFunctionExtension : public Extension { 6810 class NativeFunctionExtension : public Extension {
6759 public: 6811 public:
6760 NativeFunctionExtension(const char* name, 6812 NativeFunctionExtension(const char* name,
6761 const char* source, 6813 const char* source,
6762 v8::FunctionCallback fun = &Echo) 6814 v8::FunctionCallback fun = &Echo)
6763 : Extension(name, source), 6815 : Extension(name, source),
6764 function_(fun) { } 6816 function_(fun) { }
(...skipping 16 matching lines...) Expand all
6781 v8::HandleScope handle_scope(CcTest::isolate()); 6833 v8::HandleScope handle_scope(CcTest::isolate());
6782 const char* name = "nativedecl"; 6834 const char* name = "nativedecl";
6783 v8::RegisterExtension(new NativeFunctionExtension(name, 6835 v8::RegisterExtension(new NativeFunctionExtension(name,
6784 "native function foo();")); 6836 "native function foo();"));
6785 const char* extension_names[] = { name }; 6837 const char* extension_names[] = { name };
6786 v8::ExtensionConfiguration extensions(1, extension_names); 6838 v8::ExtensionConfiguration extensions(1, extension_names);
6787 v8::Handle<Context> context = 6839 v8::Handle<Context> context =
6788 Context::New(CcTest::isolate(), &extensions); 6840 Context::New(CcTest::isolate(), &extensions);
6789 Context::Scope lock(context); 6841 Context::Scope lock(context);
6790 v8::Handle<Value> result = Script::Compile(v8_str("foo(42);"))->Run(); 6842 v8::Handle<Value> result = Script::Compile(v8_str("foo(42);"))->Run();
6791 CHECK_EQ(result, v8::Integer::New(42)); 6843 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 42));
6792 } 6844 }
6793 6845
6794 6846
6795 THREADED_TEST(NativeFunctionDeclarationError) { 6847 THREADED_TEST(NativeFunctionDeclarationError) {
6796 v8::HandleScope handle_scope(CcTest::isolate()); 6848 v8::HandleScope handle_scope(CcTest::isolate());
6797 const char* name = "nativedeclerr"; 6849 const char* name = "nativedeclerr";
6798 // Syntax error in extension code. 6850 // Syntax error in extension code.
6799 v8::RegisterExtension(new NativeFunctionExtension(name, 6851 v8::RegisterExtension(new NativeFunctionExtension(name,
6800 "native\nfunction foo();")); 6852 "native\nfunction foo();"));
6801 const char* extension_names[] = { name }; 6853 const char* extension_names[] = { name };
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
6889 v8::Isolate* isolate, 6941 v8::Isolate* isolate,
6890 v8::Handle<String> name); 6942 v8::Handle<String> name);
6891 }; 6943 };
6892 6944
6893 6945
6894 static int lookup_count = 0; 6946 static int lookup_count = 0;
6895 v8::Handle<v8::FunctionTemplate> FunctionExtension::GetNativeFunctionTemplate( 6947 v8::Handle<v8::FunctionTemplate> FunctionExtension::GetNativeFunctionTemplate(
6896 v8::Isolate* isolate, v8::Handle<String> name) { 6948 v8::Isolate* isolate, v8::Handle<String> name) {
6897 lookup_count++; 6949 lookup_count++;
6898 if (name->Equals(v8_str("A"))) { 6950 if (name->Equals(v8_str("A"))) {
6899 return v8::FunctionTemplate::New(isolate, CallFun, v8::Integer::New(8)); 6951 return v8::FunctionTemplate::New(
6952 isolate, CallFun, v8::Integer::New(isolate, 8));
6900 } else if (name->Equals(v8_str("B"))) { 6953 } else if (name->Equals(v8_str("B"))) {
6901 return v8::FunctionTemplate::New(isolate, CallFun, v8::Integer::New(7)); 6954 return v8::FunctionTemplate::New(
6955 isolate, CallFun, v8::Integer::New(isolate, 7));
6902 } else if (name->Equals(v8_str("C"))) { 6956 } else if (name->Equals(v8_str("C"))) {
6903 return v8::FunctionTemplate::New(isolate, CallFun, v8::Integer::New(6)); 6957 return v8::FunctionTemplate::New(
6958 isolate, CallFun, v8::Integer::New(isolate, 6));
6904 } else { 6959 } else {
6905 return v8::Handle<v8::FunctionTemplate>(); 6960 return v8::Handle<v8::FunctionTemplate>();
6906 } 6961 }
6907 } 6962 }
6908 6963
6909 6964
6910 THREADED_TEST(FunctionLookup) { 6965 THREADED_TEST(FunctionLookup) {
6911 v8::RegisterExtension(new FunctionExtension()); 6966 v8::RegisterExtension(new FunctionExtension());
6912 v8::HandleScope handle_scope(CcTest::isolate()); 6967 v8::HandleScope handle_scope(CcTest::isolate());
6913 static const char* exts[1] = { "functiontest" }; 6968 static const char* exts[1] = { "functiontest" };
6914 v8::ExtensionConfiguration config(1, exts); 6969 v8::ExtensionConfiguration config(1, exts);
6915 LocalContext context(&config); 6970 LocalContext context(&config);
6916 CHECK_EQ(3, lookup_count); 6971 CHECK_EQ(3, lookup_count);
6917 CHECK_EQ(v8::Integer::New(8), Script::Compile(v8_str("Foo(0)"))->Run()); 6972 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 8),
6918 CHECK_EQ(v8::Integer::New(7), Script::Compile(v8_str("Foo(1)"))->Run()); 6973 Script::Compile(v8_str("Foo(0)"))->Run());
6919 CHECK_EQ(v8::Integer::New(6), Script::Compile(v8_str("Foo(2)"))->Run()); 6974 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 7),
6975 Script::Compile(v8_str("Foo(1)"))->Run());
6976 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 6),
6977 Script::Compile(v8_str("Foo(2)"))->Run());
6920 } 6978 }
6921 6979
6922 6980
6923 THREADED_TEST(NativeFunctionConstructCall) { 6981 THREADED_TEST(NativeFunctionConstructCall) {
6924 v8::RegisterExtension(new FunctionExtension()); 6982 v8::RegisterExtension(new FunctionExtension());
6925 v8::HandleScope handle_scope(CcTest::isolate()); 6983 v8::HandleScope handle_scope(CcTest::isolate());
6926 static const char* exts[1] = { "functiontest" }; 6984 static const char* exts[1] = { "functiontest" };
6927 v8::ExtensionConfiguration config(1, exts); 6985 v8::ExtensionConfiguration config(1, exts);
6928 LocalContext context(&config); 6986 LocalContext context(&config);
6929 for (int i = 0; i < 10; i++) { 6987 for (int i = 0; i < 10; i++) {
6930 // Run a few times to ensure that allocation of objects doesn't 6988 // Run a few times to ensure that allocation of objects doesn't
6931 // change behavior of a constructor function. 6989 // change behavior of a constructor function.
6932 CHECK_EQ(v8::Integer::New(8), 6990 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 8),
6933 Script::Compile(v8_str("(new A()).data"))->Run()); 6991 Script::Compile(v8_str("(new A()).data"))->Run());
6934 CHECK_EQ(v8::Integer::New(7), 6992 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 7),
6935 Script::Compile(v8_str("(new B()).data"))->Run()); 6993 Script::Compile(v8_str("(new B()).data"))->Run());
6936 CHECK_EQ(v8::Integer::New(6), 6994 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 6),
6937 Script::Compile(v8_str("(new C()).data"))->Run()); 6995 Script::Compile(v8_str("(new C()).data"))->Run());
6938 } 6996 }
6939 } 6997 }
6940 6998
6941 6999
6942 static const char* last_location; 7000 static const char* last_location;
6943 static const char* last_message; 7001 static const char* last_message;
6944 void StoringErrorCallback(const char* location, const char* message) { 7002 void StoringErrorCallback(const char* location, const char* message) {
6945 if (last_location == NULL) { 7003 if (last_location == NULL) {
6946 last_location = location; 7004 last_location = location;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
7042 delete data.GetParameter(); 7100 delete data.GetParameter();
7043 } 7101 }
7044 7102
7045 void WhammyPropertyGetter(Local<String> name, 7103 void WhammyPropertyGetter(Local<String> name,
7046 const v8::PropertyCallbackInfo<v8::Value>& info) { 7104 const v8::PropertyCallbackInfo<v8::Value>& info) {
7047 Whammy* whammy = 7105 Whammy* whammy =
7048 static_cast<Whammy*>(v8::Handle<v8::External>::Cast(info.Data())->Value()); 7106 static_cast<Whammy*>(v8::Handle<v8::External>::Cast(info.Data())->Value());
7049 7107
7050 v8::Persistent<v8::Object>& prev = whammy->objects_[whammy->cursor_]; 7108 v8::Persistent<v8::Object>& prev = whammy->objects_[whammy->cursor_];
7051 7109
7052 v8::Handle<v8::Object> obj = v8::Object::New(); 7110 v8::Handle<v8::Object> obj = v8::Object::New(info.GetIsolate());
7053 if (!prev.IsEmpty()) { 7111 if (!prev.IsEmpty()) {
7054 v8::Local<v8::Object>::New(info.GetIsolate(), prev) 7112 v8::Local<v8::Object>::New(info.GetIsolate(), prev)
7055 ->Set(v8_str("next"), obj); 7113 ->Set(v8_str("next"), obj);
7056 prev.SetWeak<Value, Snorkel<Value> >(new Snorkel<Value>(&prev.As<Value>()), 7114 prev.SetWeak<Value, Snorkel<Value> >(new Snorkel<Value>(&prev.As<Value>()),
7057 &HandleWeakReference); 7115 &HandleWeakReference);
7058 } 7116 }
7059 whammy->objects_[whammy->cursor_].Reset(info.GetIsolate(), obj); 7117 whammy->objects_[whammy->cursor_].Reset(info.GetIsolate(), obj);
7060 whammy->cursor_ = (whammy->cursor_ + 1) % Whammy::kObjectCount; 7118 whammy->cursor_ = (whammy->cursor_ + 1) % Whammy::kObjectCount;
7061 info.GetReturnValue().Set(whammy->getScript()->Run()); 7119 info.GetReturnValue().Set(whammy->getScript()->Run());
7062 } 7120 }
7063 7121
7064 7122
7065 THREADED_TEST(WeakReference) { 7123 THREADED_TEST(WeakReference) {
7066 v8::HandleScope handle_scope(CcTest::isolate()); 7124 v8::Isolate* isolate = CcTest::isolate();
7067 v8::Handle<v8::ObjectTemplate> templ= v8::ObjectTemplate::New(); 7125 v8::HandleScope handle_scope(isolate);
7126 v8::Handle<v8::ObjectTemplate> templ= v8::ObjectTemplate::New(isolate);
7068 Whammy* whammy = new Whammy(CcTest::isolate()); 7127 Whammy* whammy = new Whammy(CcTest::isolate());
7069 templ->SetNamedPropertyHandler(WhammyPropertyGetter, 7128 templ->SetNamedPropertyHandler(WhammyPropertyGetter,
7070 0, 0, 0, 0, 7129 0, 0, 0, 0,
7071 v8::External::New(CcTest::isolate(), whammy)); 7130 v8::External::New(CcTest::isolate(), whammy));
7072 const char* extension_list[] = { "v8/gc" }; 7131 const char* extension_list[] = { "v8/gc" };
7073 v8::ExtensionConfiguration extensions(1, extension_list); 7132 v8::ExtensionConfiguration extensions(1, extension_list);
7074 v8::Handle<Context> context = 7133 v8::Handle<Context> context =
7075 Context::New(CcTest::isolate(), &extensions); 7134 Context::New(CcTest::isolate(), &extensions);
7076 Context::Scope context_scope(context); 7135 Context::Scope context_scope(context);
7077 7136
(...skipping 30 matching lines...) Expand all
7108 THREADED_TEST(IndependentWeakHandle) { 7167 THREADED_TEST(IndependentWeakHandle) {
7109 v8::Isolate* iso = CcTest::isolate(); 7168 v8::Isolate* iso = CcTest::isolate();
7110 v8::HandleScope scope(iso); 7169 v8::HandleScope scope(iso);
7111 v8::Handle<Context> context = Context::New(iso); 7170 v8::Handle<Context> context = Context::New(iso);
7112 Context::Scope context_scope(context); 7171 Context::Scope context_scope(context);
7113 7172
7114 FlagAndPersistent object_a, object_b; 7173 FlagAndPersistent object_a, object_b;
7115 7174
7116 { 7175 {
7117 v8::HandleScope handle_scope(iso); 7176 v8::HandleScope handle_scope(iso);
7118 object_a.handle.Reset(iso, v8::Object::New()); 7177 object_a.handle.Reset(iso, v8::Object::New(iso));
7119 object_b.handle.Reset(iso, v8::Object::New()); 7178 object_b.handle.Reset(iso, v8::Object::New(iso));
7120 } 7179 }
7121 7180
7122 object_a.flag = false; 7181 object_a.flag = false;
7123 object_b.flag = false; 7182 object_b.flag = false;
7124 object_a.handle.SetWeak(&object_a, &DisposeAndSetFlag); 7183 object_a.handle.SetWeak(&object_a, &DisposeAndSetFlag);
7125 object_b.handle.SetWeak(&object_b, &DisposeAndSetFlag); 7184 object_b.handle.SetWeak(&object_b, &DisposeAndSetFlag);
7126 CHECK(!object_b.handle.IsIndependent()); 7185 CHECK(!object_b.handle.IsIndependent());
7127 object_a.handle.MarkIndependent(); 7186 object_a.handle.MarkIndependent();
7128 object_b.handle.MarkIndependent(); 7187 object_b.handle.MarkIndependent();
7129 CHECK(object_b.handle.IsIndependent()); 7188 CHECK(object_b.handle.IsIndependent());
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
7172 {&ForceScavenge, &ForceMarkSweep}; 7231 {&ForceScavenge, &ForceMarkSweep};
7173 7232
7174 typedef void (*GCInvoker)(); 7233 typedef void (*GCInvoker)();
7175 GCInvoker invoke_gc[kNumberOfGCTypes] = {&InvokeScavenge, &InvokeMarkSweep}; 7234 GCInvoker invoke_gc[kNumberOfGCTypes] = {&InvokeScavenge, &InvokeMarkSweep};
7176 7235
7177 for (int outer_gc = 0; outer_gc < kNumberOfGCTypes; outer_gc++) { 7236 for (int outer_gc = 0; outer_gc < kNumberOfGCTypes; outer_gc++) {
7178 for (int inner_gc = 0; inner_gc < kNumberOfGCTypes; inner_gc++) { 7237 for (int inner_gc = 0; inner_gc < kNumberOfGCTypes; inner_gc++) {
7179 FlagAndPersistent object; 7238 FlagAndPersistent object;
7180 { 7239 {
7181 v8::HandleScope handle_scope(isolate); 7240 v8::HandleScope handle_scope(isolate);
7182 object.handle.Reset(isolate, v8::Object::New()); 7241 object.handle.Reset(isolate, v8::Object::New(isolate));
7183 } 7242 }
7184 object.flag = false; 7243 object.flag = false;
7185 object.handle.SetWeak(&object, gc_forcing_callback[inner_gc]); 7244 object.handle.SetWeak(&object, gc_forcing_callback[inner_gc]);
7186 object.handle.MarkIndependent(); 7245 object.handle.MarkIndependent();
7187 invoke_gc[outer_gc](); 7246 invoke_gc[outer_gc]();
7188 CHECK(object.flag); 7247 CHECK(object.flag);
7189 } 7248 }
7190 } 7249 }
7191 } 7250 }
7192 7251
7193 7252
7194 static void RevivingCallback( 7253 static void RevivingCallback(
7195 const v8::WeakCallbackData<v8::Object, FlagAndPersistent>& data) { 7254 const v8::WeakCallbackData<v8::Object, FlagAndPersistent>& data) {
7196 data.GetParameter()->handle.ClearWeak(); 7255 data.GetParameter()->handle.ClearWeak();
7197 data.GetParameter()->flag = true; 7256 data.GetParameter()->flag = true;
7198 } 7257 }
7199 7258
7200 7259
7201 THREADED_TEST(IndependentHandleRevival) { 7260 THREADED_TEST(IndependentHandleRevival) {
7202 v8::Isolate* isolate = CcTest::isolate(); 7261 v8::Isolate* isolate = CcTest::isolate();
7203 v8::HandleScope scope(isolate); 7262 v8::HandleScope scope(isolate);
7204 v8::Handle<Context> context = Context::New(isolate); 7263 v8::Handle<Context> context = Context::New(isolate);
7205 Context::Scope context_scope(context); 7264 Context::Scope context_scope(context);
7206 7265
7207 FlagAndPersistent object; 7266 FlagAndPersistent object;
7208 { 7267 {
7209 v8::HandleScope handle_scope(isolate); 7268 v8::HandleScope handle_scope(isolate);
7210 v8::Local<v8::Object> o = v8::Object::New(); 7269 v8::Local<v8::Object> o = v8::Object::New(isolate);
7211 object.handle.Reset(isolate, o); 7270 object.handle.Reset(isolate, o);
7212 o->Set(v8_str("x"), v8::Integer::New(1)); 7271 o->Set(v8_str("x"), v8::Integer::New(isolate, 1));
7213 v8::Local<String> y_str = v8_str("y"); 7272 v8::Local<String> y_str = v8_str("y");
7214 o->Set(y_str, y_str); 7273 o->Set(y_str, y_str);
7215 } 7274 }
7216 object.flag = false; 7275 object.flag = false;
7217 object.handle.SetWeak(&object, &RevivingCallback); 7276 object.handle.SetWeak(&object, &RevivingCallback);
7218 object.handle.MarkIndependent(); 7277 object.handle.MarkIndependent();
7219 CcTest::heap()->PerformScavenge(); 7278 CcTest::heap()->PerformScavenge();
7220 CHECK(object.flag); 7279 CHECK(object.flag);
7221 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 7280 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
7222 { 7281 {
7223 v8::HandleScope handle_scope(isolate); 7282 v8::HandleScope handle_scope(isolate);
7224 v8::Local<v8::Object> o = 7283 v8::Local<v8::Object> o =
7225 v8::Local<v8::Object>::New(isolate, object.handle); 7284 v8::Local<v8::Object>::New(isolate, object.handle);
7226 v8::Local<String> y_str = v8_str("y"); 7285 v8::Local<String> y_str = v8_str("y");
7227 CHECK_EQ(v8::Integer::New(1), o->Get(v8_str("x"))); 7286 CHECK_EQ(v8::Integer::New(isolate, 1), o->Get(v8_str("x")));
7228 CHECK(o->Get(y_str)->Equals(y_str)); 7287 CHECK(o->Get(y_str)->Equals(y_str));
7229 } 7288 }
7230 } 7289 }
7231 7290
7232 7291
7233 v8::Handle<Function> args_fun; 7292 v8::Handle<Function> args_fun;
7234 7293
7235 7294
7236 static void ArgumentsTestCallback( 7295 static void ArgumentsTestCallback(
7237 const v8::FunctionCallbackInfo<v8::Value>& args) { 7296 const v8::FunctionCallbackInfo<v8::Value>& args) {
7238 ApiTestFuzzer::Fuzz(); 7297 ApiTestFuzzer::Fuzz();
7239 v8::Isolate* isolate = args.GetIsolate(); 7298 v8::Isolate* isolate = args.GetIsolate();
7240 CHECK_EQ(args_fun, args.Callee()); 7299 CHECK_EQ(args_fun, args.Callee());
7241 CHECK_EQ(3, args.Length()); 7300 CHECK_EQ(3, args.Length());
7242 CHECK_EQ(v8::Integer::New(1, isolate), args[0]); 7301 CHECK_EQ(v8::Integer::New(isolate, 1), args[0]);
7243 CHECK_EQ(v8::Integer::New(2, isolate), args[1]); 7302 CHECK_EQ(v8::Integer::New(isolate, 2), args[1]);
7244 CHECK_EQ(v8::Integer::New(3, isolate), args[2]); 7303 CHECK_EQ(v8::Integer::New(isolate, 3), args[2]);
7245 CHECK_EQ(v8::Undefined(isolate), args[3]); 7304 CHECK_EQ(v8::Undefined(isolate), args[3]);
7246 v8::HandleScope scope(args.GetIsolate()); 7305 v8::HandleScope scope(args.GetIsolate());
7247 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 7306 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
7248 } 7307 }
7249 7308
7250 7309
7251 THREADED_TEST(Arguments) { 7310 THREADED_TEST(Arguments) {
7252 v8::Isolate* isolate = CcTest::isolate(); 7311 v8::Isolate* isolate = CcTest::isolate();
7253 v8::HandleScope scope(isolate); 7312 v8::HandleScope scope(isolate);
7254 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(); 7313 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(isolate);
7255 global->Set(v8_str("f"), 7314 global->Set(v8_str("f"),
7256 v8::FunctionTemplate::New(isolate, ArgumentsTestCallback)); 7315 v8::FunctionTemplate::New(isolate, ArgumentsTestCallback));
7257 LocalContext context(NULL, global); 7316 LocalContext context(NULL, global);
7258 args_fun = context->Global()->Get(v8_str("f")).As<Function>(); 7317 args_fun = context->Global()->Get(v8_str("f")).As<Function>();
7259 v8_compile("f(1, 2, 3)")->Run(); 7318 v8_compile("f(1, 2, 3)")->Run();
7260 } 7319 }
7261 7320
7262 7321
7263 static void NoBlockGetterX(Local<String> name, 7322 static void NoBlockGetterX(Local<String> name,
7264 const v8::PropertyCallbackInfo<v8::Value>&) { 7323 const v8::PropertyCallbackInfo<v8::Value>&) {
(...skipping 19 matching lines...) Expand all
7284 const v8::PropertyCallbackInfo<v8::Boolean>& info) { 7343 const v8::PropertyCallbackInfo<v8::Boolean>& info) {
7285 if (index != 2) { 7344 if (index != 2) {
7286 return; // not intercepted 7345 return; // not intercepted
7287 } 7346 }
7288 7347
7289 info.GetReturnValue().Set(false); // intercepted, don't delete the property 7348 info.GetReturnValue().Set(false); // intercepted, don't delete the property
7290 } 7349 }
7291 7350
7292 7351
7293 THREADED_TEST(Deleter) { 7352 THREADED_TEST(Deleter) {
7294 v8::HandleScope scope(CcTest::isolate()); 7353 v8::Isolate* isolate = CcTest::isolate();
7295 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 7354 v8::HandleScope scope(isolate);
7355 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate);
7296 obj->SetNamedPropertyHandler(NoBlockGetterX, NULL, NULL, PDeleter, NULL); 7356 obj->SetNamedPropertyHandler(NoBlockGetterX, NULL, NULL, PDeleter, NULL);
7297 obj->SetIndexedPropertyHandler(NoBlockGetterI, NULL, NULL, IDeleter, NULL); 7357 obj->SetIndexedPropertyHandler(NoBlockGetterI, NULL, NULL, IDeleter, NULL);
7298 LocalContext context; 7358 LocalContext context;
7299 context->Global()->Set(v8_str("k"), obj->NewInstance()); 7359 context->Global()->Set(v8_str("k"), obj->NewInstance());
7300 CompileRun( 7360 CompileRun(
7301 "k.foo = 'foo';" 7361 "k.foo = 'foo';"
7302 "k.bar = 'bar';" 7362 "k.bar = 'bar';"
7303 "k[2] = 2;" 7363 "k[2] = 2;"
7304 "k[4] = 4;"); 7364 "k[4] = 4;");
7305 CHECK(v8_compile("delete k.foo")->Run()->IsFalse()); 7365 CHECK(v8_compile("delete k.foo")->Run()->IsFalse());
(...skipping 24 matching lines...) Expand all
7330 static void IndexedGetK(uint32_t index, 7390 static void IndexedGetK(uint32_t index,
7331 const v8::PropertyCallbackInfo<v8::Value>& info) { 7391 const v8::PropertyCallbackInfo<v8::Value>& info) {
7332 ApiTestFuzzer::Fuzz(); 7392 ApiTestFuzzer::Fuzz();
7333 if (index == 0 || index == 1) info.GetReturnValue().SetUndefined(); 7393 if (index == 0 || index == 1) info.GetReturnValue().SetUndefined();
7334 } 7394 }
7335 7395
7336 7396
7337 static void NamedEnum(const v8::PropertyCallbackInfo<v8::Array>& info) { 7397 static void NamedEnum(const v8::PropertyCallbackInfo<v8::Array>& info) {
7338 ApiTestFuzzer::Fuzz(); 7398 ApiTestFuzzer::Fuzz();
7339 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 3); 7399 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 3);
7340 result->Set(v8::Integer::New(0), v8_str("foo")); 7400 result->Set(v8::Integer::New(info.GetIsolate(), 0), v8_str("foo"));
7341 result->Set(v8::Integer::New(1), v8_str("bar")); 7401 result->Set(v8::Integer::New(info.GetIsolate(), 1), v8_str("bar"));
7342 result->Set(v8::Integer::New(2), v8_str("baz")); 7402 result->Set(v8::Integer::New(info.GetIsolate(), 2), v8_str("baz"));
7343 info.GetReturnValue().Set(result); 7403 info.GetReturnValue().Set(result);
7344 } 7404 }
7345 7405
7346 7406
7347 static void IndexedEnum(const v8::PropertyCallbackInfo<v8::Array>& info) { 7407 static void IndexedEnum(const v8::PropertyCallbackInfo<v8::Array>& info) {
7348 ApiTestFuzzer::Fuzz(); 7408 ApiTestFuzzer::Fuzz();
7349 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 2); 7409 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 2);
7350 result->Set(v8::Integer::New(0), v8_str("0")); 7410 result->Set(v8::Integer::New(info.GetIsolate(), 0), v8_str("0"));
7351 result->Set(v8::Integer::New(1), v8_str("1")); 7411 result->Set(v8::Integer::New(info.GetIsolate(), 1), v8_str("1"));
7352 info.GetReturnValue().Set(result); 7412 info.GetReturnValue().Set(result);
7353 } 7413 }
7354 7414
7355 7415
7356 THREADED_TEST(Enumerators) { 7416 THREADED_TEST(Enumerators) {
7357 v8::HandleScope scope(CcTest::isolate()); 7417 v8::Isolate* isolate = CcTest::isolate();
7358 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 7418 v8::HandleScope scope(isolate);
7419 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate);
7359 obj->SetNamedPropertyHandler(GetK, NULL, NULL, NULL, NamedEnum); 7420 obj->SetNamedPropertyHandler(GetK, NULL, NULL, NULL, NamedEnum);
7360 obj->SetIndexedPropertyHandler(IndexedGetK, NULL, NULL, NULL, IndexedEnum); 7421 obj->SetIndexedPropertyHandler(IndexedGetK, NULL, NULL, NULL, IndexedEnum);
7361 LocalContext context; 7422 LocalContext context;
7362 context->Global()->Set(v8_str("k"), obj->NewInstance()); 7423 context->Global()->Set(v8_str("k"), obj->NewInstance());
7363 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( 7424 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun(
7364 "k[10] = 0;" 7425 "k[10] = 0;"
7365 "k.a = 0;" 7426 "k.a = 0;"
7366 "k[5] = 0;" 7427 "k[5] = 0;"
7367 "k.b = 0;" 7428 "k.b = 0;"
7368 "k[4294967295] = 0;" 7429 "k[4294967295] = 0;"
(...skipping 10 matching lines...) Expand all
7379 "}" 7440 "}"
7380 "result")); 7441 "result"));
7381 // Check that we get all the property names returned including the 7442 // Check that we get all the property names returned including the
7382 // ones from the enumerators in the right order: indexed properties 7443 // ones from the enumerators in the right order: indexed properties
7383 // in numerical order, indexed interceptor properties, named 7444 // in numerical order, indexed interceptor properties, named
7384 // properties in insertion order, named interceptor properties. 7445 // properties in insertion order, named interceptor properties.
7385 // This order is not mandated by the spec, so this test is just 7446 // This order is not mandated by the spec, so this test is just
7386 // documenting our behavior. 7447 // documenting our behavior.
7387 CHECK_EQ(17, result->Length()); 7448 CHECK_EQ(17, result->Length());
7388 // Indexed properties in numerical order. 7449 // Indexed properties in numerical order.
7389 CHECK_EQ(v8_str("5"), result->Get(v8::Integer::New(0))); 7450 CHECK_EQ(v8_str("5"), result->Get(v8::Integer::New(isolate, 0)));
7390 CHECK_EQ(v8_str("10"), result->Get(v8::Integer::New(1))); 7451 CHECK_EQ(v8_str("10"), result->Get(v8::Integer::New(isolate, 1)));
7391 CHECK_EQ(v8_str("140000"), result->Get(v8::Integer::New(2))); 7452 CHECK_EQ(v8_str("140000"), result->Get(v8::Integer::New(isolate, 2)));
7392 CHECK_EQ(v8_str("4294967295"), result->Get(v8::Integer::New(3))); 7453 CHECK_EQ(v8_str("4294967295"), result->Get(v8::Integer::New(isolate, 3)));
7393 // Indexed interceptor properties in the order they are returned 7454 // Indexed interceptor properties in the order they are returned
7394 // from the enumerator interceptor. 7455 // from the enumerator interceptor.
7395 CHECK_EQ(v8_str("0"), result->Get(v8::Integer::New(4))); 7456 CHECK_EQ(v8_str("0"), result->Get(v8::Integer::New(isolate, 4)));
7396 CHECK_EQ(v8_str("1"), result->Get(v8::Integer::New(5))); 7457 CHECK_EQ(v8_str("1"), result->Get(v8::Integer::New(isolate, 5)));
7397 // Named properties in insertion order. 7458 // Named properties in insertion order.
7398 CHECK_EQ(v8_str("a"), result->Get(v8::Integer::New(6))); 7459 CHECK_EQ(v8_str("a"), result->Get(v8::Integer::New(isolate, 6)));
7399 CHECK_EQ(v8_str("b"), result->Get(v8::Integer::New(7))); 7460 CHECK_EQ(v8_str("b"), result->Get(v8::Integer::New(isolate, 7)));
7400 CHECK_EQ(v8_str("c"), result->Get(v8::Integer::New(8))); 7461 CHECK_EQ(v8_str("c"), result->Get(v8::Integer::New(isolate, 8)));
7401 CHECK_EQ(v8_str("4294967296"), result->Get(v8::Integer::New(9))); 7462 CHECK_EQ(v8_str("4294967296"), result->Get(v8::Integer::New(isolate, 9)));
7402 CHECK_EQ(v8_str("d"), result->Get(v8::Integer::New(10))); 7463 CHECK_EQ(v8_str("d"), result->Get(v8::Integer::New(isolate, 10)));
7403 CHECK_EQ(v8_str("e"), result->Get(v8::Integer::New(11))); 7464 CHECK_EQ(v8_str("e"), result->Get(v8::Integer::New(isolate, 11)));
7404 CHECK_EQ(v8_str("30000000000"), result->Get(v8::Integer::New(12))); 7465 CHECK_EQ(v8_str("30000000000"), result->Get(v8::Integer::New(isolate, 12)));
7405 CHECK_EQ(v8_str("f"), result->Get(v8::Integer::New(13))); 7466 CHECK_EQ(v8_str("f"), result->Get(v8::Integer::New(isolate, 13)));
7406 // Named interceptor properties. 7467 // Named interceptor properties.
7407 CHECK_EQ(v8_str("foo"), result->Get(v8::Integer::New(14))); 7468 CHECK_EQ(v8_str("foo"), result->Get(v8::Integer::New(isolate, 14)));
7408 CHECK_EQ(v8_str("bar"), result->Get(v8::Integer::New(15))); 7469 CHECK_EQ(v8_str("bar"), result->Get(v8::Integer::New(isolate, 15)));
7409 CHECK_EQ(v8_str("baz"), result->Get(v8::Integer::New(16))); 7470 CHECK_EQ(v8_str("baz"), result->Get(v8::Integer::New(isolate, 16)));
7410 } 7471 }
7411 7472
7412 7473
7413 int p_getter_count; 7474 int p_getter_count;
7414 int p_getter_count2; 7475 int p_getter_count2;
7415 7476
7416 7477
7417 static void PGetter(Local<String> name, 7478 static void PGetter(Local<String> name,
7418 const v8::PropertyCallbackInfo<v8::Value>& info) { 7479 const v8::PropertyCallbackInfo<v8::Value>& info) {
7419 ApiTestFuzzer::Fuzz(); 7480 ApiTestFuzzer::Fuzz();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
7462 CHECK_EQ(info.This(), global->Get(v8_str("o2"))); 7523 CHECK_EQ(info.This(), global->Get(v8_str("o2")));
7463 } else if (name->Equals(v8_str("p3"))) { 7524 } else if (name->Equals(v8_str("p3"))) {
7464 CHECK_EQ(info.This(), global->Get(v8_str("o3"))); 7525 CHECK_EQ(info.This(), global->Get(v8_str("o3")));
7465 } else if (name->Equals(v8_str("p4"))) { 7526 } else if (name->Equals(v8_str("p4"))) {
7466 CHECK_EQ(info.This(), global->Get(v8_str("o4"))); 7527 CHECK_EQ(info.This(), global->Get(v8_str("o4")));
7467 } 7528 }
7468 } 7529 }
7469 7530
7470 7531
7471 THREADED_TEST(GetterHolders) { 7532 THREADED_TEST(GetterHolders) {
7472 v8::HandleScope scope(CcTest::isolate()); 7533 v8::Isolate* isolate = CcTest::isolate();
7473 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 7534 v8::HandleScope scope(isolate);
7535 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate);
7474 obj->SetAccessor(v8_str("p1"), PGetter); 7536 obj->SetAccessor(v8_str("p1"), PGetter);
7475 obj->SetAccessor(v8_str("p2"), PGetter); 7537 obj->SetAccessor(v8_str("p2"), PGetter);
7476 obj->SetAccessor(v8_str("p3"), PGetter); 7538 obj->SetAccessor(v8_str("p3"), PGetter);
7477 obj->SetAccessor(v8_str("p4"), PGetter); 7539 obj->SetAccessor(v8_str("p4"), PGetter);
7478 p_getter_count = 0; 7540 p_getter_count = 0;
7479 RunHolderTest(obj); 7541 RunHolderTest(obj);
7480 CHECK_EQ(40, p_getter_count); 7542 CHECK_EQ(40, p_getter_count);
7481 } 7543 }
7482 7544
7483 7545
7484 THREADED_TEST(PreInterceptorHolders) { 7546 THREADED_TEST(PreInterceptorHolders) {
7485 v8::HandleScope scope(CcTest::isolate()); 7547 v8::Isolate* isolate = CcTest::isolate();
7486 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 7548 v8::HandleScope scope(isolate);
7549 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate);
7487 obj->SetNamedPropertyHandler(PGetter2); 7550 obj->SetNamedPropertyHandler(PGetter2);
7488 p_getter_count2 = 0; 7551 p_getter_count2 = 0;
7489 RunHolderTest(obj); 7552 RunHolderTest(obj);
7490 CHECK_EQ(40, p_getter_count2); 7553 CHECK_EQ(40, p_getter_count2);
7491 } 7554 }
7492 7555
7493 7556
7494 THREADED_TEST(ObjectInstantiation) { 7557 THREADED_TEST(ObjectInstantiation) {
7495 v8::Isolate* isolate = CcTest::isolate(); 7558 v8::Isolate* isolate = CcTest::isolate();
7496 v8::HandleScope scope(isolate); 7559 v8::HandleScope scope(isolate);
7497 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 7560 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate);
7498 templ->SetAccessor(v8_str("t"), PGetter2); 7561 templ->SetAccessor(v8_str("t"), PGetter2);
7499 LocalContext context; 7562 LocalContext context;
7500 context->Global()->Set(v8_str("o"), templ->NewInstance()); 7563 context->Global()->Set(v8_str("o"), templ->NewInstance());
7501 for (int i = 0; i < 100; i++) { 7564 for (int i = 0; i < 100; i++) {
7502 v8::HandleScope inner_scope(CcTest::isolate()); 7565 v8::HandleScope inner_scope(CcTest::isolate());
7503 v8::Handle<v8::Object> obj = templ->NewInstance(); 7566 v8::Handle<v8::Object> obj = templ->NewInstance();
7504 CHECK_NE(obj, context->Global()->Get(v8_str("o"))); 7567 CHECK_NE(obj, context->Global()->Get(v8_str("o")));
7505 context->Global()->Set(v8_str("o2"), obj); 7568 context->Global()->Set(v8_str("o2"), obj);
7506 v8::Handle<Value> value = 7569 v8::Handle<Value> value =
7507 Script::Compile(v8_str("o.__proto__ === o2.__proto__"))->Run(); 7570 Script::Compile(v8_str("o.__proto__ === o2.__proto__"))->Run();
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
8018 CHECK(SameSymbol(sym0b, Handle<String>::Cast(s0b))); 8081 CHECK(SameSymbol(sym0b, Handle<String>::Cast(s0b)));
8019 CHECK(SameSymbol(sym1, Handle<String>::Cast(s1))); 8082 CHECK(SameSymbol(sym1, Handle<String>::Cast(s1)));
8020 CHECK(SameSymbol(sym2, Handle<String>::Cast(s2))); 8083 CHECK(SameSymbol(sym2, Handle<String>::Cast(s2)));
8021 CHECK(SameSymbol(sym3, Handle<String>::Cast(s3))); 8084 CHECK(SameSymbol(sym3, Handle<String>::Cast(s3)));
8022 CHECK(SameSymbol(sym4, Handle<String>::Cast(s4))); 8085 CHECK(SameSymbol(sym4, Handle<String>::Cast(s4)));
8023 } 8086 }
8024 8087
8025 8088
8026 THREADED_TEST(ToArrayIndex) { 8089 THREADED_TEST(ToArrayIndex) {
8027 LocalContext context; 8090 LocalContext context;
8028 v8::HandleScope scope(context->GetIsolate()); 8091 v8::Isolate* isolate = context->GetIsolate();
8092 v8::HandleScope scope(isolate);
8029 8093
8030 v8::Handle<String> str = v8_str("42"); 8094 v8::Handle<String> str = v8_str("42");
8031 v8::Handle<v8::Uint32> index = str->ToArrayIndex(); 8095 v8::Handle<v8::Uint32> index = str->ToArrayIndex();
8032 CHECK(!index.IsEmpty()); 8096 CHECK(!index.IsEmpty());
8033 CHECK_EQ(42.0, index->Uint32Value()); 8097 CHECK_EQ(42.0, index->Uint32Value());
8034 str = v8_str("42asdf"); 8098 str = v8_str("42asdf");
8035 index = str->ToArrayIndex(); 8099 index = str->ToArrayIndex();
8036 CHECK(index.IsEmpty()); 8100 CHECK(index.IsEmpty());
8037 str = v8_str("-42"); 8101 str = v8_str("-42");
8038 index = str->ToArrayIndex(); 8102 index = str->ToArrayIndex();
8039 CHECK(index.IsEmpty()); 8103 CHECK(index.IsEmpty());
8040 str = v8_str("4294967295"); 8104 str = v8_str("4294967295");
8041 index = str->ToArrayIndex(); 8105 index = str->ToArrayIndex();
8042 CHECK(!index.IsEmpty()); 8106 CHECK(!index.IsEmpty());
8043 CHECK_EQ(4294967295.0, index->Uint32Value()); 8107 CHECK_EQ(4294967295.0, index->Uint32Value());
8044 v8::Handle<v8::Number> num = v8::Number::New(1); 8108 v8::Handle<v8::Number> num = v8::Number::New(isolate, 1);
8045 index = num->ToArrayIndex(); 8109 index = num->ToArrayIndex();
8046 CHECK(!index.IsEmpty()); 8110 CHECK(!index.IsEmpty());
8047 CHECK_EQ(1.0, index->Uint32Value()); 8111 CHECK_EQ(1.0, index->Uint32Value());
8048 num = v8::Number::New(-1); 8112 num = v8::Number::New(isolate, -1);
8049 index = num->ToArrayIndex(); 8113 index = num->ToArrayIndex();
8050 CHECK(index.IsEmpty()); 8114 CHECK(index.IsEmpty());
8051 v8::Handle<v8::Object> obj = v8::Object::New(); 8115 v8::Handle<v8::Object> obj = v8::Object::New(isolate);
8052 index = obj->ToArrayIndex(); 8116 index = obj->ToArrayIndex();
8053 CHECK(index.IsEmpty()); 8117 CHECK(index.IsEmpty());
8054 } 8118 }
8055 8119
8056 8120
8057 THREADED_TEST(ErrorConstruction) { 8121 THREADED_TEST(ErrorConstruction) {
8058 LocalContext context; 8122 LocalContext context;
8059 v8::HandleScope scope(context->GetIsolate()); 8123 v8::HandleScope scope(context->GetIsolate());
8060 8124
8061 v8::Handle<String> foo = v8_str("foo"); 8125 v8::Handle<String> foo = v8_str("foo");
(...skipping 27 matching lines...) Expand all
8089 Local<Value> value, 8153 Local<Value> value,
8090 const v8::PropertyCallbackInfo<void>& info) { 8154 const v8::PropertyCallbackInfo<void>& info) {
8091 if (info.This()->Has(name)) { 8155 if (info.This()->Has(name)) {
8092 info.This()->Delete(name); 8156 info.This()->Delete(name);
8093 } 8157 }
8094 info.This()->Set(name, value); 8158 info.This()->Set(name, value);
8095 } 8159 }
8096 8160
8097 8161
8098 THREADED_TEST(DeleteAccessor) { 8162 THREADED_TEST(DeleteAccessor) {
8099 v8::HandleScope scope(CcTest::isolate()); 8163 v8::Isolate* isolate = CcTest::isolate();
8100 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 8164 v8::HandleScope scope(isolate);
8165 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate);
8101 obj->SetAccessor(v8_str("y"), YGetter, YSetter); 8166 obj->SetAccessor(v8_str("y"), YGetter, YSetter);
8102 LocalContext context; 8167 LocalContext context;
8103 v8::Handle<v8::Object> holder = obj->NewInstance(); 8168 v8::Handle<v8::Object> holder = obj->NewInstance();
8104 context->Global()->Set(v8_str("holder"), holder); 8169 context->Global()->Set(v8_str("holder"), holder);
8105 v8::Handle<Value> result = CompileRun( 8170 v8::Handle<Value> result = CompileRun(
8106 "holder.y = 11; holder.y = 12; holder.y"); 8171 "holder.y = 11; holder.y = 12; holder.y");
8107 CHECK_EQ(12, result->Uint32Value()); 8172 CHECK_EQ(12, result->Uint32Value());
8108 } 8173 }
8109 8174
8110 8175
8111 THREADED_TEST(TypeSwitch) { 8176 THREADED_TEST(TypeSwitch) {
8112 v8::Isolate* isolate = CcTest::isolate(); 8177 v8::Isolate* isolate = CcTest::isolate();
8113 v8::HandleScope scope(isolate); 8178 v8::HandleScope scope(isolate);
8114 v8::Handle<v8::FunctionTemplate> templ1 = v8::FunctionTemplate::New(isolate); 8179 v8::Handle<v8::FunctionTemplate> templ1 = v8::FunctionTemplate::New(isolate);
8115 v8::Handle<v8::FunctionTemplate> templ2 = v8::FunctionTemplate::New(isolate); 8180 v8::Handle<v8::FunctionTemplate> templ2 = v8::FunctionTemplate::New(isolate);
8116 v8::Handle<v8::FunctionTemplate> templ3 = v8::FunctionTemplate::New(isolate); 8181 v8::Handle<v8::FunctionTemplate> templ3 = v8::FunctionTemplate::New(isolate);
8117 v8::Handle<v8::FunctionTemplate> templs[3] = { templ1, templ2, templ3 }; 8182 v8::Handle<v8::FunctionTemplate> templs[3] = { templ1, templ2, templ3 };
8118 v8::Handle<v8::TypeSwitch> type_switch = v8::TypeSwitch::New(3, templs); 8183 v8::Handle<v8::TypeSwitch> type_switch = v8::TypeSwitch::New(3, templs);
8119 LocalContext context; 8184 LocalContext context;
8120 v8::Handle<v8::Object> obj0 = v8::Object::New(); 8185 v8::Handle<v8::Object> obj0 = v8::Object::New(isolate);
8121 v8::Handle<v8::Object> obj1 = templ1->GetFunction()->NewInstance(); 8186 v8::Handle<v8::Object> obj1 = templ1->GetFunction()->NewInstance();
8122 v8::Handle<v8::Object> obj2 = templ2->GetFunction()->NewInstance(); 8187 v8::Handle<v8::Object> obj2 = templ2->GetFunction()->NewInstance();
8123 v8::Handle<v8::Object> obj3 = templ3->GetFunction()->NewInstance(); 8188 v8::Handle<v8::Object> obj3 = templ3->GetFunction()->NewInstance();
8124 for (int i = 0; i < 10; i++) { 8189 for (int i = 0; i < 10; i++) {
8125 CHECK_EQ(0, type_switch->match(obj0)); 8190 CHECK_EQ(0, type_switch->match(obj0));
8126 CHECK_EQ(1, type_switch->match(obj1)); 8191 CHECK_EQ(1, type_switch->match(obj1));
8127 CHECK_EQ(2, type_switch->match(obj2)); 8192 CHECK_EQ(2, type_switch->match(obj2));
8128 CHECK_EQ(3, type_switch->match(obj3)); 8193 CHECK_EQ(3, type_switch->match(obj3));
8129 CHECK_EQ(3, type_switch->match(obj3)); 8194 CHECK_EQ(3, type_switch->match(obj3));
8130 CHECK_EQ(2, type_switch->match(obj2)); 8195 CHECK_EQ(2, type_switch->match(obj2));
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
8281 CHECK(!try_catch.HasCaught()); 8346 CHECK(!try_catch.HasCaught());
8282 Script::Compile(v8_str("(function()" 8347 Script::Compile(v8_str("(function()"
8283 " { try { throw ''; } finally { throw 0; }" 8348 " { try { throw ''; } finally { throw 0; }"
8284 "})()"))->Run(); 8349 "})()"))->Run();
8285 CHECK(try_catch.HasCaught()); 8350 CHECK(try_catch.HasCaught());
8286 } 8351 }
8287 8352
8288 8353
8289 // SecurityHandler can't be run twice 8354 // SecurityHandler can't be run twice
8290 TEST(SecurityHandler) { 8355 TEST(SecurityHandler) {
8291 v8::HandleScope scope0(CcTest::isolate()); 8356 v8::Isolate* isolate = CcTest::isolate();
8292 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 8357 v8::HandleScope scope0(isolate);
8358 v8::Handle<v8::ObjectTemplate> global_template =
8359 v8::ObjectTemplate::New(isolate);
8293 global_template->SetAccessCheckCallbacks(NamedSecurityTestCallback, 8360 global_template->SetAccessCheckCallbacks(NamedSecurityTestCallback,
8294 IndexedSecurityTestCallback); 8361 IndexedSecurityTestCallback);
8295 // Create an environment 8362 // Create an environment
8296 v8::Handle<Context> context0 = 8363 v8::Handle<Context> context0 = Context::New(isolate, NULL, global_template);
8297 Context::New(CcTest::isolate(), NULL, global_template);
8298 context0->Enter(); 8364 context0->Enter();
8299 8365
8300 v8::Handle<v8::Object> global0 = context0->Global(); 8366 v8::Handle<v8::Object> global0 = context0->Global();
8301 v8::Handle<Script> script0 = v8_compile("foo = 111"); 8367 v8::Handle<Script> script0 = v8_compile("foo = 111");
8302 script0->Run(); 8368 script0->Run();
8303 global0->Set(v8_str("0"), v8_num(999)); 8369 global0->Set(v8_str("0"), v8_num(999));
8304 v8::Handle<Value> foo0 = global0->Get(v8_str("foo")); 8370 v8::Handle<Value> foo0 = global0->Get(v8_str("foo"));
8305 CHECK_EQ(111, foo0->Int32Value()); 8371 CHECK_EQ(111, foo0->Int32Value());
8306 v8::Handle<Value> z0 = global0->Get(v8_str("0")); 8372 v8::Handle<Value> z0 = global0->Get(v8_str("0"));
8307 CHECK_EQ(999, z0->Int32Value()); 8373 CHECK_EQ(999, z0->Int32Value());
8308 8374
8309 // Create another environment, should fail security checks. 8375 // Create another environment, should fail security checks.
8310 v8::HandleScope scope1(CcTest::isolate()); 8376 v8::HandleScope scope1(isolate);
8311 8377
8312 v8::Handle<Context> context1 = 8378 v8::Handle<Context> context1 =
8313 Context::New(CcTest::isolate(), NULL, global_template); 8379 Context::New(isolate, NULL, global_template);
8314 context1->Enter(); 8380 context1->Enter();
8315 8381
8316 v8::Handle<v8::Object> global1 = context1->Global(); 8382 v8::Handle<v8::Object> global1 = context1->Global();
8317 global1->Set(v8_str("othercontext"), global0); 8383 global1->Set(v8_str("othercontext"), global0);
8318 // This set will fail the security check. 8384 // This set will fail the security check.
8319 v8::Handle<Script> script1 = 8385 v8::Handle<Script> script1 =
8320 v8_compile("othercontext.foo = 222; othercontext[0] = 888;"); 8386 v8_compile("othercontext.foo = 222; othercontext[0] = 888;");
8321 script1->Run(); 8387 script1->Run();
8322 // This read will pass the security check. 8388 // This read will pass the security check.
8323 v8::Handle<Value> foo1 = global0->Get(v8_str("foo")); 8389 v8::Handle<Value> foo1 = global0->Get(v8_str("foo"));
8324 CHECK_EQ(111, foo1->Int32Value()); 8390 CHECK_EQ(111, foo1->Int32Value());
8325 // This read will pass the security check. 8391 // This read will pass the security check.
8326 v8::Handle<Value> z1 = global0->Get(v8_str("0")); 8392 v8::Handle<Value> z1 = global0->Get(v8_str("0"));
8327 CHECK_EQ(999, z1->Int32Value()); 8393 CHECK_EQ(999, z1->Int32Value());
8328 8394
8329 // Create another environment, should pass security checks. 8395 // Create another environment, should pass security checks.
8330 { g_security_callback_result = true; // allow security handler to pass. 8396 { g_security_callback_result = true; // allow security handler to pass.
8331 v8::HandleScope scope2(CcTest::isolate()); 8397 v8::HandleScope scope2(isolate);
8332 LocalContext context2; 8398 LocalContext context2;
8333 v8::Handle<v8::Object> global2 = context2->Global(); 8399 v8::Handle<v8::Object> global2 = context2->Global();
8334 global2->Set(v8_str("othercontext"), global0); 8400 global2->Set(v8_str("othercontext"), global0);
8335 v8::Handle<Script> script2 = 8401 v8::Handle<Script> script2 =
8336 v8_compile("othercontext.foo = 333; othercontext[0] = 888;"); 8402 v8_compile("othercontext.foo = 333; othercontext[0] = 888;");
8337 script2->Run(); 8403 script2->Run();
8338 v8::Handle<Value> foo2 = global0->Get(v8_str("foo")); 8404 v8::Handle<Value> foo2 = global0->Get(v8_str("foo"));
8339 CHECK_EQ(333, foo2->Int32Value()); 8405 CHECK_EQ(333, foo2->Int32Value());
8340 v8::Handle<Value> z2 = global0->Get(v8_str("0")); 8406 v8::Handle<Value> z2 = global0->Get(v8_str("0"));
8341 CHECK_EQ(888, z2->Int32Value()); 8407 CHECK_EQ(888, z2->Int32Value());
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
8563 8629
8564 // Set to the same domain. 8630 // Set to the same domain.
8565 env1->SetSecurityToken(foo); 8631 env1->SetSecurityToken(foo);
8566 env2->SetSecurityToken(foo); 8632 env2->SetSecurityToken(foo);
8567 8633
8568 // Enter env2 8634 // Enter env2
8569 env2->Enter(); 8635 env2->Enter();
8570 8636
8571 // Create a function in env2 and add a reference to it in env1. 8637 // Create a function in env2 and add a reference to it in env1.
8572 Local<v8::Object> global2 = env2->Global(); 8638 Local<v8::Object> global2 = env2->Global();
8573 global2->Set(v8_str("prop"), v8::Integer::New(1)); 8639 global2->Set(v8_str("prop"), v8::Integer::New(env2->GetIsolate(), 1));
8574 CompileRun("function getProp() {return prop;}"); 8640 CompileRun("function getProp() {return prop;}");
8575 8641
8576 env1->Global()->Set(v8_str("getProp"), 8642 env1->Global()->Set(v8_str("getProp"),
8577 global2->Get(v8_str("getProp"))); 8643 global2->Get(v8_str("getProp")));
8578 8644
8579 // Detach env2's global, and reuse the global object of env2 8645 // Detach env2's global, and reuse the global object of env2
8580 env2->Exit(); 8646 env2->Exit();
8581 env2->DetachGlobal(); 8647 env2->DetachGlobal();
8582 8648
8583 v8::Handle<Context> env3 = Context::New(env1->GetIsolate(), 8649 v8::Handle<Context> env3 = Context::New(env1->GetIsolate(),
8584 0, 8650 0,
8585 v8::Handle<v8::ObjectTemplate>(), 8651 v8::Handle<v8::ObjectTemplate>(),
8586 global2); 8652 global2);
8587 env3->SetSecurityToken(v8_str("bar")); 8653 env3->SetSecurityToken(v8_str("bar"));
8588 env3->Enter(); 8654 env3->Enter();
8589 8655
8590 Local<v8::Object> global3 = env3->Global(); 8656 Local<v8::Object> global3 = env3->Global();
8591 CHECK_EQ(global2, global3); 8657 CHECK_EQ(global2, global3);
8592 CHECK(global3->Get(v8_str("prop"))->IsUndefined()); 8658 CHECK(global3->Get(v8_str("prop"))->IsUndefined());
8593 CHECK(global3->Get(v8_str("getProp"))->IsUndefined()); 8659 CHECK(global3->Get(v8_str("getProp"))->IsUndefined());
8594 global3->Set(v8_str("prop"), v8::Integer::New(-1)); 8660 global3->Set(v8_str("prop"), v8::Integer::New(env3->GetIsolate(), -1));
8595 global3->Set(v8_str("prop2"), v8::Integer::New(2)); 8661 global3->Set(v8_str("prop2"), v8::Integer::New(env3->GetIsolate(), 2));
8596 env3->Exit(); 8662 env3->Exit();
8597 8663
8598 // Call getProp in env1, and it should return the value 1 8664 // Call getProp in env1, and it should return the value 1
8599 { 8665 {
8600 Local<Value> get_prop = global1->Get(v8_str("getProp")); 8666 Local<Value> get_prop = global1->Get(v8_str("getProp"));
8601 CHECK(get_prop->IsFunction()); 8667 CHECK(get_prop->IsFunction());
8602 v8::TryCatch try_catch; 8668 v8::TryCatch try_catch;
8603 Local<Value> r = Function::Cast(*get_prop)->Call(global1, 0, NULL); 8669 Local<Value> r = Function::Cast(*get_prop)->Call(global1, 0, NULL);
8604 CHECK(!try_catch.HasCaught()); 8670 CHECK(!try_catch.HasCaught());
8605 CHECK_EQ(1, r->Int32Value()); 8671 CHECK_EQ(1, r->Int32Value());
(...skipping 16 matching lines...) Expand all
8622 8688
8623 Local<Value> foo = v8_str("foo"); 8689 Local<Value> foo = v8_str("foo");
8624 8690
8625 // Set same security token for env1 and env2. 8691 // Set same security token for env1 and env2.
8626 env1->SetSecurityToken(foo); 8692 env1->SetSecurityToken(foo);
8627 env2->SetSecurityToken(foo); 8693 env2->SetSecurityToken(foo);
8628 8694
8629 // Create a property on the global object in env2. 8695 // Create a property on the global object in env2.
8630 { 8696 {
8631 v8::Context::Scope scope(env2); 8697 v8::Context::Scope scope(env2);
8632 env2->Global()->Set(v8_str("p"), v8::Integer::New(42)); 8698 env2->Global()->Set(v8_str("p"), v8::Integer::New(env2->GetIsolate(), 42));
8633 } 8699 }
8634 8700
8635 // Create a reference to env2 global from env1 global. 8701 // Create a reference to env2 global from env1 global.
8636 env1->Global()->Set(v8_str("other"), env2->Global()); 8702 env1->Global()->Set(v8_str("other"), env2->Global());
8637 8703
8638 // Check that we have access to other.p in env2 from env1. 8704 // Check that we have access to other.p in env2 from env1.
8639 Local<Value> result = CompileRun("other.p"); 8705 Local<Value> result = CompileRun("other.p");
8640 CHECK(result->IsInt32()); 8706 CHECK(result->IsInt32());
8641 CHECK_EQ(42, result->Int32Value()); 8707 CHECK_EQ(42, result->Int32Value());
8642 8708
(...skipping 12 matching lines...) Expand all
8655 v8::Handle<v8::ObjectTemplate>(), 8721 v8::Handle<v8::ObjectTemplate>(),
8656 global2); 8722 global2);
8657 CHECK_EQ(global2, env3->Global()); 8723 CHECK_EQ(global2, env3->Global());
8658 8724
8659 // Start by using the same security token for env3 as for env1 and env2. 8725 // Start by using the same security token for env3 as for env1 and env2.
8660 env3->SetSecurityToken(foo); 8726 env3->SetSecurityToken(foo);
8661 8727
8662 // Create a property on the global object in env3. 8728 // Create a property on the global object in env3.
8663 { 8729 {
8664 v8::Context::Scope scope(env3); 8730 v8::Context::Scope scope(env3);
8665 env3->Global()->Set(v8_str("p"), v8::Integer::New(24)); 8731 env3->Global()->Set(v8_str("p"), v8::Integer::New(env3->GetIsolate(), 24));
8666 } 8732 }
8667 8733
8668 // Check that other.p is now the property in env3 and that we have access. 8734 // Check that other.p is now the property in env3 and that we have access.
8669 result = CompileRun("other.p"); 8735 result = CompileRun("other.p");
8670 CHECK(result->IsInt32()); 8736 CHECK(result->IsInt32());
8671 CHECK_EQ(24, result->Int32Value()); 8737 CHECK_EQ(24, result->Int32Value());
8672 8738
8673 // Change security token for env3 to something different from env1 and env2. 8739 // Change security token for env3 to something different from env1 and env2.
8674 env3->SetSecurityToken(v8_str("bar")); 8740 env3->SetSecurityToken(v8_str("bar"));
8675 8741
8676 // Check that we do not have access to other.p in env1. |other| is now 8742 // Check that we do not have access to other.p in env1. |other| is now
8677 // the global object for env3 which has a different security token, 8743 // the global object for env3 which has a different security token,
8678 // so access should be blocked. 8744 // so access should be blocked.
8679 result = CompileRun("other.p"); 8745 result = CompileRun("other.p");
8680 CHECK(result->IsUndefined()); 8746 CHECK(result->IsUndefined());
8681 } 8747 }
8682 8748
8683 8749
8750 void GetThisX(const v8::FunctionCallbackInfo<v8::Value>& info) {
8751 info.GetReturnValue().Set(
8752 info.GetIsolate()->GetCurrentContext()->Global()->Get(v8_str("x")));
8753 }
8754
8755
8684 TEST(DetachedAccesses) { 8756 TEST(DetachedAccesses) {
8685 LocalContext env1; 8757 LocalContext env1;
8686 v8::HandleScope scope(env1->GetIsolate()); 8758 v8::HandleScope scope(env1->GetIsolate());
8687 8759
8688 // Create second environment. 8760 // Create second environment.
8689 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); 8761 Local<ObjectTemplate> inner_global_template =
8762 FunctionTemplate::New(env1->GetIsolate())->InstanceTemplate();
8763 inner_global_template ->SetAccessorProperty(
8764 v8_str("this_x"), FunctionTemplate::New(env1->GetIsolate(), GetThisX));
8765 v8::Local<Context> env2 =
8766 Context::New(env1->GetIsolate(), NULL, inner_global_template);
8690 8767
8691 Local<Value> foo = v8_str("foo"); 8768 Local<Value> foo = v8_str("foo");
8692 8769
8693 // Set same security token for env1 and env2. 8770 // Set same security token for env1 and env2.
8694 env1->SetSecurityToken(foo); 8771 env1->SetSecurityToken(foo);
8695 env2->SetSecurityToken(foo); 8772 env2->SetSecurityToken(foo);
8696 8773
8774 env1->Global()->Set(v8_str("x"), v8_str("env1_x"));
8775
8697 { 8776 {
8698 v8::Context::Scope scope(env2); 8777 v8::Context::Scope scope(env2);
8778 env2->Global()->Set(v8_str("x"), v8_str("env2_x"));
8699 CompileRun( 8779 CompileRun(
8700 "var x = 'x';" 8780 "function bound_x() { return x; }"
8701 "function get_x() { return this.x; }" 8781 "function get_x() { return this.x; }"
8702 "function get_x_w() { return get_x(); }" 8782 "function get_x_w() { return (function() {return this.x;})(); }");
8703 ""); 8783 env1->Global()->Set(v8_str("bound_x"), CompileRun("bound_x"));
8704 env1->Global()->Set(v8_str("get_x"), CompileRun("get_x")); 8784 env1->Global()->Set(v8_str("get_x"), CompileRun("get_x"));
8705 env1->Global()->Set(v8_str("get_x_w"), CompileRun("get_x_w")); 8785 env1->Global()->Set(v8_str("get_x_w"), CompileRun("get_x_w"));
8786 env1->Global()->Set(
8787 v8_str("this_x"),
8788 CompileRun("Object.getOwnPropertyDescriptor(this, 'this_x').get"));
8706 } 8789 }
8707 8790
8708 Local<Object> env2_global = env2->Global(); 8791 Local<Object> env2_global = env2->Global();
8709 env2_global->TurnOnAccessCheck(); 8792 env2_global->TurnOnAccessCheck();
8710 env2->DetachGlobal(); 8793 env2->DetachGlobal();
8711 8794
8712 Local<Value> result; 8795 Local<Value> result;
8796 result = CompileRun("bound_x()");
8797 CHECK_EQ(v8_str("env2_x"), result);
8713 result = CompileRun("get_x()"); 8798 result = CompileRun("get_x()");
8714 CHECK(result->IsUndefined()); 8799 CHECK(result->IsUndefined());
8715 result = CompileRun("get_x_w()"); 8800 result = CompileRun("get_x_w()");
8716 CHECK(result->IsUndefined()); 8801 CHECK(result->IsUndefined());
8802 result = CompileRun("this_x()");
8803 CHECK_EQ(v8_str("env2_x"), result);
8717 8804
8718 // Reattach env2's proxy 8805 // Reattach env2's proxy
8719 env2 = Context::New(env1->GetIsolate(), 8806 env2 = Context::New(env1->GetIsolate(),
8720 0, 8807 0,
8721 v8::Handle<v8::ObjectTemplate>(), 8808 v8::Handle<v8::ObjectTemplate>(),
8722 env2_global); 8809 env2_global);
8723 env2->SetSecurityToken(foo); 8810 env2->SetSecurityToken(foo);
8724 { 8811 {
8725 v8::Context::Scope scope(env2); 8812 v8::Context::Scope scope(env2);
8726 CompileRun("var x = 'x2';"); 8813 env2->Global()->Set(v8_str("x"), v8_str("env3_x"));
8814 env2->Global()->Set(v8_str("env1"), env1->Global());
8815 result = CompileRun(
8816 "results = [];"
8817 "for (var i = 0; i < 4; i++ ) {"
8818 " results.push(env1.bound_x());"
8819 " results.push(env1.get_x());"
8820 " results.push(env1.get_x_w());"
8821 " results.push(env1.this_x());"
8822 "}"
8823 "results");
8824 Local<v8::Array> results = Local<v8::Array>::Cast(result);
8825 CHECK_EQ(16, results->Length());
8826 for (int i = 0; i < 16; i += 4) {
8827 CHECK_EQ(v8_str("env2_x"), results->Get(i + 0));
8828 CHECK_EQ(v8_str("env1_x"), results->Get(i + 1));
8829 CHECK_EQ(v8_str("env3_x"), results->Get(i + 2));
8830 CHECK_EQ(v8_str("env2_x"), results->Get(i + 3));
8831 }
8727 } 8832 }
8728 8833
8729 result = CompileRun("get_x()"); 8834 result = CompileRun(
8730 CHECK(result->IsUndefined()); 8835 "results = [];"
8731 result = CompileRun("get_x_w()"); 8836 "for (var i = 0; i < 4; i++ ) {"
8732 CHECK_EQ(v8_str("x2"), result); 8837 " results.push(bound_x());"
8838 " results.push(get_x());"
8839 " results.push(get_x_w());"
8840 " results.push(this_x());"
8841 "}"
8842 "results");
8843 Local<v8::Array> results = Local<v8::Array>::Cast(result);
8844 CHECK_EQ(16, results->Length());
8845 for (int i = 0; i < 16; i += 4) {
8846 CHECK_EQ(v8_str("env2_x"), results->Get(i + 0));
8847 CHECK_EQ(v8_str("env3_x"), results->Get(i + 1));
8848 CHECK_EQ(v8_str("env3_x"), results->Get(i + 2));
8849 CHECK_EQ(v8_str("env2_x"), results->Get(i + 3));
8850 }
8851
8852 result = CompileRun(
8853 "results = [];"
8854 "for (var i = 0; i < 4; i++ ) {"
8855 " results.push(this.bound_x());"
8856 " results.push(this.get_x());"
8857 " results.push(this.get_x_w());"
8858 " results.push(this.this_x());"
8859 "}"
8860 "results");
8861 results = Local<v8::Array>::Cast(result);
8862 CHECK_EQ(16, results->Length());
8863 for (int i = 0; i < 16; i += 4) {
8864 CHECK_EQ(v8_str("env2_x"), results->Get(i + 0));
8865 CHECK_EQ(v8_str("env1_x"), results->Get(i + 1));
8866 CHECK_EQ(v8_str("env3_x"), results->Get(i + 2));
8867 CHECK_EQ(v8_str("env2_x"), results->Get(i + 3));
8868 }
8733 } 8869 }
8734 8870
8735 8871
8736 static bool allowed_access_type[v8::ACCESS_KEYS + 1] = { false }; 8872 static bool allowed_access_type[v8::ACCESS_KEYS + 1] = { false };
8737 static bool NamedAccessBlocker(Local<v8::Object> global, 8873 static bool NamedAccessBlocker(Local<v8::Object> global,
8738 Local<Value> name, 8874 Local<Value> name,
8739 v8::AccessType type, 8875 v8::AccessType type,
8740 Local<Value> data) { 8876 Local<Value> data) {
8741 return CcTest::isolate()->GetCurrentContext()->Global()->Equals(global) || 8877 return CcTest::isolate()->GetCurrentContext()->Global()->Equals(global) ||
8742 allowed_access_type[type]; 8878 allowed_access_type[type];
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
8799 8935
8800 static void UnreachableFunction( 8936 static void UnreachableFunction(
8801 const v8::FunctionCallbackInfo<v8::Value>& info) { 8937 const v8::FunctionCallbackInfo<v8::Value>& info) {
8802 CHECK(false); // This function should not be called.. 8938 CHECK(false); // This function should not be called..
8803 } 8939 }
8804 8940
8805 8941
8806 TEST(AccessControl) { 8942 TEST(AccessControl) {
8807 v8::Isolate* isolate = CcTest::isolate(); 8943 v8::Isolate* isolate = CcTest::isolate();
8808 v8::HandleScope handle_scope(isolate); 8944 v8::HandleScope handle_scope(isolate);
8809 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 8945 v8::Handle<v8::ObjectTemplate> global_template =
8946 v8::ObjectTemplate::New(isolate);
8810 8947
8811 global_template->SetAccessCheckCallbacks(NamedAccessBlocker, 8948 global_template->SetAccessCheckCallbacks(NamedAccessBlocker,
8812 IndexedAccessBlocker); 8949 IndexedAccessBlocker);
8813 8950
8814 // Add an accessor accessible by cross-domain JS code. 8951 // Add an accessor accessible by cross-domain JS code.
8815 global_template->SetAccessor( 8952 global_template->SetAccessor(
8816 v8_str("accessible_prop"), 8953 v8_str("accessible_prop"),
8817 EchoGetter, EchoSetter, 8954 EchoGetter, EchoSetter,
8818 v8::Handle<Value>(), 8955 v8::Handle<Value>(),
8819 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE)); 8956 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE));
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
9078 CHECK(value->IsTrue()); 9215 CHECK(value->IsTrue());
9079 9216
9080 context1->Exit(); 9217 context1->Exit();
9081 context0->Exit(); 9218 context0->Exit();
9082 } 9219 }
9083 9220
9084 9221
9085 TEST(AccessControlES5) { 9222 TEST(AccessControlES5) {
9086 v8::Isolate* isolate = CcTest::isolate(); 9223 v8::Isolate* isolate = CcTest::isolate();
9087 v8::HandleScope handle_scope(isolate); 9224 v8::HandleScope handle_scope(isolate);
9088 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 9225 v8::Handle<v8::ObjectTemplate> global_template =
9226 v8::ObjectTemplate::New(isolate);
9089 9227
9090 global_template->SetAccessCheckCallbacks(NamedAccessBlocker, 9228 global_template->SetAccessCheckCallbacks(NamedAccessBlocker,
9091 IndexedAccessBlocker); 9229 IndexedAccessBlocker);
9092 9230
9093 // Add accessible accessor. 9231 // Add accessible accessor.
9094 global_template->SetAccessor( 9232 global_template->SetAccessor(
9095 v8_str("accessible_prop"), 9233 v8_str("accessible_prop"),
9096 EchoGetter, EchoSetter, 9234 EchoGetter, EchoSetter,
9097 v8::Handle<Value>(), 9235 v8::Handle<Value>(),
9098 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE)); 9236 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE));
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
9165 uint32_t key, 9303 uint32_t key,
9166 v8::AccessType type, 9304 v8::AccessType type,
9167 Local<Value> data) { 9305 Local<Value> data) {
9168 return false; 9306 return false;
9169 } 9307 }
9170 9308
9171 9309
9172 THREADED_TEST(AccessControlGetOwnPropertyNames) { 9310 THREADED_TEST(AccessControlGetOwnPropertyNames) {
9173 v8::Isolate* isolate = CcTest::isolate(); 9311 v8::Isolate* isolate = CcTest::isolate();
9174 v8::HandleScope handle_scope(isolate); 9312 v8::HandleScope handle_scope(isolate);
9175 v8::Handle<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(); 9313 v8::Handle<v8::ObjectTemplate> obj_template =
9314 v8::ObjectTemplate::New(isolate);
9176 9315
9177 obj_template->Set(v8_str("x"), v8::Integer::New(42)); 9316 obj_template->Set(v8_str("x"), v8::Integer::New(isolate, 42));
9178 obj_template->SetAccessCheckCallbacks(GetOwnPropertyNamesNamedBlocker, 9317 obj_template->SetAccessCheckCallbacks(GetOwnPropertyNamesNamedBlocker,
9179 GetOwnPropertyNamesIndexedBlocker); 9318 GetOwnPropertyNamesIndexedBlocker);
9180 9319
9181 // Create an environment 9320 // Create an environment
9182 v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template); 9321 v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template);
9183 context0->Enter(); 9322 context0->Enter();
9184 9323
9185 v8::Handle<v8::Object> global0 = context0->Global(); 9324 v8::Handle<v8::Object> global0 = context0->Global();
9186 9325
9187 v8::HandleScope scope1(CcTest::isolate()); 9326 v8::HandleScope scope1(CcTest::isolate());
(...skipping 19 matching lines...) Expand all
9207 CHECK(value->IsTrue()); 9346 CHECK(value->IsTrue());
9208 9347
9209 context1->Exit(); 9348 context1->Exit();
9210 context0->Exit(); 9349 context0->Exit();
9211 } 9350 }
9212 9351
9213 9352
9214 static void IndexedPropertyEnumerator( 9353 static void IndexedPropertyEnumerator(
9215 const v8::PropertyCallbackInfo<v8::Array>& info) { 9354 const v8::PropertyCallbackInfo<v8::Array>& info) {
9216 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 2); 9355 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 2);
9217 result->Set(0, v8::Integer::New(7)); 9356 result->Set(0, v8::Integer::New(info.GetIsolate(), 7));
9218 result->Set(1, v8::Object::New()); 9357 result->Set(1, v8::Object::New(info.GetIsolate()));
9219 info.GetReturnValue().Set(result); 9358 info.GetReturnValue().Set(result);
9220 } 9359 }
9221 9360
9222 9361
9223 static void NamedPropertyEnumerator( 9362 static void NamedPropertyEnumerator(
9224 const v8::PropertyCallbackInfo<v8::Array>& info) { 9363 const v8::PropertyCallbackInfo<v8::Array>& info) {
9225 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 2); 9364 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 2);
9226 result->Set(0, v8_str("x")); 9365 result->Set(0, v8_str("x"));
9227 result->Set(1, v8::Object::New()); 9366 result->Set(1, v8::Object::New(info.GetIsolate()));
9228 info.GetReturnValue().Set(result); 9367 info.GetReturnValue().Set(result);
9229 } 9368 }
9230 9369
9231 9370
9232 THREADED_TEST(GetOwnPropertyNamesWithInterceptor) { 9371 THREADED_TEST(GetOwnPropertyNamesWithInterceptor) {
9233 v8::HandleScope handle_scope(CcTest::isolate()); 9372 v8::Isolate* isolate = CcTest::isolate();
9234 v8::Handle<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(); 9373 v8::HandleScope handle_scope(isolate);
9374 v8::Handle<v8::ObjectTemplate> obj_template =
9375 v8::ObjectTemplate::New(isolate);
9235 9376
9236 obj_template->Set(v8_str("7"), v8::Integer::New(7)); 9377 obj_template->Set(v8_str("7"), v8::Integer::New(CcTest::isolate(), 7));
9237 obj_template->Set(v8_str("x"), v8::Integer::New(42)); 9378 obj_template->Set(v8_str("x"), v8::Integer::New(CcTest::isolate(), 42));
9238 obj_template->SetIndexedPropertyHandler(NULL, NULL, NULL, NULL, 9379 obj_template->SetIndexedPropertyHandler(NULL, NULL, NULL, NULL,
9239 IndexedPropertyEnumerator); 9380 IndexedPropertyEnumerator);
9240 obj_template->SetNamedPropertyHandler(NULL, NULL, NULL, NULL, 9381 obj_template->SetNamedPropertyHandler(NULL, NULL, NULL, NULL,
9241 NamedPropertyEnumerator); 9382 NamedPropertyEnumerator);
9242 9383
9243 LocalContext context; 9384 LocalContext context;
9244 v8::Handle<v8::Object> global = context->Global(); 9385 v8::Handle<v8::Object> global = context->Global();
9245 global->Set(v8_str("object"), obj_template->NewInstance()); 9386 global->Set(v8_str("object"), obj_template->NewInstance());
9246 9387
9247 v8::Handle<v8::Value> result = 9388 v8::Handle<v8::Value> result =
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
9345 9486
9346 v8::Isolate* isolate = CcTest::isolate(); 9487 v8::Isolate* isolate = CcTest::isolate();
9347 v8::HandleScope handle_scope(isolate); 9488 v8::HandleScope handle_scope(isolate);
9348 9489
9349 // Create an environment. 9490 // Create an environment.
9350 v8::Local<Context> context0 = Context::New(isolate); 9491 v8::Local<Context> context0 = Context::New(isolate);
9351 context0->Enter(); 9492 context0->Enter();
9352 9493
9353 // Create an object that requires access-check functions to be 9494 // Create an object that requires access-check functions to be
9354 // called for cross-domain access. 9495 // called for cross-domain access.
9355 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); 9496 v8::Handle<v8::ObjectTemplate> object_template =
9497 v8::ObjectTemplate::New(isolate);
9356 object_template->SetAccessCheckCallbacks(NamedAccessCounter, 9498 object_template->SetAccessCheckCallbacks(NamedAccessCounter,
9357 IndexedAccessCounter); 9499 IndexedAccessCounter);
9358 Local<v8::Object> object = object_template->NewInstance(); 9500 Local<v8::Object> object = object_template->NewInstance();
9359 9501
9360 v8::HandleScope scope1(isolate); 9502 v8::HandleScope scope1(isolate);
9361 9503
9362 // Create another environment. 9504 // Create another environment.
9363 v8::Local<Context> context1 = Context::New(isolate); 9505 v8::Local<Context> context1 = Context::New(isolate);
9364 context1->Enter(); 9506 context1->Enter();
9365 9507
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
9493 9635
9494 v8::Isolate* isolate = CcTest::isolate(); 9636 v8::Isolate* isolate = CcTest::isolate();
9495 v8::HandleScope handle_scope(isolate); 9637 v8::HandleScope handle_scope(isolate);
9496 9638
9497 // Create an environment. 9639 // Create an environment.
9498 v8::Local<Context> context0 = Context::New(isolate); 9640 v8::Local<Context> context0 = Context::New(isolate);
9499 context0->Enter(); 9641 context0->Enter();
9500 9642
9501 // Create an object that requires access-check functions to be 9643 // Create an object that requires access-check functions to be
9502 // called for cross-domain access. 9644 // called for cross-domain access.
9503 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); 9645 v8::Handle<v8::ObjectTemplate> object_template =
9646 v8::ObjectTemplate::New(isolate);
9504 object_template->SetAccessCheckCallbacks(NamedAccessFlatten, 9647 object_template->SetAccessCheckCallbacks(NamedAccessFlatten,
9505 IndexedAccessFlatten); 9648 IndexedAccessFlatten);
9506 Local<v8::Object> object = object_template->NewInstance(); 9649 Local<v8::Object> object = object_template->NewInstance();
9507 9650
9508 v8::HandleScope scope1(isolate); 9651 v8::HandleScope scope1(isolate);
9509 9652
9510 // Create another environment. 9653 // Create another environment.
9511 v8::Local<Context> context1 = Context::New(isolate); 9654 v8::Local<Context> context1 = Context::New(isolate);
9512 context1->Enter(); 9655 context1->Enter();
9513 9656
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
9562 v8::Isolate* isolate = CcTest::isolate(); 9705 v8::Isolate* isolate = CcTest::isolate();
9563 v8::HandleScope handle_scope(isolate); 9706 v8::HandleScope handle_scope(isolate);
9564 9707
9565 // Create an environment. 9708 // Create an environment.
9566 v8::Local<Context> context0 = Context::New(isolate); 9709 v8::Local<Context> context0 = Context::New(isolate);
9567 context0->Enter(); 9710 context0->Enter();
9568 9711
9569 // Create an object that requires access-check functions to be 9712 // Create an object that requires access-check functions to be
9570 // called for cross-domain access. The object also has interceptors 9713 // called for cross-domain access. The object also has interceptors
9571 // interceptor. 9714 // interceptor.
9572 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); 9715 v8::Handle<v8::ObjectTemplate> object_template =
9716 v8::ObjectTemplate::New(isolate);
9573 object_template->SetAccessCheckCallbacks(NamedAccessCounter, 9717 object_template->SetAccessCheckCallbacks(NamedAccessCounter,
9574 IndexedAccessCounter); 9718 IndexedAccessCounter);
9575 object_template->SetNamedPropertyHandler(AccessControlNamedGetter, 9719 object_template->SetNamedPropertyHandler(AccessControlNamedGetter,
9576 AccessControlNamedSetter); 9720 AccessControlNamedSetter);
9577 object_template->SetIndexedPropertyHandler(AccessControlIndexedGetter, 9721 object_template->SetIndexedPropertyHandler(AccessControlIndexedGetter,
9578 AccessControlIndexedSetter); 9722 AccessControlIndexedSetter);
9579 Local<v8::Object> object = object_template->NewInstance(); 9723 Local<v8::Object> object = object_template->NewInstance();
9580 9724
9581 v8::HandleScope scope1(isolate); 9725 v8::HandleScope scope1(isolate);
9582 9726
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
9798 static void ShadowNamedGet(Local<String> key, 9942 static void ShadowNamedGet(Local<String> key,
9799 const v8::PropertyCallbackInfo<v8::Value>&) { 9943 const v8::PropertyCallbackInfo<v8::Value>&) {
9800 } 9944 }
9801 9945
9802 9946
9803 THREADED_TEST(ShadowObject) { 9947 THREADED_TEST(ShadowObject) {
9804 shadow_y = shadow_y_setter_call_count = shadow_y_getter_call_count = 0; 9948 shadow_y = shadow_y_setter_call_count = shadow_y_getter_call_count = 0;
9805 v8::Isolate* isolate = CcTest::isolate(); 9949 v8::Isolate* isolate = CcTest::isolate();
9806 v8::HandleScope handle_scope(isolate); 9950 v8::HandleScope handle_scope(isolate);
9807 9951
9808 Local<ObjectTemplate> global_template = v8::ObjectTemplate::New(); 9952 Local<ObjectTemplate> global_template = v8::ObjectTemplate::New(isolate);
9809 LocalContext context(NULL, global_template); 9953 LocalContext context(NULL, global_template);
9810 9954
9811 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); 9955 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate);
9812 t->InstanceTemplate()->SetNamedPropertyHandler(ShadowNamedGet); 9956 t->InstanceTemplate()->SetNamedPropertyHandler(ShadowNamedGet);
9813 t->InstanceTemplate()->SetIndexedPropertyHandler(ShadowIndexedGet); 9957 t->InstanceTemplate()->SetIndexedPropertyHandler(ShadowIndexedGet);
9814 Local<ObjectTemplate> proto = t->PrototypeTemplate(); 9958 Local<ObjectTemplate> proto = t->PrototypeTemplate();
9815 Local<ObjectTemplate> instance = t->InstanceTemplate(); 9959 Local<ObjectTemplate> instance = t->InstanceTemplate();
9816 9960
9817 proto->Set(v8_str("f"), 9961 proto->Set(v8_str("f"),
9818 v8::FunctionTemplate::New(isolate, 9962 v8::FunctionTemplate::New(isolate,
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
9933 10077
9934 // Regression test for issue 2457. 10078 // Regression test for issue 2457.
9935 THREADED_TEST(HiddenPrototypeIdentityHash) { 10079 THREADED_TEST(HiddenPrototypeIdentityHash) {
9936 LocalContext context; 10080 LocalContext context;
9937 v8::HandleScope handle_scope(context->GetIsolate()); 10081 v8::HandleScope handle_scope(context->GetIsolate());
9938 10082
9939 Handle<FunctionTemplate> t = FunctionTemplate::New(context->GetIsolate()); 10083 Handle<FunctionTemplate> t = FunctionTemplate::New(context->GetIsolate());
9940 t->SetHiddenPrototype(true); 10084 t->SetHiddenPrototype(true);
9941 t->InstanceTemplate()->Set(v8_str("foo"), v8_num(75)); 10085 t->InstanceTemplate()->Set(v8_str("foo"), v8_num(75));
9942 Handle<Object> p = t->GetFunction()->NewInstance(); 10086 Handle<Object> p = t->GetFunction()->NewInstance();
9943 Handle<Object> o = Object::New(); 10087 Handle<Object> o = Object::New(context->GetIsolate());
9944 o->SetPrototype(p); 10088 o->SetPrototype(p);
9945 10089
9946 int hash = o->GetIdentityHash(); 10090 int hash = o->GetIdentityHash();
9947 USE(hash); 10091 USE(hash);
9948 o->Set(v8_str("foo"), v8_num(42)); 10092 o->Set(v8_str("foo"), v8_num(42));
9949 ASSERT_EQ(hash, o->GetIdentityHash()); 10093 ASSERT_EQ(hash, o->GetIdentityHash());
9950 } 10094 }
9951 10095
9952 10096
9953 THREADED_TEST(SetPrototype) { 10097 THREADED_TEST(SetPrototype) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
10016 LocalContext context; 10160 LocalContext context;
10017 v8::Isolate* isolate = context->GetIsolate(); 10161 v8::Isolate* isolate = context->GetIsolate();
10018 v8::HandleScope handle_scope(isolate); 10162 v8::HandleScope handle_scope(isolate);
10019 10163
10020 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate); 10164 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate);
10021 t1->SetHiddenPrototype(true); 10165 t1->SetHiddenPrototype(true);
10022 t1->InstanceTemplate()->Set(v8_str("foo"), v8_num(1)); 10166 t1->InstanceTemplate()->Set(v8_str("foo"), v8_num(1));
10023 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate); 10167 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate);
10024 t2->SetHiddenPrototype(true); 10168 t2->SetHiddenPrototype(true);
10025 t2->InstanceTemplate()->Set(v8_str("fuz1"), v8_num(2)); 10169 t2->InstanceTemplate()->Set(v8_str("fuz1"), v8_num(2));
10026 t2->InstanceTemplate()->Set(v8_str("objects"), v8::Object::New()); 10170 t2->InstanceTemplate()->Set(v8_str("objects"), v8::Object::New(isolate));
10027 t2->InstanceTemplate()->Set(v8_str("fuz2"), v8_num(2)); 10171 t2->InstanceTemplate()->Set(v8_str("fuz2"), v8_num(2));
10028 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(isolate); 10172 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(isolate);
10029 t3->SetHiddenPrototype(true); 10173 t3->SetHiddenPrototype(true);
10030 t3->InstanceTemplate()->Set(v8_str("boo"), v8_num(3)); 10174 t3->InstanceTemplate()->Set(v8_str("boo"), v8_num(3));
10031 Local<v8::FunctionTemplate> t4 = v8::FunctionTemplate::New(isolate); 10175 Local<v8::FunctionTemplate> t4 = v8::FunctionTemplate::New(isolate);
10032 t4->InstanceTemplate()->Set(v8_str("baz"), v8_num(4)); 10176 t4->InstanceTemplate()->Set(v8_str("baz"), v8_num(4));
10033 10177
10034 // Force dictionary-based properties. 10178 // Force dictionary-based properties.
10035 i::ScopedVector<char> name_buf(1024); 10179 i::ScopedVector<char> name_buf(1024);
10036 for (int i = 1; i <= 1000; i++) { 10180 for (int i = 1; i <= 1000; i++) {
10037 i::OS::SNPrintF(name_buf, "sdf%d", i); 10181 i::OS::SNPrintF(name_buf, "sdf%d", i);
10038 t2->InstanceTemplate()->Set(v8_str(name_buf.start()), v8_num(2)); 10182 t2->InstanceTemplate()->Set(v8_str(name_buf.start()), v8_num(2));
10039 } 10183 }
10040 10184
10041 Local<v8::Object> o1 = t1->GetFunction()->NewInstance(); 10185 Local<v8::Object> o1 = t1->GetFunction()->NewInstance();
10042 Local<v8::Object> o2 = t2->GetFunction()->NewInstance(); 10186 Local<v8::Object> o2 = t2->GetFunction()->NewInstance();
10043 Local<v8::Object> o3 = t3->GetFunction()->NewInstance(); 10187 Local<v8::Object> o3 = t3->GetFunction()->NewInstance();
10044 Local<v8::Object> o4 = t4->GetFunction()->NewInstance(); 10188 Local<v8::Object> o4 = t4->GetFunction()->NewInstance();
10045 10189
10046 // Create prototype chain of hidden prototypes. 10190 // Create prototype chain of hidden prototypes.
10047 CHECK(o4->SetPrototype(o3)); 10191 CHECK(o4->SetPrototype(o3));
10048 CHECK(o3->SetPrototype(o2)); 10192 CHECK(o3->SetPrototype(o2));
10049 CHECK(o2->SetPrototype(o1)); 10193 CHECK(o2->SetPrototype(o1));
10050 10194
10051 // Call the runtime version of GetLocalPropertyNames() on the natively 10195 // Call the runtime version of GetLocalPropertyNames() on the natively
10052 // created object through JavaScript. 10196 // created object through JavaScript.
10053 context->Global()->Set(v8_str("obj"), o4); 10197 context->Global()->Set(v8_str("obj"), o4);
10054 CompileRun("var names = %GetLocalPropertyNames(obj, true);"); 10198 // PROPERTY_ATTRIBUTES_NONE = 0
10199 CompileRun("var names = %GetLocalPropertyNames(obj, 0);");
10055 10200
10056 ExpectInt32("names.length", 1006); 10201 ExpectInt32("names.length", 1006);
10057 ExpectTrue("names.indexOf(\"baz\") >= 0"); 10202 ExpectTrue("names.indexOf(\"baz\") >= 0");
10058 ExpectTrue("names.indexOf(\"boo\") >= 0"); 10203 ExpectTrue("names.indexOf(\"boo\") >= 0");
10059 ExpectTrue("names.indexOf(\"foo\") >= 0"); 10204 ExpectTrue("names.indexOf(\"foo\") >= 0");
10060 ExpectTrue("names.indexOf(\"fuz1\") >= 0"); 10205 ExpectTrue("names.indexOf(\"fuz1\") >= 0");
10061 ExpectTrue("names.indexOf(\"fuz2\") >= 0"); 10206 ExpectTrue("names.indexOf(\"fuz2\") >= 0");
10062 ExpectFalse("names[1005] == undefined"); 10207 ExpectFalse("names[1005] == undefined");
10063 } 10208 }
10064 10209
10065 10210
10211 // Getting property names of an object with a hidden and inherited
10212 // prototype should not duplicate the accessor properties inherited.
10213 THREADED_TEST(Regress269562) {
10214 i::FLAG_allow_natives_syntax = true;
10215 LocalContext context;
10216 v8::HandleScope handle_scope(context->GetIsolate());
10217
10218 Local<v8::FunctionTemplate> t1 =
10219 v8::FunctionTemplate::New(context->GetIsolate());
10220 t1->SetHiddenPrototype(true);
10221
10222 Local<v8::ObjectTemplate> i1 = t1->InstanceTemplate();
10223 i1->SetAccessor(v8_str("foo"),
10224 SimpleAccessorGetter, SimpleAccessorSetter);
10225 i1->SetAccessor(v8_str("bar"),
10226 SimpleAccessorGetter, SimpleAccessorSetter);
10227 i1->SetAccessor(v8_str("baz"),
10228 SimpleAccessorGetter, SimpleAccessorSetter);
10229 i1->Set(v8_str("n1"), v8_num(1));
10230 i1->Set(v8_str("n2"), v8_num(2));
10231
10232 Local<v8::Object> o1 = t1->GetFunction()->NewInstance();
10233 Local<v8::FunctionTemplate> t2 =
10234 v8::FunctionTemplate::New(context->GetIsolate());
10235 t2->SetHiddenPrototype(true);
10236
10237 // Inherit from t1 and mark prototype as hidden.
10238 t2->Inherit(t1);
10239 t2->InstanceTemplate()->Set(v8_str("mine"), v8_num(4));
10240
10241 Local<v8::Object> o2 = t2->GetFunction()->NewInstance();
10242 CHECK(o2->SetPrototype(o1));
10243
10244 v8::Local<v8::Symbol> sym = v8::Symbol::New(context->GetIsolate(), "s1");
10245 o1->Set(sym, v8_num(3));
10246 o1->SetHiddenValue(v8_str("h1"),
10247 v8::Integer::New(context->GetIsolate(), 2013));
10248
10249 // Call the runtime version of GetLocalPropertyNames() on
10250 // the natively created object through JavaScript.
10251 context->Global()->Set(v8_str("obj"), o2);
10252 context->Global()->Set(v8_str("sym"), sym);
10253 // PROPERTY_ATTRIBUTES_NONE = 0
10254 CompileRun("var names = %GetLocalPropertyNames(obj, 0);");
10255
10256 ExpectInt32("names.length", 7);
10257 ExpectTrue("names.indexOf(\"foo\") >= 0");
10258 ExpectTrue("names.indexOf(\"bar\") >= 0");
10259 ExpectTrue("names.indexOf(\"baz\") >= 0");
10260 ExpectTrue("names.indexOf(\"n1\") >= 0");
10261 ExpectTrue("names.indexOf(\"n2\") >= 0");
10262 ExpectTrue("names.indexOf(sym) >= 0");
10263 ExpectTrue("names.indexOf(\"mine\") >= 0");
10264 }
10265
10266
10066 THREADED_TEST(FunctionReadOnlyPrototype) { 10267 THREADED_TEST(FunctionReadOnlyPrototype) {
10067 LocalContext context; 10268 LocalContext context;
10068 v8::Isolate* isolate = context->GetIsolate(); 10269 v8::Isolate* isolate = context->GetIsolate();
10069 v8::HandleScope handle_scope(isolate); 10270 v8::HandleScope handle_scope(isolate);
10070 10271
10071 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate); 10272 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate);
10072 t1->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(42)); 10273 t1->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(isolate, 42));
10073 t1->ReadOnlyPrototype(); 10274 t1->ReadOnlyPrototype();
10074 context->Global()->Set(v8_str("func1"), t1->GetFunction()); 10275 context->Global()->Set(v8_str("func1"), t1->GetFunction());
10075 // Configured value of ReadOnly flag. 10276 // Configured value of ReadOnly flag.
10076 CHECK(CompileRun( 10277 CHECK(CompileRun(
10077 "(function() {" 10278 "(function() {"
10078 " descriptor = Object.getOwnPropertyDescriptor(func1, 'prototype');" 10279 " descriptor = Object.getOwnPropertyDescriptor(func1, 'prototype');"
10079 " return (descriptor['writable'] == false);" 10280 " return (descriptor['writable'] == false);"
10080 "})()")->BooleanValue()); 10281 "})()")->BooleanValue());
10081 CHECK_EQ(42, CompileRun("func1.prototype.x")->Int32Value()); 10282 CHECK_EQ(42, CompileRun("func1.prototype.x")->Int32Value());
10082 CHECK_EQ(42, 10283 CHECK_EQ(42,
10083 CompileRun("func1.prototype = {}; func1.prototype.x")->Int32Value()); 10284 CompileRun("func1.prototype = {}; func1.prototype.x")->Int32Value());
10084 10285
10085 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate); 10286 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate);
10086 t2->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(42)); 10287 t2->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(isolate, 42));
10087 context->Global()->Set(v8_str("func2"), t2->GetFunction()); 10288 context->Global()->Set(v8_str("func2"), t2->GetFunction());
10088 // Default value of ReadOnly flag. 10289 // Default value of ReadOnly flag.
10089 CHECK(CompileRun( 10290 CHECK(CompileRun(
10090 "(function() {" 10291 "(function() {"
10091 " descriptor = Object.getOwnPropertyDescriptor(func2, 'prototype');" 10292 " descriptor = Object.getOwnPropertyDescriptor(func2, 'prototype');"
10092 " return (descriptor['writable'] == true);" 10293 " return (descriptor['writable'] == true);"
10093 "})()")->BooleanValue()); 10294 "})()")->BooleanValue());
10094 CHECK_EQ(42, CompileRun("func2.prototype.x")->Int32Value()); 10295 CHECK_EQ(42, CompileRun("func2.prototype.x")->Int32Value());
10095 } 10296 }
10096 10297
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
10133 CHECK(try_catch.HasCaught()); 10334 CHECK(try_catch.HasCaught());
10134 10335
10135 try_catch.Reset(); 10336 try_catch.Reset();
10136 fun->NewInstance(); 10337 fun->NewInstance();
10137 CHECK(try_catch.HasCaught()); 10338 CHECK(try_catch.HasCaught());
10138 } 10339 }
10139 10340
10140 10341
10141 THREADED_TEST(GetterSetterExceptions) { 10342 THREADED_TEST(GetterSetterExceptions) {
10142 LocalContext context; 10343 LocalContext context;
10143 v8::HandleScope handle_scope(context->GetIsolate()); 10344 v8::Isolate* isolate = context->GetIsolate();
10345 v8::HandleScope handle_scope(isolate);
10144 CompileRun( 10346 CompileRun(
10145 "function Foo() { };" 10347 "function Foo() { };"
10146 "function Throw() { throw 5; };" 10348 "function Throw() { throw 5; };"
10147 "var x = { };" 10349 "var x = { };"
10148 "x.__defineSetter__('set', Throw);" 10350 "x.__defineSetter__('set', Throw);"
10149 "x.__defineGetter__('get', Throw);"); 10351 "x.__defineGetter__('get', Throw);");
10150 Local<v8::Object> x = 10352 Local<v8::Object> x =
10151 Local<v8::Object>::Cast(context->Global()->Get(v8_str("x"))); 10353 Local<v8::Object>::Cast(context->Global()->Get(v8_str("x")));
10152 v8::TryCatch try_catch; 10354 v8::TryCatch try_catch;
10153 x->Set(v8_str("set"), v8::Integer::New(8)); 10355 x->Set(v8_str("set"), v8::Integer::New(isolate, 8));
10154 x->Get(v8_str("get")); 10356 x->Get(v8_str("get"));
10155 x->Set(v8_str("set"), v8::Integer::New(8)); 10357 x->Set(v8_str("set"), v8::Integer::New(isolate, 8));
10156 x->Get(v8_str("get")); 10358 x->Get(v8_str("get"));
10157 x->Set(v8_str("set"), v8::Integer::New(8)); 10359 x->Set(v8_str("set"), v8::Integer::New(isolate, 8));
10158 x->Get(v8_str("get")); 10360 x->Get(v8_str("get"));
10159 x->Set(v8_str("set"), v8::Integer::New(8)); 10361 x->Set(v8_str("set"), v8::Integer::New(isolate, 8));
10160 x->Get(v8_str("get")); 10362 x->Get(v8_str("get"));
10161 } 10363 }
10162 10364
10163 10365
10164 THREADED_TEST(Constructor) { 10366 THREADED_TEST(Constructor) {
10165 LocalContext context; 10367 LocalContext context;
10166 v8::Isolate* isolate = context->GetIsolate(); 10368 v8::Isolate* isolate = context->GetIsolate();
10167 v8::HandleScope handle_scope(isolate); 10369 v8::HandleScope handle_scope(isolate);
10168 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); 10370 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate);
10169 templ->SetClassName(v8_str("Fun")); 10371 templ->SetClassName(v8_str("Fun"));
10170 Local<Function> cons = templ->GetFunction(); 10372 Local<Function> cons = templ->GetFunction();
10171 context->Global()->Set(v8_str("Fun"), cons); 10373 context->Global()->Set(v8_str("Fun"), cons);
10172 Local<v8::Object> inst = cons->NewInstance(); 10374 Local<v8::Object> inst = cons->NewInstance();
10173 i::Handle<i::JSObject> obj(v8::Utils::OpenHandle(*inst)); 10375 i::Handle<i::JSObject> obj(v8::Utils::OpenHandle(*inst));
10174 CHECK(obj->IsJSObject()); 10376 CHECK(obj->IsJSObject());
10175 Local<Value> value = CompileRun("(new Fun()).constructor === Fun"); 10377 Local<Value> value = CompileRun("(new Fun()).constructor === Fun");
10176 CHECK(value->BooleanValue()); 10378 CHECK(value->BooleanValue());
10177 } 10379 }
10178 10380
10179 10381
10180 static void ConstructorCallback( 10382 static void ConstructorCallback(
10181 const v8::FunctionCallbackInfo<v8::Value>& args) { 10383 const v8::FunctionCallbackInfo<v8::Value>& args) {
10182 ApiTestFuzzer::Fuzz(); 10384 ApiTestFuzzer::Fuzz();
10183 Local<Object> This; 10385 Local<Object> This;
10184 10386
10185 if (args.IsConstructCall()) { 10387 if (args.IsConstructCall()) {
10186 Local<Object> Holder = args.Holder(); 10388 Local<Object> Holder = args.Holder();
10187 This = Object::New(); 10389 This = Object::New(args.GetIsolate());
10188 Local<Value> proto = Holder->GetPrototype(); 10390 Local<Value> proto = Holder->GetPrototype();
10189 if (proto->IsObject()) { 10391 if (proto->IsObject()) {
10190 This->SetPrototype(proto); 10392 This->SetPrototype(proto);
10191 } 10393 }
10192 } else { 10394 } else {
10193 This = args.This(); 10395 This = args.This();
10194 } 10396 }
10195 10397
10196 This->Set(v8_str("a"), args[0]); 10398 This->Set(v8_str("a"), args[0]);
10197 args.GetReturnValue().Set(This); 10399 args.GetReturnValue().Set(This);
10198 } 10400 }
10199 10401
10200 10402
10201 static void FakeConstructorCallback( 10403 static void FakeConstructorCallback(
10202 const v8::FunctionCallbackInfo<v8::Value>& args) { 10404 const v8::FunctionCallbackInfo<v8::Value>& args) {
10203 ApiTestFuzzer::Fuzz(); 10405 ApiTestFuzzer::Fuzz();
10204 args.GetReturnValue().Set(args[0]); 10406 args.GetReturnValue().Set(args[0]);
10205 } 10407 }
10206 10408
10207 10409
10208 THREADED_TEST(ConstructorForObject) { 10410 THREADED_TEST(ConstructorForObject) {
10209 LocalContext context; 10411 LocalContext context;
10210 v8::Isolate* isolate = context->GetIsolate(); 10412 v8::Isolate* isolate = context->GetIsolate();
10211 v8::HandleScope handle_scope(isolate); 10413 v8::HandleScope handle_scope(isolate);
10212 10414
10213 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(); 10415 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate);
10214 instance_template->SetCallAsFunctionHandler(ConstructorCallback); 10416 instance_template->SetCallAsFunctionHandler(ConstructorCallback);
10215 Local<Object> instance = instance_template->NewInstance(); 10417 Local<Object> instance = instance_template->NewInstance();
10216 context->Global()->Set(v8_str("obj"), instance); 10418 context->Global()->Set(v8_str("obj"), instance);
10217 v8::TryCatch try_catch; 10419 v8::TryCatch try_catch;
10218 Local<Value> value; 10420 Local<Value> value;
10219 CHECK(!try_catch.HasCaught()); 10421 CHECK(!try_catch.HasCaught());
10220 10422
10221 // Call the Object's constructor with a 32-bit signed integer. 10423 // Call the Object's constructor with a 32-bit signed integer.
10222 value = CompileRun("(function() { var o = new obj(28); return o.a; })()"); 10424 value = CompileRun("(function() { var o = new obj(28); return o.a; })()");
10223 CHECK(!try_catch.HasCaught()); 10425 CHECK(!try_catch.HasCaught());
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
10279 Handle<Value> args5[] = { v8::Null(isolate) }; 10481 Handle<Value> args5[] = { v8::Null(isolate) };
10280 Local<Value> value_obj5 = instance->CallAsConstructor(1, args5); 10482 Local<Value> value_obj5 = instance->CallAsConstructor(1, args5);
10281 CHECK(value_obj5->IsObject()); 10483 CHECK(value_obj5->IsObject());
10282 Local<Object> object5 = Local<Object>::Cast(value_obj5); 10484 Local<Object> object5 = Local<Object>::Cast(value_obj5);
10283 value = object5->Get(v8_str("a")); 10485 value = object5->Get(v8_str("a"));
10284 CHECK(!try_catch.HasCaught()); 10486 CHECK(!try_catch.HasCaught());
10285 CHECK(value->IsNull()); 10487 CHECK(value->IsNull());
10286 } 10488 }
10287 10489
10288 // Check exception handling when there is no constructor set for the Object. 10490 // Check exception handling when there is no constructor set for the Object.
10289 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(); 10491 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate);
10290 Local<Object> instance = instance_template->NewInstance(); 10492 Local<Object> instance = instance_template->NewInstance();
10291 context->Global()->Set(v8_str("obj2"), instance); 10493 context->Global()->Set(v8_str("obj2"), instance);
10292 v8::TryCatch try_catch; 10494 v8::TryCatch try_catch;
10293 Local<Value> value; 10495 Local<Value> value;
10294 CHECK(!try_catch.HasCaught()); 10496 CHECK(!try_catch.HasCaught());
10295 10497
10296 value = CompileRun("new obj2(28)"); 10498 value = CompileRun("new obj2(28)");
10297 CHECK(try_catch.HasCaught()); 10499 CHECK(try_catch.HasCaught());
10298 String::Utf8Value exception_value1(try_catch.Exception()); 10500 String::Utf8Value exception_value1(try_catch.Exception());
10299 CHECK_EQ("TypeError: object is not a function", *exception_value1); 10501 CHECK_EQ("TypeError: object is not a function", *exception_value1);
10300 try_catch.Reset(); 10502 try_catch.Reset();
10301 10503
10302 Local<Value> args[] = { v8_num(29) }; 10504 Local<Value> args[] = { v8_num(29) };
10303 value = instance->CallAsConstructor(1, args); 10505 value = instance->CallAsConstructor(1, args);
10304 CHECK(try_catch.HasCaught()); 10506 CHECK(try_catch.HasCaught());
10305 String::Utf8Value exception_value2(try_catch.Exception()); 10507 String::Utf8Value exception_value2(try_catch.Exception());
10306 CHECK_EQ("TypeError: #<Object> is not a function", *exception_value2); 10508 CHECK_EQ("TypeError: #<Object> is not a function", *exception_value2);
10307 try_catch.Reset(); 10509 try_catch.Reset();
10308 } 10510 }
10309 10511
10310 // Check the case when constructor throws exception. 10512 // Check the case when constructor throws exception.
10311 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(); 10513 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate);
10312 instance_template->SetCallAsFunctionHandler(ThrowValue); 10514 instance_template->SetCallAsFunctionHandler(ThrowValue);
10313 Local<Object> instance = instance_template->NewInstance(); 10515 Local<Object> instance = instance_template->NewInstance();
10314 context->Global()->Set(v8_str("obj3"), instance); 10516 context->Global()->Set(v8_str("obj3"), instance);
10315 v8::TryCatch try_catch; 10517 v8::TryCatch try_catch;
10316 Local<Value> value; 10518 Local<Value> value;
10317 CHECK(!try_catch.HasCaught()); 10519 CHECK(!try_catch.HasCaught());
10318 10520
10319 value = CompileRun("new obj3(22)"); 10521 value = CompileRun("new obj3(22)");
10320 CHECK(try_catch.HasCaught()); 10522 CHECK(try_catch.HasCaught());
10321 String::Utf8Value exception_value1(try_catch.Exception()); 10523 String::Utf8Value exception_value1(try_catch.Exception());
(...skipping 23 matching lines...) Expand all
10345 10547
10346 value = CompileRun("new obj4(28)"); 10548 value = CompileRun("new obj4(28)");
10347 CHECK(!try_catch.HasCaught()); 10549 CHECK(!try_catch.HasCaught());
10348 CHECK(value->IsObject()); 10550 CHECK(value->IsObject());
10349 10551
10350 Local<Value> args1[] = { v8_num(28) }; 10552 Local<Value> args1[] = { v8_num(28) };
10351 value = instance1->CallAsConstructor(1, args1); 10553 value = instance1->CallAsConstructor(1, args1);
10352 CHECK(!try_catch.HasCaught()); 10554 CHECK(!try_catch.HasCaught());
10353 CHECK(value->IsObject()); 10555 CHECK(value->IsObject());
10354 10556
10355 Local<ObjectTemplate> instance_template = ObjectTemplate::New(); 10557 Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate);
10356 instance_template->SetCallAsFunctionHandler(FakeConstructorCallback); 10558 instance_template->SetCallAsFunctionHandler(FakeConstructorCallback);
10357 Local<Object> instance2 = instance_template->NewInstance(); 10559 Local<Object> instance2 = instance_template->NewInstance();
10358 context->Global()->Set(v8_str("obj5"), instance2); 10560 context->Global()->Set(v8_str("obj5"), instance2);
10359 CHECK(!try_catch.HasCaught()); 10561 CHECK(!try_catch.HasCaught());
10360 10562
10361 CHECK(instance2->IsObject()); 10563 CHECK(instance2->IsObject());
10362 CHECK(!instance2->IsFunction()); 10564 CHECK(!instance2->IsFunction());
10363 10565
10364 value = CompileRun("new obj5(28)"); 10566 value = CompileRun("new obj5(28)");
10365 CHECK(!try_catch.HasCaught()); 10567 CHECK(!try_catch.HasCaught());
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
10777 } 10979 }
10778 } 10980 }
10779 10981
10780 10982
10781 // Check whether a non-function object is callable. 10983 // Check whether a non-function object is callable.
10782 THREADED_TEST(CallableObject) { 10984 THREADED_TEST(CallableObject) {
10783 LocalContext context; 10985 LocalContext context;
10784 v8::Isolate* isolate = context->GetIsolate(); 10986 v8::Isolate* isolate = context->GetIsolate();
10785 v8::HandleScope scope(isolate); 10987 v8::HandleScope scope(isolate);
10786 10988
10787 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(); 10989 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate);
10788 instance_template->SetCallAsFunctionHandler(call_as_function); 10990 instance_template->SetCallAsFunctionHandler(call_as_function);
10789 Local<Object> instance = instance_template->NewInstance(); 10991 Local<Object> instance = instance_template->NewInstance();
10790 v8::TryCatch try_catch; 10992 v8::TryCatch try_catch;
10791 10993
10792 CHECK(instance->IsCallable()); 10994 CHECK(instance->IsCallable());
10793 CHECK(!try_catch.HasCaught()); 10995 CHECK(!try_catch.HasCaught());
10794 } 10996 }
10795 10997
10796 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(); 10998 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate);
10797 Local<Object> instance = instance_template->NewInstance(); 10999 Local<Object> instance = instance_template->NewInstance();
10798 v8::TryCatch try_catch; 11000 v8::TryCatch try_catch;
10799 11001
10800 CHECK(!instance->IsCallable()); 11002 CHECK(!instance->IsCallable());
10801 CHECK(!try_catch.HasCaught()); 11003 CHECK(!try_catch.HasCaught());
10802 } 11004 }
10803 11005
10804 { Local<FunctionTemplate> function_template = 11006 { Local<FunctionTemplate> function_template =
10805 FunctionTemplate::New(isolate, call_as_function); 11007 FunctionTemplate::New(isolate, call_as_function);
10806 Local<Function> function = function_template->GetFunction(); 11008 Local<Function> function = function_template->GetFunction();
10807 Local<Object> instance = function; 11009 Local<Object> instance = function;
10808 v8::TryCatch try_catch; 11010 v8::TryCatch try_catch;
10809 11011
10810 CHECK(instance->IsCallable()); 11012 CHECK(instance->IsCallable());
10811 CHECK(!try_catch.HasCaught()); 11013 CHECK(!try_catch.HasCaught());
10812 } 11014 }
10813 11015
10814 { Local<FunctionTemplate> function_template = FunctionTemplate::New(isolate); 11016 { Local<FunctionTemplate> function_template = FunctionTemplate::New(isolate);
10815 Local<Function> function = function_template->GetFunction(); 11017 Local<Function> function = function_template->GetFunction();
10816 Local<Object> instance = function; 11018 Local<Object> instance = function;
10817 v8::TryCatch try_catch; 11019 v8::TryCatch try_catch;
10818 11020
10819 CHECK(instance->IsCallable()); 11021 CHECK(instance->IsCallable());
10820 CHECK(!try_catch.HasCaught()); 11022 CHECK(!try_catch.HasCaught());
10821 } 11023 }
10822 } 11024 }
10823 11025
10824 11026
10825 static int CountHandles() { 11027 static int Recurse(v8::Isolate* isolate, int depth, int iterations) {
10826 return v8::HandleScope::NumberOfHandles(); 11028 v8::HandleScope scope(isolate);
10827 } 11029 if (depth == 0) return v8::HandleScope::NumberOfHandles(isolate);
10828
10829
10830 static int Recurse(int depth, int iterations) {
10831 v8::HandleScope scope(CcTest::isolate());
10832 if (depth == 0) return CountHandles();
10833 for (int i = 0; i < iterations; i++) { 11030 for (int i = 0; i < iterations; i++) {
10834 Local<v8::Number> n(v8::Integer::New(42)); 11031 Local<v8::Number> n(v8::Integer::New(isolate, 42));
10835 } 11032 }
10836 return Recurse(depth - 1, iterations); 11033 return Recurse(isolate, depth - 1, iterations);
10837 } 11034 }
10838 11035
10839 11036
10840 THREADED_TEST(HandleIteration) { 11037 THREADED_TEST(HandleIteration) {
10841 static const int kIterations = 500; 11038 static const int kIterations = 500;
10842 static const int kNesting = 200; 11039 static const int kNesting = 200;
10843 CHECK_EQ(0, CountHandles()); 11040 LocalContext context;
11041 v8::Isolate* isolate = context->GetIsolate();
11042 v8::HandleScope scope0(isolate);
11043 CHECK_EQ(0, v8::HandleScope::NumberOfHandles(isolate));
10844 { 11044 {
10845 v8::HandleScope scope1(CcTest::isolate()); 11045 v8::HandleScope scope1(isolate);
10846 CHECK_EQ(0, CountHandles()); 11046 CHECK_EQ(0, v8::HandleScope::NumberOfHandles(isolate));
10847 for (int i = 0; i < kIterations; i++) { 11047 for (int i = 0; i < kIterations; i++) {
10848 Local<v8::Number> n(v8::Integer::New(42)); 11048 Local<v8::Number> n(v8::Integer::New(CcTest::isolate(), 42));
10849 CHECK_EQ(i + 1, CountHandles()); 11049 CHECK_EQ(i + 1, v8::HandleScope::NumberOfHandles(isolate));
10850 } 11050 }
10851 11051
10852 CHECK_EQ(kIterations, CountHandles()); 11052 CHECK_EQ(kIterations, v8::HandleScope::NumberOfHandles(isolate));
10853 { 11053 {
10854 v8::HandleScope scope2(CcTest::isolate()); 11054 v8::HandleScope scope2(CcTest::isolate());
10855 for (int j = 0; j < kIterations; j++) { 11055 for (int j = 0; j < kIterations; j++) {
10856 Local<v8::Number> n(v8::Integer::New(42)); 11056 Local<v8::Number> n(v8::Integer::New(CcTest::isolate(), 42));
10857 CHECK_EQ(j + 1 + kIterations, CountHandles()); 11057 CHECK_EQ(j + 1 + kIterations,
11058 v8::HandleScope::NumberOfHandles(isolate));
10858 } 11059 }
10859 } 11060 }
10860 CHECK_EQ(kIterations, CountHandles()); 11061 CHECK_EQ(kIterations, v8::HandleScope::NumberOfHandles(isolate));
10861 } 11062 }
10862 CHECK_EQ(0, CountHandles()); 11063 CHECK_EQ(0, v8::HandleScope::NumberOfHandles(isolate));
10863 CHECK_EQ(kNesting * kIterations, Recurse(kNesting, kIterations)); 11064 CHECK_EQ(kNesting * kIterations, Recurse(isolate, kNesting, kIterations));
10864 } 11065 }
10865 11066
10866 11067
10867 static void InterceptorHasOwnPropertyGetter( 11068 static void InterceptorHasOwnPropertyGetter(
10868 Local<String> name, 11069 Local<String> name,
10869 const v8::PropertyCallbackInfo<v8::Value>& info) { 11070 const v8::PropertyCallbackInfo<v8::Value>& info) {
10870 ApiTestFuzzer::Fuzz(); 11071 ApiTestFuzzer::Fuzz();
10871 } 11072 }
10872 11073
10873 11074
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
10934 11135
10935 11136
10936 typedef void (*NamedPropertyGetter)( 11137 typedef void (*NamedPropertyGetter)(
10937 Local<String> property, 11138 Local<String> property,
10938 const v8::PropertyCallbackInfo<v8::Value>& info); 11139 const v8::PropertyCallbackInfo<v8::Value>& info);
10939 11140
10940 11141
10941 static void CheckInterceptorLoadIC(NamedPropertyGetter getter, 11142 static void CheckInterceptorLoadIC(NamedPropertyGetter getter,
10942 const char* source, 11143 const char* source,
10943 int expected) { 11144 int expected) {
10944 v8::HandleScope scope(CcTest::isolate()); 11145 v8::Isolate* isolate = CcTest::isolate();
10945 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 11146 v8::HandleScope scope(isolate);
11147 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate);
10946 templ->SetNamedPropertyHandler(getter, 0, 0, 0, 0, v8_str("data")); 11148 templ->SetNamedPropertyHandler(getter, 0, 0, 0, 0, v8_str("data"));
10947 LocalContext context; 11149 LocalContext context;
10948 context->Global()->Set(v8_str("o"), templ->NewInstance()); 11150 context->Global()->Set(v8_str("o"), templ->NewInstance());
10949 v8::Handle<Value> value = CompileRun(source); 11151 v8::Handle<Value> value = CompileRun(source);
10950 CHECK_EQ(expected, value->Int32Value()); 11152 CHECK_EQ(expected, value->Int32Value());
10951 } 11153 }
10952 11154
10953 11155
10954 static void InterceptorLoadICGetter( 11156 static void InterceptorLoadICGetter(
10955 Local<String> name, 11157 Local<String> name,
10956 const v8::PropertyCallbackInfo<v8::Value>& info) { 11158 const v8::PropertyCallbackInfo<v8::Value>& info) {
10957 ApiTestFuzzer::Fuzz(); 11159 ApiTestFuzzer::Fuzz();
10958 v8::Isolate* isolate = CcTest::isolate(); 11160 v8::Isolate* isolate = CcTest::isolate();
10959 CHECK_EQ(isolate, info.GetIsolate()); 11161 CHECK_EQ(isolate, info.GetIsolate());
10960 CHECK_EQ(v8_str("data"), info.Data()); 11162 CHECK_EQ(v8_str("data"), info.Data());
10961 CHECK_EQ(v8_str("x"), name); 11163 CHECK_EQ(v8_str("x"), name);
10962 info.GetReturnValue().Set(v8::Integer::New(42)); 11164 info.GetReturnValue().Set(v8::Integer::New(isolate, 42));
10963 } 11165 }
10964 11166
10965 11167
10966 // This test should hit the load IC for the interceptor case. 11168 // This test should hit the load IC for the interceptor case.
10967 THREADED_TEST(InterceptorLoadIC) { 11169 THREADED_TEST(InterceptorLoadIC) {
10968 CheckInterceptorLoadIC(InterceptorLoadICGetter, 11170 CheckInterceptorLoadIC(InterceptorLoadICGetter,
10969 "var result = 0;" 11171 "var result = 0;"
10970 "for (var i = 0; i < 1000; i++) {" 11172 "for (var i = 0; i < 1000; i++) {"
10971 " result = o.x;" 11173 " result = o.x;"
10972 "}", 11174 "}",
10973 42); 11175 42);
10974 } 11176 }
10975 11177
10976 11178
10977 // Below go several tests which verify that JITing for various 11179 // Below go several tests which verify that JITing for various
10978 // configurations of interceptor and explicit fields works fine 11180 // configurations of interceptor and explicit fields works fine
10979 // (those cases are special cased to get better performance). 11181 // (those cases are special cased to get better performance).
10980 11182
10981 static void InterceptorLoadXICGetter( 11183 static void InterceptorLoadXICGetter(
10982 Local<String> name, 11184 Local<String> name,
10983 const v8::PropertyCallbackInfo<v8::Value>& info) { 11185 const v8::PropertyCallbackInfo<v8::Value>& info) {
10984 ApiTestFuzzer::Fuzz(); 11186 ApiTestFuzzer::Fuzz();
10985 info.GetReturnValue().Set( 11187 info.GetReturnValue().Set(
10986 v8_str("x")->Equals(name) ? 11188 v8_str("x")->Equals(name) ?
10987 v8::Handle<v8::Value>(v8::Integer::New(42)) : 11189 v8::Handle<v8::Value>(v8::Integer::New(info.GetIsolate(), 42)) :
10988 v8::Handle<v8::Value>()); 11190 v8::Handle<v8::Value>());
10989 } 11191 }
10990 11192
10991 11193
10992 THREADED_TEST(InterceptorLoadICWithFieldOnHolder) { 11194 THREADED_TEST(InterceptorLoadICWithFieldOnHolder) {
10993 CheckInterceptorLoadIC(InterceptorLoadXICGetter, 11195 CheckInterceptorLoadIC(InterceptorLoadXICGetter,
10994 "var result = 0;" 11196 "var result = 0;"
10995 "o.y = 239;" 11197 "o.y = 239;"
10996 "for (var i = 0; i < 1000; i++) {" 11198 "for (var i = 0; i < 1000; i++) {"
10997 " result = o.y;" 11199 " result = o.y;"
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
11147 11349
11148 11350
11149 static void SetOnThis(Local<String> name, 11351 static void SetOnThis(Local<String> name,
11150 Local<Value> value, 11352 Local<Value> value,
11151 const v8::PropertyCallbackInfo<void>& info) { 11353 const v8::PropertyCallbackInfo<void>& info) {
11152 info.This()->ForceSet(name, value); 11354 info.This()->ForceSet(name, value);
11153 } 11355 }
11154 11356
11155 11357
11156 THREADED_TEST(InterceptorLoadICWithCallbackOnHolder) { 11358 THREADED_TEST(InterceptorLoadICWithCallbackOnHolder) {
11157 v8::HandleScope scope(CcTest::isolate()); 11359 v8::Isolate* isolate = CcTest::isolate();
11158 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 11360 v8::HandleScope scope(isolate);
11361 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate);
11159 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter); 11362 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter);
11160 templ->SetAccessor(v8_str("y"), Return239Callback); 11363 templ->SetAccessor(v8_str("y"), Return239Callback);
11161 LocalContext context; 11364 LocalContext context;
11162 context->Global()->Set(v8_str("o"), templ->NewInstance()); 11365 context->Global()->Set(v8_str("o"), templ->NewInstance());
11163 11366
11164 // Check the case when receiver and interceptor's holder 11367 // Check the case when receiver and interceptor's holder
11165 // are the same objects. 11368 // are the same objects.
11166 v8::Handle<Value> value = CompileRun( 11369 v8::Handle<Value> value = CompileRun(
11167 "var result = 0;" 11370 "var result = 0;"
11168 "for (var i = 0; i < 7; i++) {" 11371 "for (var i = 0; i < 7; i++) {"
11169 " result = o.y;" 11372 " result = o.y;"
11170 "}"); 11373 "}");
11171 CHECK_EQ(239, value->Int32Value()); 11374 CHECK_EQ(239, value->Int32Value());
11172 11375
11173 // Check the case when interceptor's holder is in proto chain 11376 // Check the case when interceptor's holder is in proto chain
11174 // of receiver. 11377 // of receiver.
11175 value = CompileRun( 11378 value = CompileRun(
11176 "r = { __proto__: o };" 11379 "r = { __proto__: o };"
11177 "var result = 0;" 11380 "var result = 0;"
11178 "for (var i = 0; i < 7; i++) {" 11381 "for (var i = 0; i < 7; i++) {"
11179 " result = r.y;" 11382 " result = r.y;"
11180 "}"); 11383 "}");
11181 CHECK_EQ(239, value->Int32Value()); 11384 CHECK_EQ(239, value->Int32Value());
11182 } 11385 }
11183 11386
11184 11387
11185 THREADED_TEST(InterceptorLoadICWithCallbackOnProto) { 11388 THREADED_TEST(InterceptorLoadICWithCallbackOnProto) {
11186 v8::HandleScope scope(CcTest::isolate()); 11389 v8::Isolate* isolate = CcTest::isolate();
11187 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); 11390 v8::HandleScope scope(isolate);
11391 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate);
11188 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter); 11392 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter);
11189 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(); 11393 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(isolate);
11190 templ_p->SetAccessor(v8_str("y"), Return239Callback); 11394 templ_p->SetAccessor(v8_str("y"), Return239Callback);
11191 11395
11192 LocalContext context; 11396 LocalContext context;
11193 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); 11397 context->Global()->Set(v8_str("o"), templ_o->NewInstance());
11194 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); 11398 context->Global()->Set(v8_str("p"), templ_p->NewInstance());
11195 11399
11196 // Check the case when receiver and interceptor's holder 11400 // Check the case when receiver and interceptor's holder
11197 // are the same objects. 11401 // are the same objects.
11198 v8::Handle<Value> value = CompileRun( 11402 v8::Handle<Value> value = CompileRun(
11199 "o.__proto__ = p;" 11403 "o.__proto__ = p;"
11200 "var result = 0;" 11404 "var result = 0;"
11201 "for (var i = 0; i < 7; i++) {" 11405 "for (var i = 0; i < 7; i++) {"
11202 " result = o.x + o.y;" 11406 " result = o.x + o.y;"
11203 "}"); 11407 "}");
11204 CHECK_EQ(239 + 42, value->Int32Value()); 11408 CHECK_EQ(239 + 42, value->Int32Value());
11205 11409
11206 // Check the case when interceptor's holder is in proto chain 11410 // Check the case when interceptor's holder is in proto chain
11207 // of receiver. 11411 // of receiver.
11208 value = CompileRun( 11412 value = CompileRun(
11209 "r = { __proto__: o };" 11413 "r = { __proto__: o };"
11210 "var result = 0;" 11414 "var result = 0;"
11211 "for (var i = 0; i < 7; i++) {" 11415 "for (var i = 0; i < 7; i++) {"
11212 " result = r.x + r.y;" 11416 " result = r.x + r.y;"
11213 "}"); 11417 "}");
11214 CHECK_EQ(239 + 42, value->Int32Value()); 11418 CHECK_EQ(239 + 42, value->Int32Value());
11215 } 11419 }
11216 11420
11217 11421
11218 THREADED_TEST(InterceptorLoadICForCallbackWithOverride) { 11422 THREADED_TEST(InterceptorLoadICForCallbackWithOverride) {
11219 v8::HandleScope scope(CcTest::isolate()); 11423 v8::Isolate* isolate = CcTest::isolate();
11220 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 11424 v8::HandleScope scope(isolate);
11425 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate);
11221 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter); 11426 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter);
11222 templ->SetAccessor(v8_str("y"), Return239Callback); 11427 templ->SetAccessor(v8_str("y"), Return239Callback);
11223 11428
11224 LocalContext context; 11429 LocalContext context;
11225 context->Global()->Set(v8_str("o"), templ->NewInstance()); 11430 context->Global()->Set(v8_str("o"), templ->NewInstance());
11226 11431
11227 v8::Handle<Value> value = CompileRun( 11432 v8::Handle<Value> value = CompileRun(
11228 "fst = new Object(); fst.__proto__ = o;" 11433 "fst = new Object(); fst.__proto__ = o;"
11229 "snd = new Object(); snd.__proto__ = fst;" 11434 "snd = new Object(); snd.__proto__ = fst;"
11230 "var result1 = 0;" 11435 "var result1 = 0;"
11231 "for (var i = 0; i < 7; i++) {" 11436 "for (var i = 0; i < 7; i++) {"
11232 " result1 = snd.x;" 11437 " result1 = snd.x;"
11233 "}" 11438 "}"
11234 "fst.x = 239;" 11439 "fst.x = 239;"
11235 "var result = 0;" 11440 "var result = 0;"
11236 "for (var i = 0; i < 7; i++) {" 11441 "for (var i = 0; i < 7; i++) {"
11237 " result = snd.x;" 11442 " result = snd.x;"
11238 "}" 11443 "}"
11239 "result + result1"); 11444 "result + result1");
11240 CHECK_EQ(239 + 42, value->Int32Value()); 11445 CHECK_EQ(239 + 42, value->Int32Value());
11241 } 11446 }
11242 11447
11243 11448
11244 // Test the case when we stored callback into 11449 // Test the case when we stored callback into
11245 // a stub, but interceptor produced value on its own. 11450 // a stub, but interceptor produced value on its own.
11246 THREADED_TEST(InterceptorLoadICCallbackNotNeeded) { 11451 THREADED_TEST(InterceptorLoadICCallbackNotNeeded) {
11247 v8::HandleScope scope(CcTest::isolate()); 11452 v8::Isolate* isolate = CcTest::isolate();
11248 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); 11453 v8::HandleScope scope(isolate);
11454 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate);
11249 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter); 11455 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter);
11250 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(); 11456 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(isolate);
11251 templ_p->SetAccessor(v8_str("y"), Return239Callback); 11457 templ_p->SetAccessor(v8_str("y"), Return239Callback);
11252 11458
11253 LocalContext context; 11459 LocalContext context;
11254 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); 11460 context->Global()->Set(v8_str("o"), templ_o->NewInstance());
11255 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); 11461 context->Global()->Set(v8_str("p"), templ_p->NewInstance());
11256 11462
11257 v8::Handle<Value> value = CompileRun( 11463 v8::Handle<Value> value = CompileRun(
11258 "o.__proto__ = p;" 11464 "o.__proto__ = p;"
11259 "for (var i = 0; i < 7; i++) {" 11465 "for (var i = 0; i < 7; i++) {"
11260 " o.x;" 11466 " o.x;"
11261 // Now it should be ICed and keep a reference to x defined on p 11467 // Now it should be ICed and keep a reference to x defined on p
11262 "}" 11468 "}"
11263 "var result = 0;" 11469 "var result = 0;"
11264 "for (var i = 0; i < 7; i++) {" 11470 "for (var i = 0; i < 7; i++) {"
11265 " result += o.x;" 11471 " result += o.x;"
11266 "}" 11472 "}"
11267 "result"); 11473 "result");
11268 CHECK_EQ(42 * 7, value->Int32Value()); 11474 CHECK_EQ(42 * 7, value->Int32Value());
11269 } 11475 }
11270 11476
11271 11477
11272 // Test the case when we stored callback into 11478 // Test the case when we stored callback into
11273 // a stub, but it got invalidated later on. 11479 // a stub, but it got invalidated later on.
11274 THREADED_TEST(InterceptorLoadICInvalidatedCallback) { 11480 THREADED_TEST(InterceptorLoadICInvalidatedCallback) {
11275 v8::HandleScope scope(CcTest::isolate()); 11481 v8::Isolate* isolate = CcTest::isolate();
11276 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); 11482 v8::HandleScope scope(isolate);
11483 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate);
11277 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter); 11484 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter);
11278 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(); 11485 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(isolate);
11279 templ_p->SetAccessor(v8_str("y"), Return239Callback, SetOnThis); 11486 templ_p->SetAccessor(v8_str("y"), Return239Callback, SetOnThis);
11280 11487
11281 LocalContext context; 11488 LocalContext context;
11282 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); 11489 context->Global()->Set(v8_str("o"), templ_o->NewInstance());
11283 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); 11490 context->Global()->Set(v8_str("p"), templ_p->NewInstance());
11284 11491
11285 v8::Handle<Value> value = CompileRun( 11492 v8::Handle<Value> value = CompileRun(
11286 "inbetween = new Object();" 11493 "inbetween = new Object();"
11287 "o.__proto__ = inbetween;" 11494 "o.__proto__ = inbetween;"
11288 "inbetween.__proto__ = p;" 11495 "inbetween.__proto__ = p;"
11289 "for (var i = 0; i < 10; i++) {" 11496 "for (var i = 0; i < 10; i++) {"
11290 " o.y;" 11497 " o.y;"
11291 // Now it should be ICed and keep a reference to y defined on p 11498 // Now it should be ICed and keep a reference to y defined on p
11292 "}" 11499 "}"
11293 "inbetween.y = 42;" 11500 "inbetween.y = 42;"
11294 "var result = 0;" 11501 "var result = 0;"
11295 "for (var i = 0; i < 10; i++) {" 11502 "for (var i = 0; i < 10; i++) {"
11296 " result += o.y;" 11503 " result += o.y;"
11297 "}" 11504 "}"
11298 "result"); 11505 "result");
11299 CHECK_EQ(42 * 10, value->Int32Value()); 11506 CHECK_EQ(42 * 10, value->Int32Value());
11300 } 11507 }
11301 11508
11302 11509
11303 // Test the case when we stored callback into 11510 // Test the case when we stored callback into
11304 // a stub, but it got invalidated later on due to override on 11511 // a stub, but it got invalidated later on due to override on
11305 // global object which is between interceptor and callbacks' holders. 11512 // global object which is between interceptor and callbacks' holders.
11306 THREADED_TEST(InterceptorLoadICInvalidatedCallbackViaGlobal) { 11513 THREADED_TEST(InterceptorLoadICInvalidatedCallbackViaGlobal) {
11307 v8::HandleScope scope(CcTest::isolate()); 11514 v8::Isolate* isolate = CcTest::isolate();
11308 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); 11515 v8::HandleScope scope(isolate);
11516 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate);
11309 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter); 11517 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter);
11310 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(); 11518 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(isolate);
11311 templ_p->SetAccessor(v8_str("y"), Return239Callback, SetOnThis); 11519 templ_p->SetAccessor(v8_str("y"), Return239Callback, SetOnThis);
11312 11520
11313 LocalContext context; 11521 LocalContext context;
11314 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); 11522 context->Global()->Set(v8_str("o"), templ_o->NewInstance());
11315 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); 11523 context->Global()->Set(v8_str("p"), templ_p->NewInstance());
11316 11524
11317 v8::Handle<Value> value = CompileRun( 11525 v8::Handle<Value> value = CompileRun(
11318 "o.__proto__ = this;" 11526 "o.__proto__ = this;"
11319 "this.__proto__ = p;" 11527 "this.__proto__ = p;"
11320 "for (var i = 0; i < 10; i++) {" 11528 "for (var i = 0; i < 10; i++) {"
11321 " if (o.y != 239) throw 'oops: ' + o.y;" 11529 " if (o.y != 239) throw 'oops: ' + o.y;"
11322 // Now it should be ICed and keep a reference to y defined on p 11530 // Now it should be ICed and keep a reference to y defined on p
11323 "}" 11531 "}"
11324 "this.y = 42;" 11532 "this.y = 42;"
11325 "var result = 0;" 11533 "var result = 0;"
11326 "for (var i = 0; i < 10; i++) {" 11534 "for (var i = 0; i < 10; i++) {"
11327 " result += o.y;" 11535 " result += o.y;"
11328 "}" 11536 "}"
11329 "result"); 11537 "result");
11330 CHECK_EQ(42 * 10, value->Int32Value()); 11538 CHECK_EQ(42 * 10, value->Int32Value());
11331 } 11539 }
11332 11540
11333 11541
11334 static void InterceptorLoadICGetter0( 11542 static void InterceptorLoadICGetter0(
11335 Local<String> name, 11543 Local<String> name,
11336 const v8::PropertyCallbackInfo<v8::Value>& info) { 11544 const v8::PropertyCallbackInfo<v8::Value>& info) {
11337 ApiTestFuzzer::Fuzz(); 11545 ApiTestFuzzer::Fuzz();
11338 CHECK(v8_str("x")->Equals(name)); 11546 CHECK(v8_str("x")->Equals(name));
11339 info.GetReturnValue().Set(v8::Integer::New(0)); 11547 info.GetReturnValue().Set(v8::Integer::New(info.GetIsolate(), 0));
11340 } 11548 }
11341 11549
11342 11550
11343 THREADED_TEST(InterceptorReturningZero) { 11551 THREADED_TEST(InterceptorReturningZero) {
11344 CheckInterceptorLoadIC(InterceptorLoadICGetter0, 11552 CheckInterceptorLoadIC(InterceptorLoadICGetter0,
11345 "o.x == undefined ? 1 : 0", 11553 "o.x == undefined ? 1 : 0",
11346 0); 11554 0);
11347 } 11555 }
11348 11556
11349 11557
11350 static void InterceptorStoreICSetter( 11558 static void InterceptorStoreICSetter(
11351 Local<String> key, 11559 Local<String> key,
11352 Local<Value> value, 11560 Local<Value> value,
11353 const v8::PropertyCallbackInfo<v8::Value>& info) { 11561 const v8::PropertyCallbackInfo<v8::Value>& info) {
11354 CHECK(v8_str("x")->Equals(key)); 11562 CHECK(v8_str("x")->Equals(key));
11355 CHECK_EQ(42, value->Int32Value()); 11563 CHECK_EQ(42, value->Int32Value());
11356 info.GetReturnValue().Set(value); 11564 info.GetReturnValue().Set(value);
11357 } 11565 }
11358 11566
11359 11567
11360 // This test should hit the store IC for the interceptor case. 11568 // This test should hit the store IC for the interceptor case.
11361 THREADED_TEST(InterceptorStoreIC) { 11569 THREADED_TEST(InterceptorStoreIC) {
11362 v8::HandleScope scope(CcTest::isolate()); 11570 v8::Isolate* isolate = CcTest::isolate();
11363 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 11571 v8::HandleScope scope(isolate);
11572 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate);
11364 templ->SetNamedPropertyHandler(InterceptorLoadICGetter, 11573 templ->SetNamedPropertyHandler(InterceptorLoadICGetter,
11365 InterceptorStoreICSetter, 11574 InterceptorStoreICSetter,
11366 0, 0, 0, v8_str("data")); 11575 0, 0, 0, v8_str("data"));
11367 LocalContext context; 11576 LocalContext context;
11368 context->Global()->Set(v8_str("o"), templ->NewInstance()); 11577 context->Global()->Set(v8_str("o"), templ->NewInstance());
11369 CompileRun( 11578 CompileRun(
11370 "for (var i = 0; i < 1000; i++) {" 11579 "for (var i = 0; i < 1000; i++) {"
11371 " o.x = 42;" 11580 " o.x = 42;"
11372 "}"); 11581 "}");
11373 } 11582 }
11374 11583
11375 11584
11376 THREADED_TEST(InterceptorStoreICWithNoSetter) { 11585 THREADED_TEST(InterceptorStoreICWithNoSetter) {
11377 v8::HandleScope scope(CcTest::isolate()); 11586 v8::Isolate* isolate = CcTest::isolate();
11378 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 11587 v8::HandleScope scope(isolate);
11588 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate);
11379 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter); 11589 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter);
11380 LocalContext context; 11590 LocalContext context;
11381 context->Global()->Set(v8_str("o"), templ->NewInstance()); 11591 context->Global()->Set(v8_str("o"), templ->NewInstance());
11382 v8::Handle<Value> value = CompileRun( 11592 v8::Handle<Value> value = CompileRun(
11383 "for (var i = 0; i < 1000; i++) {" 11593 "for (var i = 0; i < 1000; i++) {"
11384 " o.y = 239;" 11594 " o.y = 239;"
11385 "}" 11595 "}"
11386 "42 + o.y"); 11596 "42 + o.y");
11387 CHECK_EQ(239 + 42, value->Int32Value()); 11597 CHECK_EQ(239 + 42, value->Int32Value());
11388 } 11598 }
11389 11599
11390 11600
11391 11601
11392 11602
11393 v8::Handle<Value> call_ic_function; 11603 v8::Handle<Value> call_ic_function;
11394 v8::Handle<Value> call_ic_function2; 11604 v8::Handle<Value> call_ic_function2;
11395 v8::Handle<Value> call_ic_function3; 11605 v8::Handle<Value> call_ic_function3;
11396 11606
11397 static void InterceptorCallICGetter( 11607 static void InterceptorCallICGetter(
11398 Local<String> name, 11608 Local<String> name,
11399 const v8::PropertyCallbackInfo<v8::Value>& info) { 11609 const v8::PropertyCallbackInfo<v8::Value>& info) {
11400 ApiTestFuzzer::Fuzz(); 11610 ApiTestFuzzer::Fuzz();
11401 CHECK(v8_str("x")->Equals(name)); 11611 CHECK(v8_str("x")->Equals(name));
11402 info.GetReturnValue().Set(call_ic_function); 11612 info.GetReturnValue().Set(call_ic_function);
11403 } 11613 }
11404 11614
11405 11615
11406 // This test should hit the call IC for the interceptor case. 11616 // This test should hit the call IC for the interceptor case.
11407 THREADED_TEST(InterceptorCallIC) { 11617 THREADED_TEST(InterceptorCallIC) {
11408 v8::HandleScope scope(CcTest::isolate()); 11618 v8::Isolate* isolate = CcTest::isolate();
11409 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 11619 v8::HandleScope scope(isolate);
11620 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate);
11410 templ->SetNamedPropertyHandler(InterceptorCallICGetter); 11621 templ->SetNamedPropertyHandler(InterceptorCallICGetter);
11411 LocalContext context; 11622 LocalContext context;
11412 context->Global()->Set(v8_str("o"), templ->NewInstance()); 11623 context->Global()->Set(v8_str("o"), templ->NewInstance());
11413 call_ic_function = 11624 call_ic_function =
11414 v8_compile("function f(x) { return x + 1; }; f")->Run(); 11625 v8_compile("function f(x) { return x + 1; }; f")->Run();
11415 v8::Handle<Value> value = CompileRun( 11626 v8::Handle<Value> value = CompileRun(
11416 "var result = 0;" 11627 "var result = 0;"
11417 "for (var i = 0; i < 1000; i++) {" 11628 "for (var i = 0; i < 1000; i++) {"
11418 " result = o.x(41);" 11629 " result = o.x(41);"
11419 "}"); 11630 "}");
11420 CHECK_EQ(42, value->Int32Value()); 11631 CHECK_EQ(42, value->Int32Value());
11421 } 11632 }
11422 11633
11423 11634
11424 // This test checks that if interceptor doesn't provide 11635 // This test checks that if interceptor doesn't provide
11425 // a value, we can fetch regular value. 11636 // a value, we can fetch regular value.
11426 THREADED_TEST(InterceptorCallICSeesOthers) { 11637 THREADED_TEST(InterceptorCallICSeesOthers) {
11427 v8::HandleScope scope(CcTest::isolate()); 11638 v8::Isolate* isolate = CcTest::isolate();
11428 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 11639 v8::HandleScope scope(isolate);
11640 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate);
11429 templ->SetNamedPropertyHandler(NoBlockGetterX); 11641 templ->SetNamedPropertyHandler(NoBlockGetterX);
11430 LocalContext context; 11642 LocalContext context;
11431 context->Global()->Set(v8_str("o"), templ->NewInstance()); 11643 context->Global()->Set(v8_str("o"), templ->NewInstance());
11432 v8::Handle<Value> value = CompileRun( 11644 v8::Handle<Value> value = CompileRun(
11433 "o.x = function f(x) { return x + 1; };" 11645 "o.x = function f(x) { return x + 1; };"
11434 "var result = 0;" 11646 "var result = 0;"
11435 "for (var i = 0; i < 7; i++) {" 11647 "for (var i = 0; i < 7; i++) {"
11436 " result = o.x(41);" 11648 " result = o.x(41);"
11437 "}"); 11649 "}");
11438 CHECK_EQ(42, value->Int32Value()); 11650 CHECK_EQ(42, value->Int32Value());
11439 } 11651 }
11440 11652
11441 11653
11442 static v8::Handle<Value> call_ic_function4; 11654 static v8::Handle<Value> call_ic_function4;
11443 static void InterceptorCallICGetter4( 11655 static void InterceptorCallICGetter4(
11444 Local<String> name, 11656 Local<String> name,
11445 const v8::PropertyCallbackInfo<v8::Value>& info) { 11657 const v8::PropertyCallbackInfo<v8::Value>& info) {
11446 ApiTestFuzzer::Fuzz(); 11658 ApiTestFuzzer::Fuzz();
11447 CHECK(v8_str("x")->Equals(name)); 11659 CHECK(v8_str("x")->Equals(name));
11448 info.GetReturnValue().Set(call_ic_function4); 11660 info.GetReturnValue().Set(call_ic_function4);
11449 } 11661 }
11450 11662
11451 11663
11452 // This test checks that if interceptor provides a function, 11664 // This test checks that if interceptor provides a function,
11453 // even if we cached shadowed variant, interceptor's function 11665 // even if we cached shadowed variant, interceptor's function
11454 // is invoked 11666 // is invoked
11455 THREADED_TEST(InterceptorCallICCacheableNotNeeded) { 11667 THREADED_TEST(InterceptorCallICCacheableNotNeeded) {
11456 v8::HandleScope scope(CcTest::isolate()); 11668 v8::Isolate* isolate = CcTest::isolate();
11457 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 11669 v8::HandleScope scope(isolate);
11670 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate);
11458 templ->SetNamedPropertyHandler(InterceptorCallICGetter4); 11671 templ->SetNamedPropertyHandler(InterceptorCallICGetter4);
11459 LocalContext context; 11672 LocalContext context;
11460 context->Global()->Set(v8_str("o"), templ->NewInstance()); 11673 context->Global()->Set(v8_str("o"), templ->NewInstance());
11461 call_ic_function4 = 11674 call_ic_function4 =
11462 v8_compile("function f(x) { return x - 1; }; f")->Run(); 11675 v8_compile("function f(x) { return x - 1; }; f")->Run();
11463 v8::Handle<Value> value = CompileRun( 11676 v8::Handle<Value> value = CompileRun(
11464 "Object.getPrototypeOf(o).x = function(x) { return x + 1; };" 11677 "Object.getPrototypeOf(o).x = function(x) { return x + 1; };"
11465 "var result = 0;" 11678 "var result = 0;"
11466 "for (var i = 0; i < 1000; i++) {" 11679 "for (var i = 0; i < 1000; i++) {"
11467 " result = o.x(42);" 11680 " result = o.x(42);"
11468 "}"); 11681 "}");
11469 CHECK_EQ(41, value->Int32Value()); 11682 CHECK_EQ(41, value->Int32Value());
11470 } 11683 }
11471 11684
11472 11685
11473 // Test the case when we stored cacheable lookup into 11686 // Test the case when we stored cacheable lookup into
11474 // a stub, but it got invalidated later on 11687 // a stub, but it got invalidated later on
11475 THREADED_TEST(InterceptorCallICInvalidatedCacheable) { 11688 THREADED_TEST(InterceptorCallICInvalidatedCacheable) {
11476 v8::HandleScope scope(CcTest::isolate()); 11689 v8::Isolate* isolate = CcTest::isolate();
11477 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 11690 v8::HandleScope scope(isolate);
11691 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate);
11478 templ->SetNamedPropertyHandler(NoBlockGetterX); 11692 templ->SetNamedPropertyHandler(NoBlockGetterX);
11479 LocalContext context; 11693 LocalContext context;
11480 context->Global()->Set(v8_str("o"), templ->NewInstance()); 11694 context->Global()->Set(v8_str("o"), templ->NewInstance());
11481 v8::Handle<Value> value = CompileRun( 11695 v8::Handle<Value> value = CompileRun(
11482 "proto1 = new Object();" 11696 "proto1 = new Object();"
11483 "proto2 = new Object();" 11697 "proto2 = new Object();"
11484 "o.__proto__ = proto1;" 11698 "o.__proto__ = proto1;"
11485 "proto1.__proto__ = proto2;" 11699 "proto1.__proto__ = proto2;"
11486 "proto2.y = function(x) { return x + 1; };" 11700 "proto2.y = function(x) { return x + 1; };"
11487 // Invoke it many times to compile a stub 11701 // Invoke it many times to compile a stub
11488 "for (var i = 0; i < 7; i++) {" 11702 "for (var i = 0; i < 7; i++) {"
11489 " o.y(42);" 11703 " o.y(42);"
11490 "}" 11704 "}"
11491 "proto1.y = function(x) { return x - 1; };" 11705 "proto1.y = function(x) { return x - 1; };"
11492 "var result = 0;" 11706 "var result = 0;"
11493 "for (var i = 0; i < 7; i++) {" 11707 "for (var i = 0; i < 7; i++) {"
11494 " result += o.y(42);" 11708 " result += o.y(42);"
11495 "}"); 11709 "}");
11496 CHECK_EQ(41 * 7, value->Int32Value()); 11710 CHECK_EQ(41 * 7, value->Int32Value());
11497 } 11711 }
11498 11712
11499 11713
11500 // This test checks that if interceptor doesn't provide a function, 11714 // This test checks that if interceptor doesn't provide a function,
11501 // cached constant function is used 11715 // cached constant function is used
11502 THREADED_TEST(InterceptorCallICConstantFunctionUsed) { 11716 THREADED_TEST(InterceptorCallICConstantFunctionUsed) {
11503 v8::HandleScope scope(CcTest::isolate()); 11717 v8::Isolate* isolate = CcTest::isolate();
11504 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 11718 v8::HandleScope scope(isolate);
11719 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate);
11505 templ->SetNamedPropertyHandler(NoBlockGetterX); 11720 templ->SetNamedPropertyHandler(NoBlockGetterX);
11506 LocalContext context; 11721 LocalContext context;
11507 context->Global()->Set(v8_str("o"), templ->NewInstance()); 11722 context->Global()->Set(v8_str("o"), templ->NewInstance());
11508 v8::Handle<Value> value = CompileRun( 11723 v8::Handle<Value> value = CompileRun(
11509 "function inc(x) { return x + 1; };" 11724 "function inc(x) { return x + 1; };"
11510 "inc(1);" 11725 "inc(1);"
11511 "o.x = inc;" 11726 "o.x = inc;"
11512 "var result = 0;" 11727 "var result = 0;"
11513 "for (var i = 0; i < 1000; i++) {" 11728 "for (var i = 0; i < 1000; i++) {"
11514 " result = o.x(42);" 11729 " result = o.x(42);"
11515 "}"); 11730 "}");
11516 CHECK_EQ(43, value->Int32Value()); 11731 CHECK_EQ(43, value->Int32Value());
11517 } 11732 }
11518 11733
11519 11734
11520 static v8::Handle<Value> call_ic_function5; 11735 static v8::Handle<Value> call_ic_function5;
11521 static void InterceptorCallICGetter5( 11736 static void InterceptorCallICGetter5(
11522 Local<String> name, 11737 Local<String> name,
11523 const v8::PropertyCallbackInfo<v8::Value>& info) { 11738 const v8::PropertyCallbackInfo<v8::Value>& info) {
11524 ApiTestFuzzer::Fuzz(); 11739 ApiTestFuzzer::Fuzz();
11525 if (v8_str("x")->Equals(name)) 11740 if (v8_str("x")->Equals(name))
11526 info.GetReturnValue().Set(call_ic_function5); 11741 info.GetReturnValue().Set(call_ic_function5);
11527 } 11742 }
11528 11743
11529 11744
11530 // This test checks that if interceptor provides a function, 11745 // This test checks that if interceptor provides a function,
11531 // even if we cached constant function, interceptor's function 11746 // even if we cached constant function, interceptor's function
11532 // is invoked 11747 // is invoked
11533 THREADED_TEST(InterceptorCallICConstantFunctionNotNeeded) { 11748 THREADED_TEST(InterceptorCallICConstantFunctionNotNeeded) {
11534 v8::HandleScope scope(CcTest::isolate()); 11749 v8::Isolate* isolate = CcTest::isolate();
11535 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 11750 v8::HandleScope scope(isolate);
11751 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate);
11536 templ->SetNamedPropertyHandler(InterceptorCallICGetter5); 11752 templ->SetNamedPropertyHandler(InterceptorCallICGetter5);
11537 LocalContext context; 11753 LocalContext context;
11538 context->Global()->Set(v8_str("o"), templ->NewInstance()); 11754 context->Global()->Set(v8_str("o"), templ->NewInstance());
11539 call_ic_function5 = 11755 call_ic_function5 =
11540 v8_compile("function f(x) { return x - 1; }; f")->Run(); 11756 v8_compile("function f(x) { return x - 1; }; f")->Run();
11541 v8::Handle<Value> value = CompileRun( 11757 v8::Handle<Value> value = CompileRun(
11542 "function inc(x) { return x + 1; };" 11758 "function inc(x) { return x + 1; };"
11543 "inc(1);" 11759 "inc(1);"
11544 "o.x = inc;" 11760 "o.x = inc;"
11545 "var result = 0;" 11761 "var result = 0;"
(...skipping 11 matching lines...) Expand all
11557 ApiTestFuzzer::Fuzz(); 11773 ApiTestFuzzer::Fuzz();
11558 if (v8_str("x")->Equals(name)) 11774 if (v8_str("x")->Equals(name))
11559 info.GetReturnValue().Set(call_ic_function6); 11775 info.GetReturnValue().Set(call_ic_function6);
11560 } 11776 }
11561 11777
11562 11778
11563 // Same test as above, except the code is wrapped in a function 11779 // Same test as above, except the code is wrapped in a function
11564 // to test the optimized compiler. 11780 // to test the optimized compiler.
11565 THREADED_TEST(InterceptorCallICConstantFunctionNotNeededWrapped) { 11781 THREADED_TEST(InterceptorCallICConstantFunctionNotNeededWrapped) {
11566 i::FLAG_allow_natives_syntax = true; 11782 i::FLAG_allow_natives_syntax = true;
11567 v8::HandleScope scope(CcTest::isolate()); 11783 v8::Isolate* isolate = CcTest::isolate();
11568 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 11784 v8::HandleScope scope(isolate);
11785 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate);
11569 templ->SetNamedPropertyHandler(InterceptorCallICGetter6); 11786 templ->SetNamedPropertyHandler(InterceptorCallICGetter6);
11570 LocalContext context; 11787 LocalContext context;
11571 context->Global()->Set(v8_str("o"), templ->NewInstance()); 11788 context->Global()->Set(v8_str("o"), templ->NewInstance());
11572 call_ic_function6 = 11789 call_ic_function6 =
11573 v8_compile("function f(x) { return x - 1; }; f")->Run(); 11790 v8_compile("function f(x) { return x - 1; }; f")->Run();
11574 v8::Handle<Value> value = CompileRun( 11791 v8::Handle<Value> value = CompileRun(
11575 "function inc(x) { return x + 1; };" 11792 "function inc(x) { return x + 1; };"
11576 "inc(1);" 11793 "inc(1);"
11577 "o.x = inc;" 11794 "o.x = inc;"
11578 "function test() {" 11795 "function test() {"
11579 " var result = 0;" 11796 " var result = 0;"
11580 " for (var i = 0; i < 1000; i++) {" 11797 " for (var i = 0; i < 1000; i++) {"
11581 " result = o.x(42);" 11798 " result = o.x(42);"
11582 " }" 11799 " }"
11583 " return result;" 11800 " return result;"
11584 "};" 11801 "};"
11585 "test();" 11802 "test();"
11586 "test();" 11803 "test();"
11587 "test();" 11804 "test();"
11588 "%OptimizeFunctionOnNextCall(test);" 11805 "%OptimizeFunctionOnNextCall(test);"
11589 "test()"); 11806 "test()");
11590 CHECK_EQ(41, value->Int32Value()); 11807 CHECK_EQ(41, value->Int32Value());
11591 } 11808 }
11592 11809
11593 11810
11594 // Test the case when we stored constant function into 11811 // Test the case when we stored constant function into
11595 // a stub, but it got invalidated later on 11812 // a stub, but it got invalidated later on
11596 THREADED_TEST(InterceptorCallICInvalidatedConstantFunction) { 11813 THREADED_TEST(InterceptorCallICInvalidatedConstantFunction) {
11597 v8::HandleScope scope(CcTest::isolate()); 11814 v8::Isolate* isolate = CcTest::isolate();
11598 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 11815 v8::HandleScope scope(isolate);
11816 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate);
11599 templ->SetNamedPropertyHandler(NoBlockGetterX); 11817 templ->SetNamedPropertyHandler(NoBlockGetterX);
11600 LocalContext context; 11818 LocalContext context;
11601 context->Global()->Set(v8_str("o"), templ->NewInstance()); 11819 context->Global()->Set(v8_str("o"), templ->NewInstance());
11602 v8::Handle<Value> value = CompileRun( 11820 v8::Handle<Value> value = CompileRun(
11603 "function inc(x) { return x + 1; };" 11821 "function inc(x) { return x + 1; };"
11604 "inc(1);" 11822 "inc(1);"
11605 "proto1 = new Object();" 11823 "proto1 = new Object();"
11606 "proto2 = new Object();" 11824 "proto2 = new Object();"
11607 "o.__proto__ = proto1;" 11825 "o.__proto__ = proto1;"
11608 "proto1.__proto__ = proto2;" 11826 "proto1.__proto__ = proto2;"
11609 "proto2.y = inc;" 11827 "proto2.y = inc;"
11610 // Invoke it many times to compile a stub 11828 // Invoke it many times to compile a stub
11611 "for (var i = 0; i < 7; i++) {" 11829 "for (var i = 0; i < 7; i++) {"
11612 " o.y(42);" 11830 " o.y(42);"
11613 "}" 11831 "}"
11614 "proto1.y = function(x) { return x - 1; };" 11832 "proto1.y = function(x) { return x - 1; };"
11615 "var result = 0;" 11833 "var result = 0;"
11616 "for (var i = 0; i < 7; i++) {" 11834 "for (var i = 0; i < 7; i++) {"
11617 " result += o.y(42);" 11835 " result += o.y(42);"
11618 "}"); 11836 "}");
11619 CHECK_EQ(41 * 7, value->Int32Value()); 11837 CHECK_EQ(41 * 7, value->Int32Value());
11620 } 11838 }
11621 11839
11622 11840
11623 // Test the case when we stored constant function into 11841 // Test the case when we stored constant function into
11624 // a stub, but it got invalidated later on due to override on 11842 // a stub, but it got invalidated later on due to override on
11625 // global object which is between interceptor and constant function' holders. 11843 // global object which is between interceptor and constant function' holders.
11626 THREADED_TEST(InterceptorCallICInvalidatedConstantFunctionViaGlobal) { 11844 THREADED_TEST(InterceptorCallICInvalidatedConstantFunctionViaGlobal) {
11627 v8::HandleScope scope(CcTest::isolate()); 11845 v8::Isolate* isolate = CcTest::isolate();
11628 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 11846 v8::HandleScope scope(isolate);
11847 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate);
11629 templ->SetNamedPropertyHandler(NoBlockGetterX); 11848 templ->SetNamedPropertyHandler(NoBlockGetterX);
11630 LocalContext context; 11849 LocalContext context;
11631 context->Global()->Set(v8_str("o"), templ->NewInstance()); 11850 context->Global()->Set(v8_str("o"), templ->NewInstance());
11632 v8::Handle<Value> value = CompileRun( 11851 v8::Handle<Value> value = CompileRun(
11633 "function inc(x) { return x + 1; };" 11852 "function inc(x) { return x + 1; };"
11634 "inc(1);" 11853 "inc(1);"
11635 "o.__proto__ = this;" 11854 "o.__proto__ = this;"
11636 "this.__proto__.y = inc;" 11855 "this.__proto__.y = inc;"
11637 // Invoke it many times to compile a stub 11856 // Invoke it many times to compile a stub
11638 "for (var i = 0; i < 7; i++) {" 11857 "for (var i = 0; i < 7; i++) {"
11639 " if (o.y(42) != 43) throw 'oops: ' + o.y(42);" 11858 " if (o.y(42) != 43) throw 'oops: ' + o.y(42);"
11640 "}" 11859 "}"
11641 "this.y = function(x) { return x - 1; };" 11860 "this.y = function(x) { return x - 1; };"
11642 "var result = 0;" 11861 "var result = 0;"
11643 "for (var i = 0; i < 7; i++) {" 11862 "for (var i = 0; i < 7; i++) {"
11644 " result += o.y(42);" 11863 " result += o.y(42);"
11645 "}"); 11864 "}");
11646 CHECK_EQ(41 * 7, value->Int32Value()); 11865 CHECK_EQ(41 * 7, value->Int32Value());
11647 } 11866 }
11648 11867
11649 11868
11650 // Test the case when actual function to call sits on global object. 11869 // Test the case when actual function to call sits on global object.
11651 THREADED_TEST(InterceptorCallICCachedFromGlobal) { 11870 THREADED_TEST(InterceptorCallICCachedFromGlobal) {
11652 v8::HandleScope scope(CcTest::isolate()); 11871 v8::Isolate* isolate = CcTest::isolate();
11653 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); 11872 v8::HandleScope scope(isolate);
11873 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate);
11654 templ_o->SetNamedPropertyHandler(NoBlockGetterX); 11874 templ_o->SetNamedPropertyHandler(NoBlockGetterX);
11655 11875
11656 LocalContext context; 11876 LocalContext context;
11657 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); 11877 context->Global()->Set(v8_str("o"), templ_o->NewInstance());
11658 11878
11659 v8::Handle<Value> value = CompileRun( 11879 v8::Handle<Value> value = CompileRun(
11660 "try {" 11880 "try {"
11661 " o.__proto__ = this;" 11881 " o.__proto__ = this;"
11662 " for (var i = 0; i < 10; i++) {" 11882 " for (var i = 0; i < 10; i++) {"
11663 " var v = o.parseFloat('239');" 11883 " var v = o.parseFloat('239');"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
11732 // This should move the stub 11952 // This should move the stub
11733 GenerateSomeGarbage(); // This should ensure the old stub memory is flushed 11953 GenerateSomeGarbage(); // This should ensure the old stub memory is flushed
11734 } 11954 }
11735 } 11955 }
11736 11956
11737 11957
11738 THREADED_TEST(CallICFastApi_DirectCall_GCMoveStub) { 11958 THREADED_TEST(CallICFastApi_DirectCall_GCMoveStub) {
11739 LocalContext context; 11959 LocalContext context;
11740 v8::Isolate* isolate = context->GetIsolate(); 11960 v8::Isolate* isolate = context->GetIsolate();
11741 v8::HandleScope scope(isolate); 11961 v8::HandleScope scope(isolate);
11742 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New(); 11962 v8::Handle<v8::ObjectTemplate> nativeobject_templ =
11963 v8::ObjectTemplate::New(isolate);
11743 nativeobject_templ->Set(isolate, "callback", 11964 nativeobject_templ->Set(isolate, "callback",
11744 v8::FunctionTemplate::New(isolate, 11965 v8::FunctionTemplate::New(isolate,
11745 DirectApiCallback)); 11966 DirectApiCallback));
11746 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance(); 11967 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance();
11747 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj); 11968 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj);
11748 // call the api function multiple times to ensure direct call stub creation. 11969 // call the api function multiple times to ensure direct call stub creation.
11749 CompileRun( 11970 CompileRun(
11750 "function f() {" 11971 "function f() {"
11751 " for (var i = 1; i <= 30; i++) {" 11972 " for (var i = 1; i <= 30; i++) {"
11752 " nativeobject.callback();" 11973 " nativeobject.callback();"
11753 " }" 11974 " }"
11754 "}" 11975 "}"
11755 "f();"); 11976 "f();");
11756 } 11977 }
11757 11978
11758 11979
11759 void ThrowingDirectApiCallback( 11980 void ThrowingDirectApiCallback(
11760 const v8::FunctionCallbackInfo<v8::Value>& args) { 11981 const v8::FunctionCallbackInfo<v8::Value>& args) {
11761 args.GetIsolate()->ThrowException(v8_str("g")); 11982 args.GetIsolate()->ThrowException(v8_str("g"));
11762 } 11983 }
11763 11984
11764 11985
11765 THREADED_TEST(CallICFastApi_DirectCall_Throw) { 11986 THREADED_TEST(CallICFastApi_DirectCall_Throw) {
11766 LocalContext context; 11987 LocalContext context;
11767 v8::Isolate* isolate = context->GetIsolate(); 11988 v8::Isolate* isolate = context->GetIsolate();
11768 v8::HandleScope scope(isolate); 11989 v8::HandleScope scope(isolate);
11769 v8::Handle<v8::ObjectTemplate> nativeobject_templ = 11990 v8::Handle<v8::ObjectTemplate> nativeobject_templ =
11770 v8::ObjectTemplate::New(); 11991 v8::ObjectTemplate::New(isolate);
11771 nativeobject_templ->Set(isolate, "callback", 11992 nativeobject_templ->Set(isolate, "callback",
11772 v8::FunctionTemplate::New(isolate, 11993 v8::FunctionTemplate::New(isolate,
11773 ThrowingDirectApiCallback)); 11994 ThrowingDirectApiCallback));
11774 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance(); 11995 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance();
11775 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj); 11996 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj);
11776 // call the api function multiple times to ensure direct call stub creation. 11997 // call the api function multiple times to ensure direct call stub creation.
11777 v8::Handle<Value> result = CompileRun( 11998 v8::Handle<Value> result = CompileRun(
11778 "var result = '';" 11999 "var result = '';"
11779 "function f() {" 12000 "function f() {"
11780 " for (var i = 1; i <= 5; i++) {" 12001 " for (var i = 1; i <= 5; i++) {"
(...skipping 17 matching lines...) Expand all
11798 Local<String> name, 12019 Local<String> name,
11799 const v8::PropertyCallbackInfo<v8::Value>& info) { 12020 const v8::PropertyCallbackInfo<v8::Value>& info) {
11800 CheckReturnValue(info, FUNCTION_ADDR(DirectGetterCallback)); 12021 CheckReturnValue(info, FUNCTION_ADDR(DirectGetterCallback));
11801 info.GetReturnValue().Set(DoDirectGetter()); 12022 info.GetReturnValue().Set(DoDirectGetter());
11802 } 12023 }
11803 12024
11804 12025
11805 template<typename Accessor> 12026 template<typename Accessor>
11806 static void LoadICFastApi_DirectCall_GCMoveStub(Accessor accessor) { 12027 static void LoadICFastApi_DirectCall_GCMoveStub(Accessor accessor) {
11807 LocalContext context; 12028 LocalContext context;
11808 v8::HandleScope scope(context->GetIsolate()); 12029 v8::Isolate* isolate = context->GetIsolate();
11809 v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New(); 12030 v8::HandleScope scope(isolate);
12031 v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New(isolate);
11810 obj->SetAccessor(v8_str("p1"), accessor); 12032 obj->SetAccessor(v8_str("p1"), accessor);
11811 context->Global()->Set(v8_str("o1"), obj->NewInstance()); 12033 context->Global()->Set(v8_str("o1"), obj->NewInstance());
11812 p_getter_count = 0; 12034 p_getter_count = 0;
11813 v8::Handle<v8::Value> result = CompileRun( 12035 v8::Handle<v8::Value> result = CompileRun(
11814 "function f() {" 12036 "function f() {"
11815 " for (var i = 0; i < 30; i++) o1.p1;" 12037 " for (var i = 0; i < 30; i++) o1.p1;"
11816 " return o1.p1" 12038 " return o1.p1"
11817 "}" 12039 "}"
11818 "f();"); 12040 "f();");
11819 CHECK_EQ(v8_str("Direct Getter Result"), result); 12041 CHECK_EQ(v8_str("Direct Getter Result"), result);
11820 CHECK_EQ(31, p_getter_count); 12042 CHECK_EQ(31, p_getter_count);
11821 } 12043 }
11822 12044
11823 12045
11824 THREADED_PROFILED_TEST(LoadICFastApi_DirectCall_GCMoveStub) { 12046 THREADED_PROFILED_TEST(LoadICFastApi_DirectCall_GCMoveStub) {
11825 LoadICFastApi_DirectCall_GCMoveStub(DirectGetterCallback); 12047 LoadICFastApi_DirectCall_GCMoveStub(DirectGetterCallback);
11826 } 12048 }
11827 12049
11828 12050
11829 void ThrowingDirectGetterCallback( 12051 void ThrowingDirectGetterCallback(
11830 Local<String> name, 12052 Local<String> name,
11831 const v8::PropertyCallbackInfo<v8::Value>& info) { 12053 const v8::PropertyCallbackInfo<v8::Value>& info) {
11832 info.GetIsolate()->ThrowException(v8_str("g")); 12054 info.GetIsolate()->ThrowException(v8_str("g"));
11833 } 12055 }
11834 12056
11835 12057
11836 THREADED_TEST(LoadICFastApi_DirectCall_Throw) { 12058 THREADED_TEST(LoadICFastApi_DirectCall_Throw) {
11837 LocalContext context; 12059 LocalContext context;
11838 v8::HandleScope scope(context->GetIsolate()); 12060 v8::Isolate* isolate = context->GetIsolate();
11839 v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New(); 12061 v8::HandleScope scope(isolate);
12062 v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New(isolate);
11840 obj->SetAccessor(v8_str("p1"), ThrowingDirectGetterCallback); 12063 obj->SetAccessor(v8_str("p1"), ThrowingDirectGetterCallback);
11841 context->Global()->Set(v8_str("o1"), obj->NewInstance()); 12064 context->Global()->Set(v8_str("o1"), obj->NewInstance());
11842 v8::Handle<Value> result = CompileRun( 12065 v8::Handle<Value> result = CompileRun(
11843 "var result = '';" 12066 "var result = '';"
11844 "for (var i = 0; i < 5; i++) {" 12067 "for (var i = 0; i < 5; i++) {"
11845 " try { o1.p1; } catch (e) { result += e; }" 12068 " try { o1.p1; } catch (e) { result += e; }"
11846 "}" 12069 "}"
11847 "result;"); 12070 "result;");
11848 CHECK_EQ(v8_str("ggggg"), result); 12071 CHECK_EQ(v8_str("ggggg"), result);
11849 } 12072 }
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
12252 ApiTestFuzzer::Fuzz(); 12475 ApiTestFuzzer::Fuzz();
12253 if (v8_str("x")->Equals(name)) { 12476 if (v8_str("x")->Equals(name)) {
12254 info.GetReturnValue().Set(keyed_call_ic_function); 12477 info.GetReturnValue().Set(keyed_call_ic_function);
12255 } 12478 }
12256 } 12479 }
12257 12480
12258 12481
12259 // Test the case when we stored cacheable lookup into 12482 // Test the case when we stored cacheable lookup into
12260 // a stub, but the function name changed (to another cacheable function). 12483 // a stub, but the function name changed (to another cacheable function).
12261 THREADED_TEST(InterceptorKeyedCallICKeyChange1) { 12484 THREADED_TEST(InterceptorKeyedCallICKeyChange1) {
12262 v8::HandleScope scope(CcTest::isolate()); 12485 v8::Isolate* isolate = CcTest::isolate();
12263 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 12486 v8::HandleScope scope(isolate);
12487 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate);
12264 templ->SetNamedPropertyHandler(NoBlockGetterX); 12488 templ->SetNamedPropertyHandler(NoBlockGetterX);
12265 LocalContext context; 12489 LocalContext context;
12266 context->Global()->Set(v8_str("o"), templ->NewInstance()); 12490 context->Global()->Set(v8_str("o"), templ->NewInstance());
12267 CompileRun( 12491 CompileRun(
12268 "proto = new Object();" 12492 "proto = new Object();"
12269 "proto.y = function(x) { return x + 1; };" 12493 "proto.y = function(x) { return x + 1; };"
12270 "proto.z = function(x) { return x - 1; };" 12494 "proto.z = function(x) { return x - 1; };"
12271 "o.__proto__ = proto;" 12495 "o.__proto__ = proto;"
12272 "var result = 0;" 12496 "var result = 0;"
12273 "var method = 'y';" 12497 "var method = 'y';"
12274 "for (var i = 0; i < 10; i++) {" 12498 "for (var i = 0; i < 10; i++) {"
12275 " if (i == 5) { method = 'z'; };" 12499 " if (i == 5) { method = 'z'; };"
12276 " result += o[method](41);" 12500 " result += o[method](41);"
12277 "}"); 12501 "}");
12278 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); 12502 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value());
12279 } 12503 }
12280 12504
12281 12505
12282 // Test the case when we stored cacheable lookup into 12506 // Test the case when we stored cacheable lookup into
12283 // a stub, but the function name changed (and the new function is present 12507 // a stub, but the function name changed (and the new function is present
12284 // both before and after the interceptor in the prototype chain). 12508 // both before and after the interceptor in the prototype chain).
12285 THREADED_TEST(InterceptorKeyedCallICKeyChange2) { 12509 THREADED_TEST(InterceptorKeyedCallICKeyChange2) {
12286 v8::HandleScope scope(CcTest::isolate()); 12510 v8::Isolate* isolate = CcTest::isolate();
12287 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 12511 v8::HandleScope scope(isolate);
12512 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate);
12288 templ->SetNamedPropertyHandler(InterceptorKeyedCallICGetter); 12513 templ->SetNamedPropertyHandler(InterceptorKeyedCallICGetter);
12289 LocalContext context; 12514 LocalContext context;
12290 context->Global()->Set(v8_str("proto1"), templ->NewInstance()); 12515 context->Global()->Set(v8_str("proto1"), templ->NewInstance());
12291 keyed_call_ic_function = 12516 keyed_call_ic_function =
12292 v8_compile("function f(x) { return x - 1; }; f")->Run(); 12517 v8_compile("function f(x) { return x - 1; }; f")->Run();
12293 CompileRun( 12518 CompileRun(
12294 "o = new Object();" 12519 "o = new Object();"
12295 "proto2 = new Object();" 12520 "proto2 = new Object();"
12296 "o.y = function(x) { return x + 1; };" 12521 "o.y = function(x) { return x + 1; };"
12297 "proto2.y = function(x) { return x + 2; };" 12522 "proto2.y = function(x) { return x + 2; };"
12298 "o.__proto__ = proto1;" 12523 "o.__proto__ = proto1;"
12299 "proto1.__proto__ = proto2;" 12524 "proto1.__proto__ = proto2;"
12300 "var result = 0;" 12525 "var result = 0;"
12301 "var method = 'x';" 12526 "var method = 'x';"
12302 "for (var i = 0; i < 10; i++) {" 12527 "for (var i = 0; i < 10; i++) {"
12303 " if (i == 5) { method = 'y'; };" 12528 " if (i == 5) { method = 'y'; };"
12304 " result += o[method](41);" 12529 " result += o[method](41);"
12305 "}"); 12530 "}");
12306 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); 12531 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value());
12307 } 12532 }
12308 12533
12309 12534
12310 // Same as InterceptorKeyedCallICKeyChange1 only the cacheable function sit 12535 // Same as InterceptorKeyedCallICKeyChange1 only the cacheable function sit
12311 // on the global object. 12536 // on the global object.
12312 THREADED_TEST(InterceptorKeyedCallICKeyChangeOnGlobal) { 12537 THREADED_TEST(InterceptorKeyedCallICKeyChangeOnGlobal) {
12313 v8::HandleScope scope(CcTest::isolate()); 12538 v8::Isolate* isolate = CcTest::isolate();
12314 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 12539 v8::HandleScope scope(isolate);
12540 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate);
12315 templ->SetNamedPropertyHandler(NoBlockGetterX); 12541 templ->SetNamedPropertyHandler(NoBlockGetterX);
12316 LocalContext context; 12542 LocalContext context;
12317 context->Global()->Set(v8_str("o"), templ->NewInstance()); 12543 context->Global()->Set(v8_str("o"), templ->NewInstance());
12318 CompileRun( 12544 CompileRun(
12319 "function inc(x) { return x + 1; };" 12545 "function inc(x) { return x + 1; };"
12320 "inc(1);" 12546 "inc(1);"
12321 "function dec(x) { return x - 1; };" 12547 "function dec(x) { return x - 1; };"
12322 "dec(1);" 12548 "dec(1);"
12323 "o.__proto__ = this;" 12549 "o.__proto__ = this;"
12324 "this.__proto__.x = inc;" 12550 "this.__proto__.x = inc;"
12325 "this.__proto__.y = dec;" 12551 "this.__proto__.y = dec;"
12326 "var result = 0;" 12552 "var result = 0;"
12327 "var method = 'x';" 12553 "var method = 'x';"
12328 "for (var i = 0; i < 10; i++) {" 12554 "for (var i = 0; i < 10; i++) {"
12329 " if (i == 5) { method = 'y'; };" 12555 " if (i == 5) { method = 'y'; };"
12330 " result += o[method](41);" 12556 " result += o[method](41);"
12331 "}"); 12557 "}");
12332 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); 12558 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value());
12333 } 12559 }
12334 12560
12335 12561
12336 // Test the case when actual function to call sits on global object. 12562 // Test the case when actual function to call sits on global object.
12337 THREADED_TEST(InterceptorKeyedCallICFromGlobal) { 12563 THREADED_TEST(InterceptorKeyedCallICFromGlobal) {
12338 v8::HandleScope scope(CcTest::isolate()); 12564 v8::Isolate* isolate = CcTest::isolate();
12339 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); 12565 v8::HandleScope scope(isolate);
12566 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate);
12340 templ_o->SetNamedPropertyHandler(NoBlockGetterX); 12567 templ_o->SetNamedPropertyHandler(NoBlockGetterX);
12341 LocalContext context; 12568 LocalContext context;
12342 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); 12569 context->Global()->Set(v8_str("o"), templ_o->NewInstance());
12343 12570
12344 CompileRun( 12571 CompileRun(
12345 "function len(x) { return x.length; };" 12572 "function len(x) { return x.length; };"
12346 "o.__proto__ = this;" 12573 "o.__proto__ = this;"
12347 "var m = 'parseFloat';" 12574 "var m = 'parseFloat';"
12348 "var result = 0;" 12575 "var result = 0;"
12349 "for (var i = 0; i < 10; i++) {" 12576 "for (var i = 0; i < 10; i++) {"
12350 " if (i == 5) {" 12577 " if (i == 5) {"
12351 " m = 'len';" 12578 " m = 'len';"
12352 " saved_result = result;" 12579 " saved_result = result;"
12353 " };" 12580 " };"
12354 " result = o[m]('239');" 12581 " result = o[m]('239');"
12355 "}"); 12582 "}");
12356 CHECK_EQ(3, context->Global()->Get(v8_str("result"))->Int32Value()); 12583 CHECK_EQ(3, context->Global()->Get(v8_str("result"))->Int32Value());
12357 CHECK_EQ(239, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 12584 CHECK_EQ(239, context->Global()->Get(v8_str("saved_result"))->Int32Value());
12358 } 12585 }
12359 12586
12360 12587
12361 // Test the map transition before the interceptor. 12588 // Test the map transition before the interceptor.
12362 THREADED_TEST(InterceptorKeyedCallICMapChangeBefore) { 12589 THREADED_TEST(InterceptorKeyedCallICMapChangeBefore) {
12363 v8::HandleScope scope(CcTest::isolate()); 12590 v8::Isolate* isolate = CcTest::isolate();
12364 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); 12591 v8::HandleScope scope(isolate);
12592 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate);
12365 templ_o->SetNamedPropertyHandler(NoBlockGetterX); 12593 templ_o->SetNamedPropertyHandler(NoBlockGetterX);
12366 LocalContext context; 12594 LocalContext context;
12367 context->Global()->Set(v8_str("proto"), templ_o->NewInstance()); 12595 context->Global()->Set(v8_str("proto"), templ_o->NewInstance());
12368 12596
12369 CompileRun( 12597 CompileRun(
12370 "var o = new Object();" 12598 "var o = new Object();"
12371 "o.__proto__ = proto;" 12599 "o.__proto__ = proto;"
12372 "o.method = function(x) { return x + 1; };" 12600 "o.method = function(x) { return x + 1; };"
12373 "var m = 'method';" 12601 "var m = 'method';"
12374 "var result = 0;" 12602 "var result = 0;"
12375 "for (var i = 0; i < 10; i++) {" 12603 "for (var i = 0; i < 10; i++) {"
12376 " if (i == 5) { o.method = function(x) { return x - 1; }; };" 12604 " if (i == 5) { o.method = function(x) { return x - 1; }; };"
12377 " result += o[m](41);" 12605 " result += o[m](41);"
12378 "}"); 12606 "}");
12379 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); 12607 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value());
12380 } 12608 }
12381 12609
12382 12610
12383 // Test the map transition after the interceptor. 12611 // Test the map transition after the interceptor.
12384 THREADED_TEST(InterceptorKeyedCallICMapChangeAfter) { 12612 THREADED_TEST(InterceptorKeyedCallICMapChangeAfter) {
12385 v8::HandleScope scope(CcTest::isolate()); 12613 v8::Isolate* isolate = CcTest::isolate();
12386 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); 12614 v8::HandleScope scope(isolate);
12615 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate);
12387 templ_o->SetNamedPropertyHandler(NoBlockGetterX); 12616 templ_o->SetNamedPropertyHandler(NoBlockGetterX);
12388 LocalContext context; 12617 LocalContext context;
12389 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); 12618 context->Global()->Set(v8_str("o"), templ_o->NewInstance());
12390 12619
12391 CompileRun( 12620 CompileRun(
12392 "var proto = new Object();" 12621 "var proto = new Object();"
12393 "o.__proto__ = proto;" 12622 "o.__proto__ = proto;"
12394 "proto.method = function(x) { return x + 1; };" 12623 "proto.method = function(x) { return x + 1; };"
12395 "var m = 'method';" 12624 "var m = 'method';"
12396 "var result = 0;" 12625 "var result = 0;"
(...skipping 14 matching lines...) Expand all
12411 if (v8_str("x")->Equals(name) && interceptor_call_count++ < 20) { 12640 if (v8_str("x")->Equals(name) && interceptor_call_count++ < 20) {
12412 info.GetReturnValue().Set(call_ic_function2); 12641 info.GetReturnValue().Set(call_ic_function2);
12413 } 12642 }
12414 } 12643 }
12415 12644
12416 12645
12417 // This test should hit load and call ICs for the interceptor case. 12646 // This test should hit load and call ICs for the interceptor case.
12418 // Once in a while, the interceptor will reply that a property was not 12647 // Once in a while, the interceptor will reply that a property was not
12419 // found in which case we should get a reference error. 12648 // found in which case we should get a reference error.
12420 THREADED_TEST(InterceptorICReferenceErrors) { 12649 THREADED_TEST(InterceptorICReferenceErrors) {
12421 v8::HandleScope scope(CcTest::isolate()); 12650 v8::Isolate* isolate = CcTest::isolate();
12422 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 12651 v8::HandleScope scope(isolate);
12652 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate);
12423 templ->SetNamedPropertyHandler(InterceptorICRefErrorGetter); 12653 templ->SetNamedPropertyHandler(InterceptorICRefErrorGetter);
12424 LocalContext context(0, templ, v8::Handle<Value>()); 12654 LocalContext context(0, templ, v8::Handle<Value>());
12425 call_ic_function2 = v8_compile("function h(x) { return x; }; h")->Run(); 12655 call_ic_function2 = v8_compile("function h(x) { return x; }; h")->Run();
12426 v8::Handle<Value> value = CompileRun( 12656 v8::Handle<Value> value = CompileRun(
12427 "function f() {" 12657 "function f() {"
12428 " for (var i = 0; i < 1000; i++) {" 12658 " for (var i = 0; i < 1000; i++) {"
12429 " try { x; } catch(e) { return true; }" 12659 " try { x; } catch(e) { return true; }"
12430 " }" 12660 " }"
12431 " return false;" 12661 " return false;"
12432 "};" 12662 "};"
(...skipping 25 matching lines...) Expand all
12458 info.GetIsolate()->ThrowException(v8_num(42)); 12688 info.GetIsolate()->ThrowException(v8_num(42));
12459 return; 12689 return;
12460 } 12690 }
12461 } 12691 }
12462 12692
12463 12693
12464 // Test interceptor load/call IC where the interceptor throws an 12694 // Test interceptor load/call IC where the interceptor throws an
12465 // exception once in a while. 12695 // exception once in a while.
12466 THREADED_TEST(InterceptorICGetterExceptions) { 12696 THREADED_TEST(InterceptorICGetterExceptions) {
12467 interceptor_ic_exception_get_count = 0; 12697 interceptor_ic_exception_get_count = 0;
12468 v8::HandleScope scope(CcTest::isolate()); 12698 v8::Isolate* isolate = CcTest::isolate();
12469 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 12699 v8::HandleScope scope(isolate);
12700 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate);
12470 templ->SetNamedPropertyHandler(InterceptorICExceptionGetter); 12701 templ->SetNamedPropertyHandler(InterceptorICExceptionGetter);
12471 LocalContext context(0, templ, v8::Handle<Value>()); 12702 LocalContext context(0, templ, v8::Handle<Value>());
12472 call_ic_function3 = v8_compile("function h(x) { return x; }; h")->Run(); 12703 call_ic_function3 = v8_compile("function h(x) { return x; }; h")->Run();
12473 v8::Handle<Value> value = CompileRun( 12704 v8::Handle<Value> value = CompileRun(
12474 "function f() {" 12705 "function f() {"
12475 " for (var i = 0; i < 100; i++) {" 12706 " for (var i = 0; i < 100; i++) {"
12476 " try { x; } catch(e) { return true; }" 12707 " try { x; } catch(e) { return true; }"
12477 " }" 12708 " }"
12478 " return false;" 12709 " return false;"
12479 "};" 12710 "};"
(...skipping 22 matching lines...) Expand all
12502 if (++interceptor_ic_exception_set_count > 20) { 12733 if (++interceptor_ic_exception_set_count > 20) {
12503 info.GetIsolate()->ThrowException(v8_num(42)); 12734 info.GetIsolate()->ThrowException(v8_num(42));
12504 } 12735 }
12505 } 12736 }
12506 12737
12507 12738
12508 // Test interceptor store IC where the interceptor throws an exception 12739 // Test interceptor store IC where the interceptor throws an exception
12509 // once in a while. 12740 // once in a while.
12510 THREADED_TEST(InterceptorICSetterExceptions) { 12741 THREADED_TEST(InterceptorICSetterExceptions) {
12511 interceptor_ic_exception_set_count = 0; 12742 interceptor_ic_exception_set_count = 0;
12512 v8::HandleScope scope(CcTest::isolate()); 12743 v8::Isolate* isolate = CcTest::isolate();
12513 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 12744 v8::HandleScope scope(isolate);
12745 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate);
12514 templ->SetNamedPropertyHandler(0, InterceptorICExceptionSetter); 12746 templ->SetNamedPropertyHandler(0, InterceptorICExceptionSetter);
12515 LocalContext context(0, templ, v8::Handle<Value>()); 12747 LocalContext context(0, templ, v8::Handle<Value>());
12516 v8::Handle<Value> value = CompileRun( 12748 v8::Handle<Value> value = CompileRun(
12517 "function f() {" 12749 "function f() {"
12518 " for (var i = 0; i < 100; i++) {" 12750 " for (var i = 0; i < 100; i++) {"
12519 " try { x = 42; } catch(e) { return true; }" 12751 " try { x = 42; } catch(e) { return true; }"
12520 " }" 12752 " }"
12521 " return false;" 12753 " return false;"
12522 "};" 12754 "};"
12523 "f();"); 12755 "f();");
12524 CHECK_EQ(true, value->BooleanValue()); 12756 CHECK_EQ(true, value->BooleanValue());
12525 } 12757 }
12526 12758
12527 12759
12528 // Test that we ignore null interceptors. 12760 // Test that we ignore null interceptors.
12529 THREADED_TEST(NullNamedInterceptor) { 12761 THREADED_TEST(NullNamedInterceptor) {
12530 v8::HandleScope scope(CcTest::isolate()); 12762 v8::Isolate* isolate = CcTest::isolate();
12531 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 12763 v8::HandleScope scope(isolate);
12764 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate);
12532 templ->SetNamedPropertyHandler( 12765 templ->SetNamedPropertyHandler(
12533 static_cast<v8::NamedPropertyGetterCallback>(0)); 12766 static_cast<v8::NamedPropertyGetterCallback>(0));
12534 LocalContext context; 12767 LocalContext context;
12535 templ->Set(CcTest::isolate(), "x", v8_num(42)); 12768 templ->Set(CcTest::isolate(), "x", v8_num(42));
12536 v8::Handle<v8::Object> obj = templ->NewInstance(); 12769 v8::Handle<v8::Object> obj = templ->NewInstance();
12537 context->Global()->Set(v8_str("obj"), obj); 12770 context->Global()->Set(v8_str("obj"), obj);
12538 v8::Handle<Value> value = CompileRun("obj.x"); 12771 v8::Handle<Value> value = CompileRun("obj.x");
12539 CHECK(value->IsInt32()); 12772 CHECK(value->IsInt32());
12540 CHECK_EQ(42, value->Int32Value()); 12773 CHECK_EQ(42, value->Int32Value());
12541 } 12774 }
12542 12775
12543 12776
12544 // Test that we ignore null interceptors. 12777 // Test that we ignore null interceptors.
12545 THREADED_TEST(NullIndexedInterceptor) { 12778 THREADED_TEST(NullIndexedInterceptor) {
12546 v8::HandleScope scope(CcTest::isolate()); 12779 v8::Isolate* isolate = CcTest::isolate();
12547 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 12780 v8::HandleScope scope(isolate);
12781 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate);
12548 templ->SetIndexedPropertyHandler( 12782 templ->SetIndexedPropertyHandler(
12549 static_cast<v8::IndexedPropertyGetterCallback>(0)); 12783 static_cast<v8::IndexedPropertyGetterCallback>(0));
12550 LocalContext context; 12784 LocalContext context;
12551 templ->Set(CcTest::isolate(), "42", v8_num(42)); 12785 templ->Set(CcTest::isolate(), "42", v8_num(42));
12552 v8::Handle<v8::Object> obj = templ->NewInstance(); 12786 v8::Handle<v8::Object> obj = templ->NewInstance();
12553 context->Global()->Set(v8_str("obj"), obj); 12787 context->Global()->Set(v8_str("obj"), obj);
12554 v8::Handle<Value> value = CompileRun("obj[42]"); 12788 v8::Handle<Value> value = CompileRun("obj[42]");
12555 CHECK(value->IsInt32()); 12789 CHECK(value->IsInt32());
12556 CHECK_EQ(42, value->Int32Value()); 12790 CHECK_EQ(42, value->Int32Value());
12557 } 12791 }
(...skipping 17 matching lines...) Expand all
12575 ApiTestFuzzer::Fuzz(); 12809 ApiTestFuzzer::Fuzz();
12576 info.GetIsolate()->ThrowException(Handle<Value>()); 12810 info.GetIsolate()->ThrowException(Handle<Value>());
12577 info.GetReturnValue().SetUndefined(); 12811 info.GetReturnValue().SetUndefined();
12578 } 12812 }
12579 12813
12580 12814
12581 THREADED_TEST(VariousGetPropertiesAndThrowingCallbacks) { 12815 THREADED_TEST(VariousGetPropertiesAndThrowingCallbacks) {
12582 LocalContext context; 12816 LocalContext context;
12583 HandleScope scope(context->GetIsolate()); 12817 HandleScope scope(context->GetIsolate());
12584 12818
12585 Local<FunctionTemplate> templ = FunctionTemplate::New(CcTest::isolate()); 12819 Local<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate());
12586 Local<ObjectTemplate> instance_templ = templ->InstanceTemplate(); 12820 Local<ObjectTemplate> instance_templ = templ->InstanceTemplate();
12587 instance_templ->SetAccessor(v8_str("f"), ThrowingGetter); 12821 instance_templ->SetAccessor(v8_str("f"), ThrowingGetter);
12588 12822
12589 Local<Object> instance = templ->GetFunction()->NewInstance(); 12823 Local<Object> instance = templ->GetFunction()->NewInstance();
12590 12824
12591 Local<Object> another = Object::New(); 12825 Local<Object> another = Object::New(context->GetIsolate());
12592 another->SetPrototype(instance); 12826 another->SetPrototype(instance);
12593 12827
12594 Local<Object> with_js_getter = CompileRun( 12828 Local<Object> with_js_getter = CompileRun(
12595 "o = {};\n" 12829 "o = {};\n"
12596 "o.__defineGetter__('f', function() { throw undefined; });\n" 12830 "o.__defineGetter__('f', function() { throw undefined; });\n"
12597 "o\n").As<Object>(); 12831 "o\n").As<Object>();
12598 CHECK(!with_js_getter.IsEmpty()); 12832 CHECK(!with_js_getter.IsEmpty());
12599 12833
12600 TryCatch try_catch; 12834 TryCatch try_catch;
12601 12835
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
13222 v8::Isolate* isolate = context->GetIsolate(); 13456 v8::Isolate* isolate = context->GetIsolate();
13223 i::GlobalHandles* globals = 13457 i::GlobalHandles* globals =
13224 reinterpret_cast<i::Isolate*>(isolate)->global_handles(); 13458 reinterpret_cast<i::Isolate*>(isolate)->global_handles();
13225 int initial_handles = globals->global_handles_count(); 13459 int initial_handles = globals->global_handles_count();
13226 typedef v8::Persistent<v8::Object, v8::CopyablePersistentTraits<v8::Object> > 13460 typedef v8::Persistent<v8::Object, v8::CopyablePersistentTraits<v8::Object> >
13227 CopyableObject; 13461 CopyableObject;
13228 { 13462 {
13229 CopyableObject handle1; 13463 CopyableObject handle1;
13230 { 13464 {
13231 v8::HandleScope scope(isolate); 13465 v8::HandleScope scope(isolate);
13232 handle1.Reset(isolate, v8::Object::New()); 13466 handle1.Reset(isolate, v8::Object::New(isolate));
13233 } 13467 }
13234 CHECK_EQ(initial_handles + 1, globals->global_handles_count()); 13468 CHECK_EQ(initial_handles + 1, globals->global_handles_count());
13235 CopyableObject handle2; 13469 CopyableObject handle2;
13236 handle2 = handle1; 13470 handle2 = handle1;
13237 CHECK(handle1 == handle2); 13471 CHECK(handle1 == handle2);
13238 CHECK_EQ(initial_handles + 2, globals->global_handles_count()); 13472 CHECK_EQ(initial_handles + 2, globals->global_handles_count());
13239 CopyableObject handle3(handle2); 13473 CopyableObject handle3(handle2);
13240 CHECK(handle1 == handle3); 13474 CHECK(handle1 == handle3);
13241 CHECK_EQ(initial_handles + 3, globals->global_handles_count()); 13475 CHECK_EQ(initial_handles + 3, globals->global_handles_count());
13242 } 13476 }
(...skipping 12 matching lines...) Expand all
13255 13489
13256 13490
13257 TEST(WeakCallbackApi) { 13491 TEST(WeakCallbackApi) {
13258 LocalContext context; 13492 LocalContext context;
13259 v8::Isolate* isolate = context->GetIsolate(); 13493 v8::Isolate* isolate = context->GetIsolate();
13260 i::GlobalHandles* globals = 13494 i::GlobalHandles* globals =
13261 reinterpret_cast<i::Isolate*>(isolate)->global_handles(); 13495 reinterpret_cast<i::Isolate*>(isolate)->global_handles();
13262 int initial_handles = globals->global_handles_count(); 13496 int initial_handles = globals->global_handles_count();
13263 { 13497 {
13264 v8::HandleScope scope(isolate); 13498 v8::HandleScope scope(isolate);
13265 v8::Local<v8::Object> obj = v8::Object::New(); 13499 v8::Local<v8::Object> obj = v8::Object::New(isolate);
13266 obj->Set(v8_str("key"), v8::Integer::New(231, isolate)); 13500 obj->Set(v8_str("key"), v8::Integer::New(isolate, 231));
13267 v8::Persistent<v8::Object>* handle = 13501 v8::Persistent<v8::Object>* handle =
13268 new v8::Persistent<v8::Object>(isolate, obj); 13502 new v8::Persistent<v8::Object>(isolate, obj);
13269 handle->SetWeak<v8::Object, v8::Persistent<v8::Object> >(handle, 13503 handle->SetWeak<v8::Object, v8::Persistent<v8::Object> >(handle,
13270 WeakApiCallback); 13504 WeakApiCallback);
13271 } 13505 }
13272 reinterpret_cast<i::Isolate*>(isolate)->heap()-> 13506 reinterpret_cast<i::Isolate*>(isolate)->heap()->
13273 CollectAllGarbage(i::Heap::kNoGCFlags); 13507 CollectAllGarbage(i::Heap::kNoGCFlags);
13274 // Verify disposed. 13508 // Verify disposed.
13275 CHECK_EQ(initial_handles, globals->global_handles_count()); 13509 CHECK_EQ(initial_handles, globals->global_handles_count());
13276 } 13510 }
(...skipping 10 matching lines...) Expand all
13287 } 13521 }
13288 13522
13289 13523
13290 THREADED_TEST(NewPersistentHandleFromWeakCallback) { 13524 THREADED_TEST(NewPersistentHandleFromWeakCallback) {
13291 LocalContext context; 13525 LocalContext context;
13292 v8::Isolate* isolate = context->GetIsolate(); 13526 v8::Isolate* isolate = context->GetIsolate();
13293 13527
13294 v8::Persistent<v8::Object> handle1, handle2; 13528 v8::Persistent<v8::Object> handle1, handle2;
13295 { 13529 {
13296 v8::HandleScope scope(isolate); 13530 v8::HandleScope scope(isolate);
13297 some_object.Reset(isolate, v8::Object::New()); 13531 some_object.Reset(isolate, v8::Object::New(isolate));
13298 handle1.Reset(isolate, v8::Object::New()); 13532 handle1.Reset(isolate, v8::Object::New(isolate));
13299 handle2.Reset(isolate, v8::Object::New()); 13533 handle2.Reset(isolate, v8::Object::New(isolate));
13300 } 13534 }
13301 // Note: order is implementation dependent alas: currently 13535 // Note: order is implementation dependent alas: currently
13302 // global handle nodes are processed by PostGarbageCollectionProcessing 13536 // global handle nodes are processed by PostGarbageCollectionProcessing
13303 // in reverse allocation order, so if second allocated handle is deleted, 13537 // in reverse allocation order, so if second allocated handle is deleted,
13304 // weak callback of the first handle would be able to 'reallocate' it. 13538 // weak callback of the first handle would be able to 'reallocate' it.
13305 handle1.SetWeak(&handle1, NewPersistentHandleCallback); 13539 handle1.SetWeak(&handle1, NewPersistentHandleCallback);
13306 handle2.Reset(); 13540 handle2.Reset();
13307 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 13541 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
13308 } 13542 }
13309 13543
13310 13544
13311 v8::Persistent<v8::Object> to_be_disposed; 13545 v8::Persistent<v8::Object> to_be_disposed;
13312 13546
13313 void DisposeAndForceGcCallback( 13547 void DisposeAndForceGcCallback(
13314 const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) { 13548 const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) {
13315 to_be_disposed.Reset(); 13549 to_be_disposed.Reset();
13316 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 13550 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
13317 data.GetParameter()->Reset(); 13551 data.GetParameter()->Reset();
13318 } 13552 }
13319 13553
13320 13554
13321 THREADED_TEST(DoNotUseDeletedNodesInSecondLevelGc) { 13555 THREADED_TEST(DoNotUseDeletedNodesInSecondLevelGc) {
13322 LocalContext context; 13556 LocalContext context;
13323 v8::Isolate* isolate = context->GetIsolate(); 13557 v8::Isolate* isolate = context->GetIsolate();
13324 13558
13325 v8::Persistent<v8::Object> handle1, handle2; 13559 v8::Persistent<v8::Object> handle1, handle2;
13326 { 13560 {
13327 v8::HandleScope scope(isolate); 13561 v8::HandleScope scope(isolate);
13328 handle1.Reset(isolate, v8::Object::New()); 13562 handle1.Reset(isolate, v8::Object::New(isolate));
13329 handle2.Reset(isolate, v8::Object::New()); 13563 handle2.Reset(isolate, v8::Object::New(isolate));
13330 } 13564 }
13331 handle1.SetWeak(&handle1, DisposeAndForceGcCallback); 13565 handle1.SetWeak(&handle1, DisposeAndForceGcCallback);
13332 to_be_disposed.Reset(isolate, handle2); 13566 to_be_disposed.Reset(isolate, handle2);
13333 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 13567 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
13334 } 13568 }
13335 13569
13336 void DisposingCallback( 13570 void DisposingCallback(
13337 const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) { 13571 const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) {
13338 data.GetParameter()->Reset(); 13572 data.GetParameter()->Reset();
13339 } 13573 }
13340 13574
13341 void HandleCreatingCallback( 13575 void HandleCreatingCallback(
13342 const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) { 13576 const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) {
13343 v8::HandleScope scope(data.GetIsolate()); 13577 v8::HandleScope scope(data.GetIsolate());
13344 v8::Persistent<v8::Object>(data.GetIsolate(), v8::Object::New()); 13578 v8::Persistent<v8::Object>(data.GetIsolate(),
13579 v8::Object::New(data.GetIsolate()));
13345 data.GetParameter()->Reset(); 13580 data.GetParameter()->Reset();
13346 } 13581 }
13347 13582
13348 13583
13349 THREADED_TEST(NoGlobalHandlesOrphaningDueToWeakCallback) { 13584 THREADED_TEST(NoGlobalHandlesOrphaningDueToWeakCallback) {
13350 LocalContext context; 13585 LocalContext context;
13351 v8::Isolate* isolate = context->GetIsolate(); 13586 v8::Isolate* isolate = context->GetIsolate();
13352 13587
13353 v8::Persistent<v8::Object> handle1, handle2, handle3; 13588 v8::Persistent<v8::Object> handle1, handle2, handle3;
13354 { 13589 {
13355 v8::HandleScope scope(isolate); 13590 v8::HandleScope scope(isolate);
13356 handle3.Reset(isolate, v8::Object::New()); 13591 handle3.Reset(isolate, v8::Object::New(isolate));
13357 handle2.Reset(isolate, v8::Object::New()); 13592 handle2.Reset(isolate, v8::Object::New(isolate));
13358 handle1.Reset(isolate, v8::Object::New()); 13593 handle1.Reset(isolate, v8::Object::New(isolate));
13359 } 13594 }
13360 handle2.SetWeak(&handle2, DisposingCallback); 13595 handle2.SetWeak(&handle2, DisposingCallback);
13361 handle3.SetWeak(&handle3, HandleCreatingCallback); 13596 handle3.SetWeak(&handle3, HandleCreatingCallback);
13362 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 13597 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
13363 } 13598 }
13364 13599
13365 13600
13366 THREADED_TEST(CheckForCrossContextObjectLiterals) { 13601 THREADED_TEST(CheckForCrossContextObjectLiterals) {
13367 v8::V8::Initialize(); 13602 v8::V8::Initialize();
13368 13603
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
13640 13875
13641 return invocations; 13876 return invocations;
13642 } 13877 }
13643 13878
13644 13879
13645 void SetFunctionEntryHookTest::RunLoopInNewEnv(v8::Isolate* isolate) { 13880 void SetFunctionEntryHookTest::RunLoopInNewEnv(v8::Isolate* isolate) {
13646 v8::HandleScope outer(isolate); 13881 v8::HandleScope outer(isolate);
13647 v8::Local<Context> env = Context::New(isolate); 13882 v8::Local<Context> env = Context::New(isolate);
13648 env->Enter(); 13883 env->Enter();
13649 13884
13650 Local<ObjectTemplate> t = ObjectTemplate::New(); 13885 Local<ObjectTemplate> t = ObjectTemplate::New(isolate);
13651 t->Set(v8_str("asdf"), v8::FunctionTemplate::New(isolate, RuntimeCallback)); 13886 t->Set(v8_str("asdf"), v8::FunctionTemplate::New(isolate, RuntimeCallback));
13652 env->Global()->Set(v8_str("obj"), t->NewInstance()); 13887 env->Global()->Set(v8_str("obj"), t->NewInstance());
13653 13888
13654 const char* script = 13889 const char* script =
13655 "function bar() {\n" 13890 "function bar() {\n"
13656 " var sum = 0;\n" 13891 " var sum = 0;\n"
13657 " for (i = 0; i < 100; ++i)\n" 13892 " for (i = 0; i < 100; ++i)\n"
13658 " sum = foo(i);\n" 13893 " sum = foo(i);\n"
13659 " return sum;\n" 13894 " return sum;\n"
13660 "}\n" 13895 "}\n"
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
14010 // Regression test for issue 54, object templates with internal fields 14245 // Regression test for issue 54, object templates with internal fields
14011 // but no accessors or interceptors did not get their internal field 14246 // but no accessors or interceptors did not get their internal field
14012 // count set on instances. 14247 // count set on instances.
14013 THREADED_TEST(Regress54) { 14248 THREADED_TEST(Regress54) {
14014 LocalContext context; 14249 LocalContext context;
14015 v8::Isolate* isolate = context->GetIsolate(); 14250 v8::Isolate* isolate = context->GetIsolate();
14016 v8::HandleScope outer(isolate); 14251 v8::HandleScope outer(isolate);
14017 static v8::Persistent<v8::ObjectTemplate> templ; 14252 static v8::Persistent<v8::ObjectTemplate> templ;
14018 if (templ.IsEmpty()) { 14253 if (templ.IsEmpty()) {
14019 v8::EscapableHandleScope inner(isolate); 14254 v8::EscapableHandleScope inner(isolate);
14020 v8::Local<v8::ObjectTemplate> local = v8::ObjectTemplate::New(); 14255 v8::Local<v8::ObjectTemplate> local = v8::ObjectTemplate::New(isolate);
14021 local->SetInternalFieldCount(1); 14256 local->SetInternalFieldCount(1);
14022 templ.Reset(isolate, inner.Escape(local)); 14257 templ.Reset(isolate, inner.Escape(local));
14023 } 14258 }
14024 v8::Handle<v8::Object> result = 14259 v8::Handle<v8::Object> result =
14025 v8::Local<v8::ObjectTemplate>::New(isolate, templ)->NewInstance(); 14260 v8::Local<v8::ObjectTemplate>::New(isolate, templ)->NewInstance();
14026 CHECK_EQ(1, result->InternalFieldCount()); 14261 CHECK_EQ(1, result->InternalFieldCount());
14027 } 14262 }
14028 14263
14029 14264
14030 // If part of the threaded tests, this test makes ThreadingTest fail 14265 // If part of the threaded tests, this test makes ThreadingTest fail
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
14095 14330
14096 resource_name = "test1.js"; 14331 resource_name = "test1.js";
14097 v8::ScriptOrigin origin1( 14332 v8::ScriptOrigin origin1(
14098 v8::String::NewFromUtf8(context->GetIsolate(), resource_name)); 14333 v8::String::NewFromUtf8(context->GetIsolate(), resource_name));
14099 script = v8::Script::Compile(source, &origin1); 14334 script = v8::Script::Compile(source, &origin1);
14100 CheckTryCatchSourceInfo(script, resource_name, 0); 14335 CheckTryCatchSourceInfo(script, resource_name, 0);
14101 14336
14102 resource_name = "test2.js"; 14337 resource_name = "test2.js";
14103 v8::ScriptOrigin origin2( 14338 v8::ScriptOrigin origin2(
14104 v8::String::NewFromUtf8(context->GetIsolate(), resource_name), 14339 v8::String::NewFromUtf8(context->GetIsolate(), resource_name),
14105 v8::Integer::New(7)); 14340 v8::Integer::New(context->GetIsolate(), 7));
14106 script = v8::Script::Compile(source, &origin2); 14341 script = v8::Script::Compile(source, &origin2);
14107 CheckTryCatchSourceInfo(script, resource_name, 7); 14342 CheckTryCatchSourceInfo(script, resource_name, 7);
14108 } 14343 }
14109 14344
14110 14345
14111 THREADED_TEST(CompilationCache) { 14346 THREADED_TEST(CompilationCache) {
14112 LocalContext context; 14347 LocalContext context;
14113 v8::HandleScope scope(context->GetIsolate()); 14348 v8::HandleScope scope(context->GetIsolate());
14114 v8::Handle<v8::String> source0 = 14349 v8::Handle<v8::String> source0 =
14115 v8::String::NewFromUtf8(context->GetIsolate(), "1234"); 14350 v8::String::NewFromUtf8(context->GetIsolate(), "1234");
(...skipping 15 matching lines...) Expand all
14131 const v8::FunctionCallbackInfo<v8::Value>& args) { 14366 const v8::FunctionCallbackInfo<v8::Value>& args) {
14132 ApiTestFuzzer::Fuzz(); 14367 ApiTestFuzzer::Fuzz();
14133 args.GetReturnValue().Set(v8_num(42)); 14368 args.GetReturnValue().Set(v8_num(42));
14134 } 14369 }
14135 14370
14136 14371
14137 THREADED_TEST(CallbackFunctionName) { 14372 THREADED_TEST(CallbackFunctionName) {
14138 LocalContext context; 14373 LocalContext context;
14139 v8::Isolate* isolate = context->GetIsolate(); 14374 v8::Isolate* isolate = context->GetIsolate();
14140 v8::HandleScope scope(isolate); 14375 v8::HandleScope scope(isolate);
14141 Local<ObjectTemplate> t = ObjectTemplate::New(); 14376 Local<ObjectTemplate> t = ObjectTemplate::New(isolate);
14142 t->Set(v8_str("asdf"), 14377 t->Set(v8_str("asdf"),
14143 v8::FunctionTemplate::New(isolate, FunctionNameCallback)); 14378 v8::FunctionTemplate::New(isolate, FunctionNameCallback));
14144 context->Global()->Set(v8_str("obj"), t->NewInstance()); 14379 context->Global()->Set(v8_str("obj"), t->NewInstance());
14145 v8::Handle<v8::Value> value = CompileRun("obj.asdf.name"); 14380 v8::Handle<v8::Value> value = CompileRun("obj.asdf.name");
14146 CHECK(value->IsString()); 14381 CHECK(value->IsString());
14147 v8::String::Utf8Value name(value); 14382 v8::String::Utf8Value name(value);
14148 CHECK_EQ("asdf", *name); 14383 CHECK_EQ("asdf", *name);
14149 } 14384 }
14150 14385
14151 14386
14152 THREADED_TEST(DateAccess) { 14387 THREADED_TEST(DateAccess) {
14153 LocalContext context; 14388 LocalContext context;
14154 v8::HandleScope scope(context->GetIsolate()); 14389 v8::HandleScope scope(context->GetIsolate());
14155 v8::Handle<v8::Value> date = 14390 v8::Handle<v8::Value> date =
14156 v8::Date::New(context->GetIsolate(), 1224744689038.0); 14391 v8::Date::New(context->GetIsolate(), 1224744689038.0);
14157 CHECK(date->IsDate()); 14392 CHECK(date->IsDate());
14158 CHECK_EQ(1224744689038.0, date.As<v8::Date>()->ValueOf()); 14393 CHECK_EQ(1224744689038.0, date.As<v8::Date>()->ValueOf());
14159 } 14394 }
14160 14395
14161 14396
14162 void CheckProperties(v8::Handle<v8::Value> val, int elmc, const char* elmv[]) { 14397 void CheckProperties(v8::Isolate* isolate,
14398 v8::Handle<v8::Value> val,
14399 int elmc,
14400 const char* elmv[]) {
14163 v8::Handle<v8::Object> obj = val.As<v8::Object>(); 14401 v8::Handle<v8::Object> obj = val.As<v8::Object>();
14164 v8::Handle<v8::Array> props = obj->GetPropertyNames(); 14402 v8::Handle<v8::Array> props = obj->GetPropertyNames();
14165 CHECK_EQ(elmc, props->Length()); 14403 CHECK_EQ(elmc, props->Length());
14166 for (int i = 0; i < elmc; i++) { 14404 for (int i = 0; i < elmc; i++) {
14167 v8::String::Utf8Value elm(props->Get(v8::Integer::New(i))); 14405 v8::String::Utf8Value elm(props->Get(v8::Integer::New(isolate, i)));
14168 CHECK_EQ(elmv[i], *elm); 14406 CHECK_EQ(elmv[i], *elm);
14169 } 14407 }
14170 } 14408 }
14171 14409
14172 14410
14173 void CheckOwnProperties(v8::Handle<v8::Value> val, 14411 void CheckOwnProperties(v8::Isolate* isolate,
14412 v8::Handle<v8::Value> val,
14174 int elmc, 14413 int elmc,
14175 const char* elmv[]) { 14414 const char* elmv[]) {
14176 v8::Handle<v8::Object> obj = val.As<v8::Object>(); 14415 v8::Handle<v8::Object> obj = val.As<v8::Object>();
14177 v8::Handle<v8::Array> props = obj->GetOwnPropertyNames(); 14416 v8::Handle<v8::Array> props = obj->GetOwnPropertyNames();
14178 CHECK_EQ(elmc, props->Length()); 14417 CHECK_EQ(elmc, props->Length());
14179 for (int i = 0; i < elmc; i++) { 14418 for (int i = 0; i < elmc; i++) {
14180 v8::String::Utf8Value elm(props->Get(v8::Integer::New(i))); 14419 v8::String::Utf8Value elm(props->Get(v8::Integer::New(isolate, i)));
14181 CHECK_EQ(elmv[i], *elm); 14420 CHECK_EQ(elmv[i], *elm);
14182 } 14421 }
14183 } 14422 }
14184 14423
14185 14424
14186 THREADED_TEST(PropertyEnumeration) { 14425 THREADED_TEST(PropertyEnumeration) {
14187 LocalContext context; 14426 LocalContext context;
14188 v8::HandleScope scope(context->GetIsolate()); 14427 v8::Isolate* isolate = context->GetIsolate();
14428 v8::HandleScope scope(isolate);
14189 v8::Handle<v8::Value> obj = v8::Script::Compile(v8::String::NewFromUtf8( 14429 v8::Handle<v8::Value> obj = v8::Script::Compile(v8::String::NewFromUtf8(
14190 context->GetIsolate(), 14430 context->GetIsolate(),
14191 "var result = [];" 14431 "var result = [];"
14192 "result[0] = {};" 14432 "result[0] = {};"
14193 "result[1] = {a: 1, b: 2};" 14433 "result[1] = {a: 1, b: 2};"
14194 "result[2] = [1, 2, 3];" 14434 "result[2] = [1, 2, 3];"
14195 "var proto = {x: 1, y: 2, z: 3};" 14435 "var proto = {x: 1, y: 2, z: 3};"
14196 "var x = { __proto__: proto, w: 0, z: 1 };" 14436 "var x = { __proto__: proto, w: 0, z: 1 };"
14197 "result[3] = x;" 14437 "result[3] = x;"
14198 "result;"))->Run(); 14438 "result;"))->Run();
14199 v8::Handle<v8::Array> elms = obj.As<v8::Array>(); 14439 v8::Handle<v8::Array> elms = obj.As<v8::Array>();
14200 CHECK_EQ(4, elms->Length()); 14440 CHECK_EQ(4, elms->Length());
14201 int elmc0 = 0; 14441 int elmc0 = 0;
14202 const char** elmv0 = NULL; 14442 const char** elmv0 = NULL;
14203 CheckProperties(elms->Get(v8::Integer::New(0)), elmc0, elmv0); 14443 CheckProperties(
14204 CheckOwnProperties(elms->Get(v8::Integer::New(0)), elmc0, elmv0); 14444 isolate, elms->Get(v8::Integer::New(isolate, 0)), elmc0, elmv0);
14445 CheckOwnProperties(
14446 isolate, elms->Get(v8::Integer::New(isolate, 0)), elmc0, elmv0);
14205 int elmc1 = 2; 14447 int elmc1 = 2;
14206 const char* elmv1[] = {"a", "b"}; 14448 const char* elmv1[] = {"a", "b"};
14207 CheckProperties(elms->Get(v8::Integer::New(1)), elmc1, elmv1); 14449 CheckProperties(
14208 CheckOwnProperties(elms->Get(v8::Integer::New(1)), elmc1, elmv1); 14450 isolate, elms->Get(v8::Integer::New(isolate, 1)), elmc1, elmv1);
14451 CheckOwnProperties(
14452 isolate, elms->Get(v8::Integer::New(isolate, 1)), elmc1, elmv1);
14209 int elmc2 = 3; 14453 int elmc2 = 3;
14210 const char* elmv2[] = {"0", "1", "2"}; 14454 const char* elmv2[] = {"0", "1", "2"};
14211 CheckProperties(elms->Get(v8::Integer::New(2)), elmc2, elmv2); 14455 CheckProperties(
14212 CheckOwnProperties(elms->Get(v8::Integer::New(2)), elmc2, elmv2); 14456 isolate, elms->Get(v8::Integer::New(isolate, 2)), elmc2, elmv2);
14457 CheckOwnProperties(
14458 isolate, elms->Get(v8::Integer::New(isolate, 2)), elmc2, elmv2);
14213 int elmc3 = 4; 14459 int elmc3 = 4;
14214 const char* elmv3[] = {"w", "z", "x", "y"}; 14460 const char* elmv3[] = {"w", "z", "x", "y"};
14215 CheckProperties(elms->Get(v8::Integer::New(3)), elmc3, elmv3); 14461 CheckProperties(
14462 isolate, elms->Get(v8::Integer::New(isolate, 3)), elmc3, elmv3);
14216 int elmc4 = 2; 14463 int elmc4 = 2;
14217 const char* elmv4[] = {"w", "z"}; 14464 const char* elmv4[] = {"w", "z"};
14218 CheckOwnProperties(elms->Get(v8::Integer::New(3)), elmc4, elmv4); 14465 CheckOwnProperties(
14466 isolate, elms->Get(v8::Integer::New(isolate, 3)), elmc4, elmv4);
14219 } 14467 }
14220 14468
14221 14469
14222 THREADED_TEST(PropertyEnumeration2) { 14470 THREADED_TEST(PropertyEnumeration2) {
14223 LocalContext context; 14471 LocalContext context;
14224 v8::HandleScope scope(context->GetIsolate()); 14472 v8::Isolate* isolate = context->GetIsolate();
14473 v8::HandleScope scope(isolate);
14225 v8::Handle<v8::Value> obj = v8::Script::Compile(v8::String::NewFromUtf8( 14474 v8::Handle<v8::Value> obj = v8::Script::Compile(v8::String::NewFromUtf8(
14226 context->GetIsolate(), 14475 context->GetIsolate(),
14227 "var result = [];" 14476 "var result = [];"
14228 "result[0] = {};" 14477 "result[0] = {};"
14229 "result[1] = {a: 1, b: 2};" 14478 "result[1] = {a: 1, b: 2};"
14230 "result[2] = [1, 2, 3];" 14479 "result[2] = [1, 2, 3];"
14231 "var proto = {x: 1, y: 2, z: 3};" 14480 "var proto = {x: 1, y: 2, z: 3};"
14232 "var x = { __proto__: proto, w: 0, z: 1 };" 14481 "var x = { __proto__: proto, w: 0, z: 1 };"
14233 "result[3] = x;" 14482 "result[3] = x;"
14234 "result;"))->Run(); 14483 "result;"))->Run();
14235 v8::Handle<v8::Array> elms = obj.As<v8::Array>(); 14484 v8::Handle<v8::Array> elms = obj.As<v8::Array>();
14236 CHECK_EQ(4, elms->Length()); 14485 CHECK_EQ(4, elms->Length());
14237 int elmc0 = 0; 14486 int elmc0 = 0;
14238 const char** elmv0 = NULL; 14487 const char** elmv0 = NULL;
14239 CheckProperties(elms->Get(v8::Integer::New(0)), elmc0, elmv0); 14488 CheckProperties(isolate,
14489 elms->Get(v8::Integer::New(isolate, 0)), elmc0, elmv0);
14240 14490
14241 v8::Handle<v8::Value> val = elms->Get(v8::Integer::New(0)); 14491 v8::Handle<v8::Value> val = elms->Get(v8::Integer::New(isolate, 0));
14242 v8::Handle<v8::Array> props = val.As<v8::Object>()->GetPropertyNames(); 14492 v8::Handle<v8::Array> props = val.As<v8::Object>()->GetPropertyNames();
14243 CHECK_EQ(0, props->Length()); 14493 CHECK_EQ(0, props->Length());
14244 for (uint32_t i = 0; i < props->Length(); i++) { 14494 for (uint32_t i = 0; i < props->Length(); i++) {
14245 printf("p[%d]\n", i); 14495 printf("p[%d]\n", i);
14246 } 14496 }
14247 } 14497 }
14248 14498
14249 static bool NamedSetAccessBlocker(Local<v8::Object> obj, 14499 static bool NamedSetAccessBlocker(Local<v8::Object> obj,
14250 Local<Value> name, 14500 Local<Value> name,
14251 v8::AccessType type, 14501 v8::AccessType type,
14252 Local<Value> data) { 14502 Local<Value> data) {
14253 return type != v8::ACCESS_SET; 14503 return type != v8::ACCESS_SET;
14254 } 14504 }
14255 14505
14256 14506
14257 static bool IndexedSetAccessBlocker(Local<v8::Object> obj, 14507 static bool IndexedSetAccessBlocker(Local<v8::Object> obj,
14258 uint32_t key, 14508 uint32_t key,
14259 v8::AccessType type, 14509 v8::AccessType type,
14260 Local<Value> data) { 14510 Local<Value> data) {
14261 return type != v8::ACCESS_SET; 14511 return type != v8::ACCESS_SET;
14262 } 14512 }
14263 14513
14264 14514
14265 THREADED_TEST(DisableAccessChecksWhileConfiguring) { 14515 THREADED_TEST(DisableAccessChecksWhileConfiguring) {
14266 LocalContext context; 14516 LocalContext context;
14267 v8::Isolate* isolate = context->GetIsolate(); 14517 v8::Isolate* isolate = context->GetIsolate();
14268 v8::HandleScope scope(isolate); 14518 v8::HandleScope scope(isolate);
14269 Local<ObjectTemplate> templ = ObjectTemplate::New(); 14519 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
14270 templ->SetAccessCheckCallbacks(NamedSetAccessBlocker, 14520 templ->SetAccessCheckCallbacks(NamedSetAccessBlocker,
14271 IndexedSetAccessBlocker); 14521 IndexedSetAccessBlocker);
14272 templ->Set(v8_str("x"), v8::True(isolate)); 14522 templ->Set(v8_str("x"), v8::True(isolate));
14273 Local<v8::Object> instance = templ->NewInstance(); 14523 Local<v8::Object> instance = templ->NewInstance();
14274 context->Global()->Set(v8_str("obj"), instance); 14524 context->Global()->Set(v8_str("obj"), instance);
14275 Local<Value> value = CompileRun("obj.x"); 14525 Local<Value> value = CompileRun("obj.x");
14276 CHECK(value->BooleanValue()); 14526 CHECK(value->BooleanValue());
14277 } 14527 }
14278 14528
14279 14529
14280 static bool NamedGetAccessBlocker(Local<v8::Object> obj, 14530 static bool NamedGetAccessBlocker(Local<v8::Object> obj,
14281 Local<Value> name, 14531 Local<Value> name,
14282 v8::AccessType type, 14532 v8::AccessType type,
14283 Local<Value> data) { 14533 Local<Value> data) {
14284 return false; 14534 return false;
14285 } 14535 }
14286 14536
14287 14537
14288 static bool IndexedGetAccessBlocker(Local<v8::Object> obj, 14538 static bool IndexedGetAccessBlocker(Local<v8::Object> obj,
14289 uint32_t key, 14539 uint32_t key,
14290 v8::AccessType type, 14540 v8::AccessType type,
14291 Local<Value> data) { 14541 Local<Value> data) {
14292 return false; 14542 return false;
14293 } 14543 }
14294 14544
14295 14545
14296 14546
14297 THREADED_TEST(AccessChecksReenabledCorrectly) { 14547 THREADED_TEST(AccessChecksReenabledCorrectly) {
14298 LocalContext context; 14548 LocalContext context;
14299 v8::HandleScope scope(context->GetIsolate()); 14549 v8::Isolate* isolate = context->GetIsolate();
14300 Local<ObjectTemplate> templ = ObjectTemplate::New(); 14550 v8::HandleScope scope(isolate);
14551 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
14301 templ->SetAccessCheckCallbacks(NamedGetAccessBlocker, 14552 templ->SetAccessCheckCallbacks(NamedGetAccessBlocker,
14302 IndexedGetAccessBlocker); 14553 IndexedGetAccessBlocker);
14303 templ->Set(v8_str("a"), v8_str("a")); 14554 templ->Set(v8_str("a"), v8_str("a"));
14304 // Add more than 8 (see kMaxFastProperties) properties 14555 // Add more than 8 (see kMaxFastProperties) properties
14305 // so that the constructor will force copying map. 14556 // so that the constructor will force copying map.
14306 // Cannot sprintf, gcc complains unsafety. 14557 // Cannot sprintf, gcc complains unsafety.
14307 char buf[4]; 14558 char buf[4];
14308 for (char i = '0'; i <= '9' ; i++) { 14559 for (char i = '0'; i <= '9' ; i++) {
14309 buf[0] = i; 14560 buf[0] = i;
14310 for (char j = '0'; j <= '9'; j++) { 14561 for (char j = '0'; j <= '9'; j++) {
14311 buf[1] = j; 14562 buf[1] = j;
14312 for (char k = '0'; k <= '9'; k++) { 14563 for (char k = '0'; k <= '9'; k++) {
14313 buf[2] = k; 14564 buf[2] = k;
14314 buf[3] = 0; 14565 buf[3] = 0;
14315 templ->Set(v8_str(buf), v8::Number::New(k)); 14566 templ->Set(v8_str(buf), v8::Number::New(isolate, k));
14316 } 14567 }
14317 } 14568 }
14318 } 14569 }
14319 14570
14320 Local<v8::Object> instance_1 = templ->NewInstance(); 14571 Local<v8::Object> instance_1 = templ->NewInstance();
14321 context->Global()->Set(v8_str("obj_1"), instance_1); 14572 context->Global()->Set(v8_str("obj_1"), instance_1);
14322 14573
14323 Local<Value> value_1 = CompileRun("obj_1.a"); 14574 Local<Value> value_1 = CompileRun("obj_1.a");
14324 CHECK(value_1->IsUndefined()); 14575 CHECK(value_1->IsUndefined());
14325 14576
14326 Local<v8::Object> instance_2 = templ->NewInstance(); 14577 Local<v8::Object> instance_2 = templ->NewInstance();
14327 context->Global()->Set(v8_str("obj_2"), instance_2); 14578 context->Global()->Set(v8_str("obj_2"), instance_2);
14328 14579
14329 Local<Value> value_2 = CompileRun("obj_2.a"); 14580 Local<Value> value_2 = CompileRun("obj_2.a");
14330 CHECK(value_2->IsUndefined()); 14581 CHECK(value_2->IsUndefined());
14331 } 14582 }
14332 14583
14333 14584
14334 // This tests that access check information remains on the global 14585 // This tests that access check information remains on the global
14335 // object template when creating contexts. 14586 // object template when creating contexts.
14336 THREADED_TEST(AccessControlRepeatedContextCreation) { 14587 THREADED_TEST(AccessControlRepeatedContextCreation) {
14337 v8::Isolate* isolate = CcTest::isolate(); 14588 v8::Isolate* isolate = CcTest::isolate();
14338 v8::HandleScope handle_scope(isolate); 14589 v8::HandleScope handle_scope(isolate);
14339 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 14590 v8::Handle<v8::ObjectTemplate> global_template =
14591 v8::ObjectTemplate::New(isolate);
14340 global_template->SetAccessCheckCallbacks(NamedSetAccessBlocker, 14592 global_template->SetAccessCheckCallbacks(NamedSetAccessBlocker,
14341 IndexedSetAccessBlocker); 14593 IndexedSetAccessBlocker);
14342 i::Handle<i::ObjectTemplateInfo> internal_template = 14594 i::Handle<i::ObjectTemplateInfo> internal_template =
14343 v8::Utils::OpenHandle(*global_template); 14595 v8::Utils::OpenHandle(*global_template);
14344 CHECK(!internal_template->constructor()->IsUndefined()); 14596 CHECK(!internal_template->constructor()->IsUndefined());
14345 i::Handle<i::FunctionTemplateInfo> constructor( 14597 i::Handle<i::FunctionTemplateInfo> constructor(
14346 i::FunctionTemplateInfo::cast(internal_template->constructor())); 14598 i::FunctionTemplateInfo::cast(internal_template->constructor()));
14347 CHECK(!constructor->access_check_info()->IsUndefined()); 14599 CHECK(!constructor->access_check_info()->IsUndefined());
14348 v8::Local<Context> context0(Context::New(isolate, NULL, global_template)); 14600 v8::Local<Context> context0(Context::New(isolate, NULL, global_template));
14349 CHECK(!context0.IsEmpty()); 14601 CHECK(!context0.IsEmpty());
14350 CHECK(!constructor->access_check_info()->IsUndefined()); 14602 CHECK(!constructor->access_check_info()->IsUndefined());
14351 } 14603 }
14352 14604
14353 14605
14354 THREADED_TEST(TurnOnAccessCheck) { 14606 THREADED_TEST(TurnOnAccessCheck) {
14355 v8::Isolate* isolate = CcTest::isolate(); 14607 v8::Isolate* isolate = CcTest::isolate();
14356 v8::HandleScope handle_scope(isolate); 14608 v8::HandleScope handle_scope(isolate);
14357 14609
14358 // Create an environment with access check to the global object disabled by 14610 // Create an environment with access check to the global object disabled by
14359 // default. 14611 // default.
14360 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 14612 v8::Handle<v8::ObjectTemplate> global_template =
14613 v8::ObjectTemplate::New(isolate);
14361 global_template->SetAccessCheckCallbacks(NamedGetAccessBlocker, 14614 global_template->SetAccessCheckCallbacks(NamedGetAccessBlocker,
14362 IndexedGetAccessBlocker, 14615 IndexedGetAccessBlocker,
14363 v8::Handle<v8::Value>(), 14616 v8::Handle<v8::Value>(),
14364 false); 14617 false);
14365 v8::Local<Context> context = Context::New(isolate, NULL, global_template); 14618 v8::Local<Context> context = Context::New(isolate, NULL, global_template);
14366 Context::Scope context_scope(context); 14619 Context::Scope context_scope(context);
14367 14620
14368 // Set up a property and a number of functions. 14621 // Set up a property and a number of functions.
14369 context->Global()->Set(v8_str("a"), v8_num(1)); 14622 context->Global()->Set(v8_str("a"), v8_num(1));
14370 CompileRun("function f1() {return a;}" 14623 CompileRun("function f1() {return a;}"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
14434 } 14687 }
14435 14688
14436 14689
14437 THREADED_TEST(TurnOnAccessCheckAndRecompile) { 14690 THREADED_TEST(TurnOnAccessCheckAndRecompile) {
14438 v8::Isolate* isolate = CcTest::isolate(); 14691 v8::Isolate* isolate = CcTest::isolate();
14439 v8::HandleScope handle_scope(isolate); 14692 v8::HandleScope handle_scope(isolate);
14440 14693
14441 // Create an environment with access check to the global object disabled by 14694 // Create an environment with access check to the global object disabled by
14442 // default. When the registered access checker will block access to properties 14695 // default. When the registered access checker will block access to properties
14443 // a and h. 14696 // a and h.
14444 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 14697 v8::Handle<v8::ObjectTemplate> global_template =
14698 v8::ObjectTemplate::New(isolate);
14445 global_template->SetAccessCheckCallbacks(NamedGetAccessBlockAandH, 14699 global_template->SetAccessCheckCallbacks(NamedGetAccessBlockAandH,
14446 IndexedGetAccessBlocker, 14700 IndexedGetAccessBlocker,
14447 v8::Handle<v8::Value>(), 14701 v8::Handle<v8::Value>(),
14448 false); 14702 false);
14449 v8::Local<Context> context = Context::New(isolate, NULL, global_template); 14703 v8::Local<Context> context = Context::New(isolate, NULL, global_template);
14450 Context::Scope context_scope(context); 14704 Context::Scope context_scope(context);
14451 14705
14452 // Set up a property and a number of functions. 14706 // Set up a property and a number of functions.
14453 context->Global()->Set(v8_str("a"), v8_num(1)); 14707 context->Global()->Set(v8_str("a"), v8_num(1));
14454 static const char* source = "function f1() {return a;}" 14708 static const char* source = "function f1() {return a;}"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
14524 14778
14525 14779
14526 // This test verifies that pre-compilation (aka preparsing) can be called 14780 // This test verifies that pre-compilation (aka preparsing) can be called
14527 // without initializing the whole VM. Thus we cannot run this test in a 14781 // without initializing the whole VM. Thus we cannot run this test in a
14528 // multi-threaded setup. 14782 // multi-threaded setup.
14529 TEST(PreCompile) { 14783 TEST(PreCompile) {
14530 // TODO(155): This test would break without the initialization of V8. This is 14784 // TODO(155): This test would break without the initialization of V8. This is
14531 // a workaround for now to make this test not fail. 14785 // a workaround for now to make this test not fail.
14532 v8::V8::Initialize(); 14786 v8::V8::Initialize();
14533 v8::Isolate* isolate = CcTest::isolate(); 14787 v8::Isolate* isolate = CcTest::isolate();
14788 HandleScope handle_scope(isolate);
14534 const char* script = "function foo(a) { return a+1; }"; 14789 const char* script = "function foo(a) { return a+1; }";
14535 v8::ScriptData* sd = 14790 v8::ScriptData* sd = v8::ScriptData::PreCompile(v8::String::NewFromUtf8(
14536 v8::ScriptData::PreCompile(isolate, script, i::StrLength(script)); 14791 isolate, script, v8::String::kNormalString, i::StrLength(script)));
14537 CHECK_NE(sd->Length(), 0); 14792 CHECK_NE(sd->Length(), 0);
14538 CHECK_NE(sd->Data(), NULL); 14793 CHECK_NE(sd->Data(), NULL);
14539 CHECK(!sd->HasError()); 14794 CHECK(!sd->HasError());
14540 delete sd; 14795 delete sd;
14541 } 14796 }
14542 14797
14543 14798
14544 TEST(PreCompileWithError) { 14799 TEST(PreCompileWithError) {
14545 v8::V8::Initialize(); 14800 v8::V8::Initialize();
14546 v8::Isolate* isolate = CcTest::isolate(); 14801 v8::Isolate* isolate = CcTest::isolate();
14802 HandleScope handle_scope(isolate);
14547 const char* script = "function foo(a) { return 1 * * 2; }"; 14803 const char* script = "function foo(a) { return 1 * * 2; }";
14548 v8::ScriptData* sd = 14804 v8::ScriptData* sd = v8::ScriptData::PreCompile(v8::String::NewFromUtf8(
14549 v8::ScriptData::PreCompile(isolate, script, i::StrLength(script)); 14805 isolate, script, v8::String::kNormalString, i::StrLength(script)));
14550 CHECK(sd->HasError()); 14806 CHECK(sd->HasError());
14551 delete sd; 14807 delete sd;
14552 } 14808 }
14553 14809
14554 14810
14555 TEST(Regress31661) { 14811 TEST(Regress31661) {
14556 v8::V8::Initialize(); 14812 v8::V8::Initialize();
14557 v8::Isolate* isolate = CcTest::isolate(); 14813 v8::Isolate* isolate = CcTest::isolate();
14814 HandleScope handle_scope(isolate);
14558 const char* script = " The Definintive Guide"; 14815 const char* script = " The Definintive Guide";
14559 v8::ScriptData* sd = 14816 v8::ScriptData* sd = v8::ScriptData::PreCompile(v8::String::NewFromUtf8(
14560 v8::ScriptData::PreCompile(isolate, script, i::StrLength(script)); 14817 isolate, script, v8::String::kNormalString, i::StrLength(script)));
14561 CHECK(sd->HasError()); 14818 CHECK(sd->HasError());
14562 delete sd; 14819 delete sd;
14563 } 14820 }
14564 14821
14565 14822
14566 // Tests that ScriptData can be serialized and deserialized. 14823 // Tests that ScriptData can be serialized and deserialized.
14567 TEST(PreCompileSerialization) { 14824 TEST(PreCompileSerialization) {
14568 v8::V8::Initialize(); 14825 v8::V8::Initialize();
14569 v8::Isolate* isolate = CcTest::isolate(); 14826 v8::Isolate* isolate = CcTest::isolate();
14827 HandleScope handle_scope(isolate);
14570 const char* script = "function foo(a) { return a+1; }"; 14828 const char* script = "function foo(a) { return a+1; }";
14571 v8::ScriptData* sd = 14829 v8::ScriptData* sd = v8::ScriptData::PreCompile(v8::String::NewFromUtf8(
14572 v8::ScriptData::PreCompile(isolate, script, i::StrLength(script)); 14830 isolate, script, v8::String::kNormalString, i::StrLength(script)));
14573 14831
14574 // Serialize. 14832 // Serialize.
14575 int serialized_data_length = sd->Length(); 14833 int serialized_data_length = sd->Length();
14576 char* serialized_data = i::NewArray<char>(serialized_data_length); 14834 char* serialized_data = i::NewArray<char>(serialized_data_length);
14577 i::OS::MemCopy(serialized_data, sd->Data(), serialized_data_length); 14835 i::OS::MemCopy(serialized_data, sd->Data(), serialized_data_length);
14578 14836
14579 // Deserialize. 14837 // Deserialize.
14580 v8::ScriptData* deserialized_sd = 14838 v8::ScriptData* deserialized_sd =
14581 v8::ScriptData::New(serialized_data, serialized_data_length); 14839 v8::ScriptData::New(serialized_data, serialized_data_length);
14582 14840
(...skipping 22 matching lines...) Expand all
14605 14863
14606 // Attempts to deserialize bad data. 14864 // Attempts to deserialize bad data.
14607 TEST(PreCompileInvalidPreparseDataError) { 14865 TEST(PreCompileInvalidPreparseDataError) {
14608 v8::V8::Initialize(); 14866 v8::V8::Initialize();
14609 v8::Isolate* isolate = CcTest::isolate(); 14867 v8::Isolate* isolate = CcTest::isolate();
14610 LocalContext context; 14868 LocalContext context;
14611 v8::HandleScope scope(context->GetIsolate()); 14869 v8::HandleScope scope(context->GetIsolate());
14612 14870
14613 const char* script = "function foo(){ return 5;}\n" 14871 const char* script = "function foo(){ return 5;}\n"
14614 "function bar(){ return 6 + 7;} foo();"; 14872 "function bar(){ return 6 + 7;} foo();";
14615 v8::ScriptData* sd = 14873 v8::ScriptData* sd = v8::ScriptData::PreCompile(v8::String::NewFromUtf8(
14616 v8::ScriptData::PreCompile(isolate, script, i::StrLength(script)); 14874 isolate, script, v8::String::kNormalString, i::StrLength(script)));
14617 CHECK(!sd->HasError()); 14875 CHECK(!sd->HasError());
14618 // ScriptDataImpl private implementation details 14876 // ScriptDataImpl private implementation details
14619 const int kHeaderSize = i::PreparseDataConstants::kHeaderSize; 14877 const int kHeaderSize = i::PreparseDataConstants::kHeaderSize;
14620 const int kFunctionEntrySize = i::FunctionEntry::kSize; 14878 const int kFunctionEntrySize = i::FunctionEntry::kSize;
14621 const int kFunctionEntryStartOffset = 0; 14879 const int kFunctionEntryStartOffset = 0;
14622 const int kFunctionEntryEndOffset = 1; 14880 const int kFunctionEntryEndOffset = 1;
14623 unsigned* sd_data = 14881 unsigned* sd_data =
14624 reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data())); 14882 reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data()));
14625 14883
14626 // Overwrite function bar's end position with 0. 14884 // Overwrite function bar's end position with 0.
14627 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryEndOffset] = 0; 14885 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryEndOffset] = 0;
14628 v8::TryCatch try_catch; 14886 v8::TryCatch try_catch;
14629 14887
14630 Local<String> source = String::NewFromUtf8(isolate, script); 14888 Local<String> source = String::NewFromUtf8(isolate, script);
14631 Local<Script> compiled_script = Script::New(source, NULL, sd); 14889 Local<Script> compiled_script = Script::New(source, NULL, sd);
14632 CHECK(try_catch.HasCaught()); 14890 CHECK(try_catch.HasCaught());
14633 String::Utf8Value exception_value(try_catch.Message()->Get()); 14891 String::Utf8Value exception_value(try_catch.Message()->Get());
14634 CHECK_EQ("Uncaught SyntaxError: Invalid preparser data for function bar", 14892 CHECK_EQ("Uncaught SyntaxError: Invalid preparser data for function bar",
14635 *exception_value); 14893 *exception_value);
14636 14894
14637 try_catch.Reset(); 14895 try_catch.Reset();
14638 14896
14639 // Overwrite function bar's start position with 200. The function entry 14897 // Overwrite function bar's start position with 200. The function entry
14640 // will not be found when searching for it by position and we should fall 14898 // will not be found when searching for it by position and we should fall
14641 // back on eager compilation. 14899 // back on eager compilation.
14642 sd = v8::ScriptData::PreCompile(isolate, script, i::StrLength(script)); 14900 sd = v8::ScriptData::PreCompile(v8::String::NewFromUtf8(
14901 isolate, script, v8::String::kNormalString, i::StrLength(script)));
14643 sd_data = reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data())); 14902 sd_data = reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data()));
14644 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryStartOffset] = 14903 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryStartOffset] =
14645 200; 14904 200;
14646 compiled_script = Script::New(source, NULL, sd); 14905 compiled_script = Script::New(source, NULL, sd);
14647 CHECK(!try_catch.HasCaught()); 14906 CHECK(!try_catch.HasCaught());
14648 14907
14649 delete sd; 14908 delete sd;
14650 } 14909 }
14651 14910
14652 14911
14653 // Verifies that the Handle<String> and const char* versions of the API produce
14654 // the same results (at least for one trivial case).
14655 TEST(PreCompileAPIVariationsAreSame) {
14656 v8::V8::Initialize();
14657 v8::Isolate* isolate = CcTest::isolate();
14658 v8::HandleScope scope(isolate);
14659
14660 const char* cstring = "function foo(a) { return a+1; }";
14661
14662 v8::ScriptData* sd_from_cstring =
14663 v8::ScriptData::PreCompile(isolate, cstring, i::StrLength(cstring));
14664
14665 TestAsciiResource* resource = new TestAsciiResource(cstring);
14666 v8::ScriptData* sd_from_external_string = v8::ScriptData::PreCompile(
14667 v8::String::NewExternal(isolate, resource));
14668
14669 v8::ScriptData* sd_from_string = v8::ScriptData::PreCompile(
14670 v8::String::NewFromUtf8(isolate, cstring));
14671
14672 CHECK_EQ(sd_from_cstring->Length(), sd_from_external_string->Length());
14673 CHECK_EQ(0, memcmp(sd_from_cstring->Data(),
14674 sd_from_external_string->Data(),
14675 sd_from_cstring->Length()));
14676
14677 CHECK_EQ(sd_from_cstring->Length(), sd_from_string->Length());
14678 CHECK_EQ(0, memcmp(sd_from_cstring->Data(),
14679 sd_from_string->Data(),
14680 sd_from_cstring->Length()));
14681
14682
14683 delete sd_from_cstring;
14684 delete sd_from_external_string;
14685 delete sd_from_string;
14686 }
14687
14688
14689 // This tests that we do not allow dictionary load/call inline caches 14912 // This tests that we do not allow dictionary load/call inline caches
14690 // to use functions that have not yet been compiled. The potential 14913 // to use functions that have not yet been compiled. The potential
14691 // problem of loading a function that has not yet been compiled can 14914 // problem of loading a function that has not yet been compiled can
14692 // arise because we share code between contexts via the compilation 14915 // arise because we share code between contexts via the compilation
14693 // cache. 14916 // cache.
14694 THREADED_TEST(DictionaryICLoadedFunction) { 14917 THREADED_TEST(DictionaryICLoadedFunction) {
14695 v8::HandleScope scope(CcTest::isolate()); 14918 v8::HandleScope scope(CcTest::isolate());
14696 // Test LoadIC. 14919 // Test LoadIC.
14697 for (int i = 0; i < 2; i++) { 14920 for (int i = 0; i < 2; i++) {
14698 LocalContext context; 14921 LocalContext context;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
14736 Local<Value> value = CompileRun("var instance = new other.C(); instance.x"); 14959 Local<Value> value = CompileRun("var instance = new other.C(); instance.x");
14737 CHECK(value->IsInt32()); 14960 CHECK(value->IsInt32());
14738 CHECK_EQ(42, value->Int32Value()); 14961 CHECK_EQ(42, value->Int32Value());
14739 context1->Exit(); 14962 context1->Exit();
14740 } 14963 }
14741 14964
14742 14965
14743 // Verify that we can clone an object 14966 // Verify that we can clone an object
14744 TEST(ObjectClone) { 14967 TEST(ObjectClone) {
14745 LocalContext env; 14968 LocalContext env;
14746 v8::HandleScope scope(env->GetIsolate()); 14969 v8::Isolate* isolate = env->GetIsolate();
14970 v8::HandleScope scope(isolate);
14747 14971
14748 const char* sample = 14972 const char* sample =
14749 "var rv = {};" \ 14973 "var rv = {};" \
14750 "rv.alpha = 'hello';" \ 14974 "rv.alpha = 'hello';" \
14751 "rv.beta = 123;" \ 14975 "rv.beta = 123;" \
14752 "rv;"; 14976 "rv;";
14753 14977
14754 // Create an object, verify basics. 14978 // Create an object, verify basics.
14755 Local<Value> val = CompileRun(sample); 14979 Local<Value> val = CompileRun(sample);
14756 CHECK(val->IsObject()); 14980 CHECK(val->IsObject());
14757 Local<v8::Object> obj = val.As<v8::Object>(); 14981 Local<v8::Object> obj = val.As<v8::Object>();
14758 obj->Set(v8_str("gamma"), v8_str("cloneme")); 14982 obj->Set(v8_str("gamma"), v8_str("cloneme"));
14759 14983
14760 CHECK_EQ(v8_str("hello"), obj->Get(v8_str("alpha"))); 14984 CHECK_EQ(v8_str("hello"), obj->Get(v8_str("alpha")));
14761 CHECK_EQ(v8::Integer::New(123), obj->Get(v8_str("beta"))); 14985 CHECK_EQ(v8::Integer::New(isolate, 123), obj->Get(v8_str("beta")));
14762 CHECK_EQ(v8_str("cloneme"), obj->Get(v8_str("gamma"))); 14986 CHECK_EQ(v8_str("cloneme"), obj->Get(v8_str("gamma")));
14763 14987
14764 // Clone it. 14988 // Clone it.
14765 Local<v8::Object> clone = obj->Clone(); 14989 Local<v8::Object> clone = obj->Clone();
14766 CHECK_EQ(v8_str("hello"), clone->Get(v8_str("alpha"))); 14990 CHECK_EQ(v8_str("hello"), clone->Get(v8_str("alpha")));
14767 CHECK_EQ(v8::Integer::New(123), clone->Get(v8_str("beta"))); 14991 CHECK_EQ(v8::Integer::New(isolate, 123), clone->Get(v8_str("beta")));
14768 CHECK_EQ(v8_str("cloneme"), clone->Get(v8_str("gamma"))); 14992 CHECK_EQ(v8_str("cloneme"), clone->Get(v8_str("gamma")));
14769 14993
14770 // Set a property on the clone, verify each object. 14994 // Set a property on the clone, verify each object.
14771 clone->Set(v8_str("beta"), v8::Integer::New(456)); 14995 clone->Set(v8_str("beta"), v8::Integer::New(isolate, 456));
14772 CHECK_EQ(v8::Integer::New(123), obj->Get(v8_str("beta"))); 14996 CHECK_EQ(v8::Integer::New(isolate, 123), obj->Get(v8_str("beta")));
14773 CHECK_EQ(v8::Integer::New(456), clone->Get(v8_str("beta"))); 14997 CHECK_EQ(v8::Integer::New(isolate, 456), clone->Get(v8_str("beta")));
14774 } 14998 }
14775 14999
14776 15000
14777 class AsciiVectorResource : public v8::String::ExternalAsciiStringResource { 15001 class AsciiVectorResource : public v8::String::ExternalAsciiStringResource {
14778 public: 15002 public:
14779 explicit AsciiVectorResource(i::Vector<const char> vector) 15003 explicit AsciiVectorResource(i::Vector<const char> vector)
14780 : data_(vector) {} 15004 : data_(vector) {}
14781 virtual ~AsciiVectorResource() {} 15005 virtual ~AsciiVectorResource() {}
14782 virtual size_t length() const { return data_.length(); } 15006 virtual size_t length() const { return data_.length(); }
14783 virtual const char* data() const { return data_.start(); } 15007 virtual const char* data() const { return data_.start(); }
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
14991 regexp_interruption_data.string.Reset(); 15215 regexp_interruption_data.string.Reset();
14992 } 15216 }
14993 15217
14994 #endif // V8_INTERPRETED_REGEXP 15218 #endif // V8_INTERPRETED_REGEXP
14995 15219
14996 15220
14997 // Test that we cannot set a property on the global object if there 15221 // Test that we cannot set a property on the global object if there
14998 // is a read-only property in the prototype chain. 15222 // is a read-only property in the prototype chain.
14999 TEST(ReadOnlyPropertyInGlobalProto) { 15223 TEST(ReadOnlyPropertyInGlobalProto) {
15000 i::FLAG_es5_readonly = true; 15224 i::FLAG_es5_readonly = true;
15001 v8::HandleScope scope(CcTest::isolate()); 15225 v8::Isolate* isolate = CcTest::isolate();
15002 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); 15226 v8::HandleScope scope(isolate);
15227 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate);
15003 LocalContext context(0, templ); 15228 LocalContext context(0, templ);
15004 v8::Handle<v8::Object> global = context->Global(); 15229 v8::Handle<v8::Object> global = context->Global();
15005 v8::Handle<v8::Object> global_proto = 15230 v8::Handle<v8::Object> global_proto =
15006 v8::Handle<v8::Object>::Cast(global->Get(v8_str("__proto__"))); 15231 v8::Handle<v8::Object>::Cast(global->Get(v8_str("__proto__")));
15007 global_proto->Set(v8_str("x"), v8::Integer::New(0), v8::ReadOnly); 15232 global_proto->Set(v8_str("x"), v8::Integer::New(isolate, 0), v8::ReadOnly);
15008 global_proto->Set(v8_str("y"), v8::Integer::New(0), v8::ReadOnly); 15233 global_proto->Set(v8_str("y"), v8::Integer::New(isolate, 0), v8::ReadOnly);
15009 // Check without 'eval' or 'with'. 15234 // Check without 'eval' or 'with'.
15010 v8::Handle<v8::Value> res = 15235 v8::Handle<v8::Value> res =
15011 CompileRun("function f() { x = 42; return x; }; f()"); 15236 CompileRun("function f() { x = 42; return x; }; f()");
15012 CHECK_EQ(v8::Integer::New(0), res); 15237 CHECK_EQ(v8::Integer::New(isolate, 0), res);
15013 // Check with 'eval'. 15238 // Check with 'eval'.
15014 res = CompileRun("function f() { eval('1'); y = 43; return y; }; f()"); 15239 res = CompileRun("function f() { eval('1'); y = 43; return y; }; f()");
15015 CHECK_EQ(v8::Integer::New(0), res); 15240 CHECK_EQ(v8::Integer::New(isolate, 0), res);
15016 // Check with 'with'. 15241 // Check with 'with'.
15017 res = CompileRun("function f() { with (this) { y = 44 }; return y; }; f()"); 15242 res = CompileRun("function f() { with (this) { y = 44 }; return y; }; f()");
15018 CHECK_EQ(v8::Integer::New(0), res); 15243 CHECK_EQ(v8::Integer::New(isolate, 0), res);
15019 } 15244 }
15020 15245
15021 static int force_set_set_count = 0; 15246 static int force_set_set_count = 0;
15022 static int force_set_get_count = 0; 15247 static int force_set_get_count = 0;
15023 bool pass_on_get = false; 15248 bool pass_on_get = false;
15024 15249
15025 static void ForceSetGetter(v8::Local<v8::String> name, 15250 static void ForceSetGetter(v8::Local<v8::String> name,
15026 const v8::PropertyCallbackInfo<v8::Value>& info) { 15251 const v8::PropertyCallbackInfo<v8::Value>& info) {
15027 force_set_get_count++; 15252 force_set_get_count++;
15028 if (pass_on_get) { 15253 if (pass_on_get) {
(...skipping 15 matching lines...) Expand all
15044 force_set_set_count++; 15269 force_set_set_count++;
15045 info.GetReturnValue().SetUndefined(); 15270 info.GetReturnValue().SetUndefined();
15046 } 15271 }
15047 15272
15048 15273
15049 TEST(ForceSet) { 15274 TEST(ForceSet) {
15050 force_set_get_count = 0; 15275 force_set_get_count = 0;
15051 force_set_set_count = 0; 15276 force_set_set_count = 0;
15052 pass_on_get = false; 15277 pass_on_get = false;
15053 15278
15054 v8::HandleScope scope(CcTest::isolate()); 15279 v8::Isolate* isolate = CcTest::isolate();
15055 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); 15280 v8::HandleScope scope(isolate);
15281 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate);
15056 v8::Handle<v8::String> access_property = 15282 v8::Handle<v8::String> access_property =
15057 v8::String::NewFromUtf8(CcTest::isolate(), "a"); 15283 v8::String::NewFromUtf8(isolate, "a");
15058 templ->SetAccessor(access_property, ForceSetGetter, ForceSetSetter); 15284 templ->SetAccessor(access_property, ForceSetGetter, ForceSetSetter);
15059 LocalContext context(NULL, templ); 15285 LocalContext context(NULL, templ);
15060 v8::Handle<v8::Object> global = context->Global(); 15286 v8::Handle<v8::Object> global = context->Global();
15061 15287
15062 // Ordinary properties 15288 // Ordinary properties
15063 v8::Handle<v8::String> simple_property = 15289 v8::Handle<v8::String> simple_property =
15064 v8::String::NewFromUtf8(CcTest::isolate(), "p"); 15290 v8::String::NewFromUtf8(isolate, "p");
15065 global->Set(simple_property, v8::Int32::New(4), v8::ReadOnly); 15291 global->Set(simple_property, v8::Int32::New(isolate, 4), v8::ReadOnly);
15066 CHECK_EQ(4, global->Get(simple_property)->Int32Value()); 15292 CHECK_EQ(4, global->Get(simple_property)->Int32Value());
15067 // This should fail because the property is read-only 15293 // This should fail because the property is read-only
15068 global->Set(simple_property, v8::Int32::New(5)); 15294 global->Set(simple_property, v8::Int32::New(isolate, 5));
15069 CHECK_EQ(4, global->Get(simple_property)->Int32Value()); 15295 CHECK_EQ(4, global->Get(simple_property)->Int32Value());
15070 // This should succeed even though the property is read-only 15296 // This should succeed even though the property is read-only
15071 global->ForceSet(simple_property, v8::Int32::New(6)); 15297 global->ForceSet(simple_property, v8::Int32::New(isolate, 6));
15072 CHECK_EQ(6, global->Get(simple_property)->Int32Value()); 15298 CHECK_EQ(6, global->Get(simple_property)->Int32Value());
15073 15299
15074 // Accessors 15300 // Accessors
15075 CHECK_EQ(0, force_set_set_count); 15301 CHECK_EQ(0, force_set_set_count);
15076 CHECK_EQ(0, force_set_get_count); 15302 CHECK_EQ(0, force_set_get_count);
15077 CHECK_EQ(3, global->Get(access_property)->Int32Value()); 15303 CHECK_EQ(3, global->Get(access_property)->Int32Value());
15078 // CHECK_EQ the property shouldn't override it, just call the setter 15304 // CHECK_EQ the property shouldn't override it, just call the setter
15079 // which in this case does nothing. 15305 // which in this case does nothing.
15080 global->Set(access_property, v8::Int32::New(7)); 15306 global->Set(access_property, v8::Int32::New(isolate, 7));
15081 CHECK_EQ(3, global->Get(access_property)->Int32Value()); 15307 CHECK_EQ(3, global->Get(access_property)->Int32Value());
15082 CHECK_EQ(1, force_set_set_count); 15308 CHECK_EQ(1, force_set_set_count);
15083 CHECK_EQ(2, force_set_get_count); 15309 CHECK_EQ(2, force_set_get_count);
15084 // Forcing the property to be set should override the accessor without 15310 // Forcing the property to be set should override the accessor without
15085 // calling it 15311 // calling it
15086 global->ForceSet(access_property, v8::Int32::New(8)); 15312 global->ForceSet(access_property, v8::Int32::New(isolate, 8));
15087 CHECK_EQ(8, global->Get(access_property)->Int32Value()); 15313 CHECK_EQ(8, global->Get(access_property)->Int32Value());
15088 CHECK_EQ(1, force_set_set_count); 15314 CHECK_EQ(1, force_set_set_count);
15089 CHECK_EQ(2, force_set_get_count); 15315 CHECK_EQ(2, force_set_get_count);
15090 } 15316 }
15091 15317
15092 15318
15093 TEST(ForceSetWithInterceptor) { 15319 TEST(ForceSetWithInterceptor) {
15094 force_set_get_count = 0; 15320 force_set_get_count = 0;
15095 force_set_set_count = 0; 15321 force_set_set_count = 0;
15096 pass_on_get = false; 15322 pass_on_get = false;
15097 15323
15098 v8::HandleScope scope(CcTest::isolate()); 15324 v8::Isolate* isolate = CcTest::isolate();
15099 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); 15325 v8::HandleScope scope(isolate);
15326 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate);
15100 templ->SetNamedPropertyHandler(ForceSetGetter, ForceSetInterceptSetter); 15327 templ->SetNamedPropertyHandler(ForceSetGetter, ForceSetInterceptSetter);
15101 LocalContext context(NULL, templ); 15328 LocalContext context(NULL, templ);
15102 v8::Handle<v8::Object> global = context->Global(); 15329 v8::Handle<v8::Object> global = context->Global();
15103 15330
15104 v8::Handle<v8::String> some_property = 15331 v8::Handle<v8::String> some_property =
15105 v8::String::NewFromUtf8(CcTest::isolate(), "a"); 15332 v8::String::NewFromUtf8(isolate, "a");
15106 CHECK_EQ(0, force_set_set_count); 15333 CHECK_EQ(0, force_set_set_count);
15107 CHECK_EQ(0, force_set_get_count); 15334 CHECK_EQ(0, force_set_get_count);
15108 CHECK_EQ(3, global->Get(some_property)->Int32Value()); 15335 CHECK_EQ(3, global->Get(some_property)->Int32Value());
15109 // Setting the property shouldn't override it, just call the setter 15336 // Setting the property shouldn't override it, just call the setter
15110 // which in this case does nothing. 15337 // which in this case does nothing.
15111 global->Set(some_property, v8::Int32::New(7)); 15338 global->Set(some_property, v8::Int32::New(isolate, 7));
15112 CHECK_EQ(3, global->Get(some_property)->Int32Value()); 15339 CHECK_EQ(3, global->Get(some_property)->Int32Value());
15113 CHECK_EQ(1, force_set_set_count); 15340 CHECK_EQ(1, force_set_set_count);
15114 CHECK_EQ(2, force_set_get_count); 15341 CHECK_EQ(2, force_set_get_count);
15115 // Getting the property when the interceptor returns an empty handle 15342 // Getting the property when the interceptor returns an empty handle
15116 // should yield undefined, since the property isn't present on the 15343 // should yield undefined, since the property isn't present on the
15117 // object itself yet. 15344 // object itself yet.
15118 pass_on_get = true; 15345 pass_on_get = true;
15119 CHECK(global->Get(some_property)->IsUndefined()); 15346 CHECK(global->Get(some_property)->IsUndefined());
15120 CHECK_EQ(1, force_set_set_count); 15347 CHECK_EQ(1, force_set_set_count);
15121 CHECK_EQ(3, force_set_get_count); 15348 CHECK_EQ(3, force_set_get_count);
15122 // Forcing the property to be set should cause the value to be 15349 // Forcing the property to be set should cause the value to be
15123 // set locally without calling the interceptor. 15350 // set locally without calling the interceptor.
15124 global->ForceSet(some_property, v8::Int32::New(8)); 15351 global->ForceSet(some_property, v8::Int32::New(isolate, 8));
15125 CHECK_EQ(8, global->Get(some_property)->Int32Value()); 15352 CHECK_EQ(8, global->Get(some_property)->Int32Value());
15126 CHECK_EQ(1, force_set_set_count); 15353 CHECK_EQ(1, force_set_set_count);
15127 CHECK_EQ(4, force_set_get_count); 15354 CHECK_EQ(4, force_set_get_count);
15128 // Reenabling the interceptor should cause it to take precedence over 15355 // Reenabling the interceptor should cause it to take precedence over
15129 // the property 15356 // the property
15130 pass_on_get = false; 15357 pass_on_get = false;
15131 CHECK_EQ(3, global->Get(some_property)->Int32Value()); 15358 CHECK_EQ(3, global->Get(some_property)->Int32Value());
15132 CHECK_EQ(1, force_set_set_count); 15359 CHECK_EQ(1, force_set_set_count);
15133 CHECK_EQ(5, force_set_get_count); 15360 CHECK_EQ(5, force_set_get_count);
15134 // The interceptor should also work for other properties 15361 // The interceptor should also work for other properties
15135 CHECK_EQ(3, global->Get(v8::String::NewFromUtf8(CcTest::isolate(), "b")) 15362 CHECK_EQ(3, global->Get(v8::String::NewFromUtf8(isolate, "b"))
15136 ->Int32Value()); 15363 ->Int32Value());
15137 CHECK_EQ(1, force_set_set_count); 15364 CHECK_EQ(1, force_set_set_count);
15138 CHECK_EQ(6, force_set_get_count); 15365 CHECK_EQ(6, force_set_get_count);
15139 } 15366 }
15140 15367
15141 15368
15142 THREADED_TEST(ForceDelete) { 15369 THREADED_TEST(ForceDelete) {
15143 v8::HandleScope scope(CcTest::isolate()); 15370 v8::Isolate* isolate = CcTest::isolate();
15144 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); 15371 v8::HandleScope scope(isolate);
15372 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate);
15145 LocalContext context(NULL, templ); 15373 LocalContext context(NULL, templ);
15146 v8::Handle<v8::Object> global = context->Global(); 15374 v8::Handle<v8::Object> global = context->Global();
15147 15375
15148 // Ordinary properties 15376 // Ordinary properties
15149 v8::Handle<v8::String> simple_property = 15377 v8::Handle<v8::String> simple_property =
15150 v8::String::NewFromUtf8(CcTest::isolate(), "p"); 15378 v8::String::NewFromUtf8(isolate, "p");
15151 global->Set(simple_property, v8::Int32::New(4), v8::DontDelete); 15379 global->Set(simple_property, v8::Int32::New(isolate, 4), v8::DontDelete);
15152 CHECK_EQ(4, global->Get(simple_property)->Int32Value()); 15380 CHECK_EQ(4, global->Get(simple_property)->Int32Value());
15153 // This should fail because the property is dont-delete. 15381 // This should fail because the property is dont-delete.
15154 CHECK(!global->Delete(simple_property)); 15382 CHECK(!global->Delete(simple_property));
15155 CHECK_EQ(4, global->Get(simple_property)->Int32Value()); 15383 CHECK_EQ(4, global->Get(simple_property)->Int32Value());
15156 // This should succeed even though the property is dont-delete. 15384 // This should succeed even though the property is dont-delete.
15157 CHECK(global->ForceDelete(simple_property)); 15385 CHECK(global->ForceDelete(simple_property));
15158 CHECK(global->Get(simple_property)->IsUndefined()); 15386 CHECK(global->Get(simple_property)->IsUndefined());
15159 } 15387 }
15160 15388
15161 15389
15162 static int force_delete_interceptor_count = 0; 15390 static int force_delete_interceptor_count = 0;
15163 static bool pass_on_delete = false; 15391 static bool pass_on_delete = false;
15164 15392
15165 15393
15166 static void ForceDeleteDeleter( 15394 static void ForceDeleteDeleter(
15167 v8::Local<v8::String> name, 15395 v8::Local<v8::String> name,
15168 const v8::PropertyCallbackInfo<v8::Boolean>& info) { 15396 const v8::PropertyCallbackInfo<v8::Boolean>& info) {
15169 force_delete_interceptor_count++; 15397 force_delete_interceptor_count++;
15170 if (pass_on_delete) return; 15398 if (pass_on_delete) return;
15171 info.GetReturnValue().Set(true); 15399 info.GetReturnValue().Set(true);
15172 } 15400 }
15173 15401
15174 15402
15175 THREADED_TEST(ForceDeleteWithInterceptor) { 15403 THREADED_TEST(ForceDeleteWithInterceptor) {
15176 force_delete_interceptor_count = 0; 15404 force_delete_interceptor_count = 0;
15177 pass_on_delete = false; 15405 pass_on_delete = false;
15178 15406
15179 v8::HandleScope scope(CcTest::isolate()); 15407 v8::Isolate* isolate = CcTest::isolate();
15180 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); 15408 v8::HandleScope scope(isolate);
15409 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate);
15181 templ->SetNamedPropertyHandler(0, 0, 0, ForceDeleteDeleter); 15410 templ->SetNamedPropertyHandler(0, 0, 0, ForceDeleteDeleter);
15182 LocalContext context(NULL, templ); 15411 LocalContext context(NULL, templ);
15183 v8::Handle<v8::Object> global = context->Global(); 15412 v8::Handle<v8::Object> global = context->Global();
15184 15413
15185 v8::Handle<v8::String> some_property = 15414 v8::Handle<v8::String> some_property =
15186 v8::String::NewFromUtf8(CcTest::isolate(), "a"); 15415 v8::String::NewFromUtf8(isolate, "a");
15187 global->Set(some_property, v8::Integer::New(42), v8::DontDelete); 15416 global->Set(some_property, v8::Integer::New(isolate, 42), v8::DontDelete);
15188 15417
15189 // Deleting a property should get intercepted and nothing should 15418 // Deleting a property should get intercepted and nothing should
15190 // happen. 15419 // happen.
15191 CHECK_EQ(0, force_delete_interceptor_count); 15420 CHECK_EQ(0, force_delete_interceptor_count);
15192 CHECK(global->Delete(some_property)); 15421 CHECK(global->Delete(some_property));
15193 CHECK_EQ(1, force_delete_interceptor_count); 15422 CHECK_EQ(1, force_delete_interceptor_count);
15194 CHECK_EQ(42, global->Get(some_property)->Int32Value()); 15423 CHECK_EQ(42, global->Get(some_property)->Int32Value());
15195 // Deleting the property when the interceptor returns an empty 15424 // Deleting the property when the interceptor returns an empty
15196 // handle should not delete the property since it is DontDelete. 15425 // handle should not delete the property since it is DontDelete.
15197 pass_on_delete = true; 15426 pass_on_delete = true;
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
15360 15589
15361 // Regression test for issue 398. 15590 // Regression test for issue 398.
15362 // If a function is added to an object, creating a constant function 15591 // If a function is added to an object, creating a constant function
15363 // field, and the result is cloned, replacing the constant function on the 15592 // field, and the result is cloned, replacing the constant function on the
15364 // original should not affect the clone. 15593 // original should not affect the clone.
15365 // See http://code.google.com/p/v8/issues/detail?id=398 15594 // See http://code.google.com/p/v8/issues/detail?id=398
15366 THREADED_TEST(ReplaceConstantFunction) { 15595 THREADED_TEST(ReplaceConstantFunction) {
15367 LocalContext context; 15596 LocalContext context;
15368 v8::Isolate* isolate = context->GetIsolate(); 15597 v8::Isolate* isolate = context->GetIsolate();
15369 v8::HandleScope scope(isolate); 15598 v8::HandleScope scope(isolate);
15370 v8::Handle<v8::Object> obj = v8::Object::New(); 15599 v8::Handle<v8::Object> obj = v8::Object::New(isolate);
15371 v8::Handle<v8::FunctionTemplate> func_templ = 15600 v8::Handle<v8::FunctionTemplate> func_templ =
15372 v8::FunctionTemplate::New(isolate); 15601 v8::FunctionTemplate::New(isolate);
15373 v8::Handle<v8::String> foo_string = 15602 v8::Handle<v8::String> foo_string =
15374 v8::String::NewFromUtf8(isolate, "foo"); 15603 v8::String::NewFromUtf8(isolate, "foo");
15375 obj->Set(foo_string, func_templ->GetFunction()); 15604 obj->Set(foo_string, func_templ->GetFunction());
15376 v8::Handle<v8::Object> obj_clone = obj->Clone(); 15605 v8::Handle<v8::Object> obj_clone = obj->Clone();
15377 obj_clone->Set(foo_string, 15606 obj_clone->Set(foo_string,
15378 v8::String::NewFromUtf8(isolate, "Hello")); 15607 v8::String::NewFromUtf8(isolate, "Hello"));
15379 CHECK(!obj->Get(foo_string)->IsUndefined()); 15608 CHECK(!obj->Get(foo_string)->IsUndefined());
15380 } 15609 }
(...skipping 25 matching lines...) Expand all
15406 for (int i = 0; i < kElementCount; i++) { 15635 for (int i = 0; i < kElementCount; i++) {
15407 pixels->set(i, i % 256); 15636 pixels->set(i, i % 256);
15408 } 15637 }
15409 // Force GC to trigger verification. 15638 // Force GC to trigger verification.
15410 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 15639 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
15411 for (int i = 0; i < kElementCount; i++) { 15640 for (int i = 0; i < kElementCount; i++) {
15412 CHECK_EQ(i % 256, pixels->get_scalar(i)); 15641 CHECK_EQ(i % 256, pixels->get_scalar(i));
15413 CHECK_EQ(i % 256, pixel_data[i]); 15642 CHECK_EQ(i % 256, pixel_data[i]);
15414 } 15643 }
15415 15644
15416 v8::Handle<v8::Object> obj = v8::Object::New(); 15645 v8::Handle<v8::Object> obj = v8::Object::New(context->GetIsolate());
15417 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); 15646 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj);
15418 // Set the elements to be the pixels. 15647 // Set the elements to be the pixels.
15419 // jsobj->set_elements(*pixels); 15648 // jsobj->set_elements(*pixels);
15420 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount); 15649 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount);
15421 CheckElementValue(isolate, 1, jsobj, 1); 15650 CheckElementValue(isolate, 1, jsobj, 1);
15422 obj->Set(v8_str("field"), v8::Int32::New(1503)); 15651 obj->Set(v8_str("field"), v8::Int32::New(CcTest::isolate(), 1503));
15423 context->Global()->Set(v8_str("pixels"), obj); 15652 context->Global()->Set(v8_str("pixels"), obj);
15424 v8::Handle<v8::Value> result = CompileRun("pixels.field"); 15653 v8::Handle<v8::Value> result = CompileRun("pixels.field");
15425 CHECK_EQ(1503, result->Int32Value()); 15654 CHECK_EQ(1503, result->Int32Value());
15426 result = CompileRun("pixels[1]"); 15655 result = CompileRun("pixels[1]");
15427 CHECK_EQ(1, result->Int32Value()); 15656 CHECK_EQ(1, result->Int32Value());
15428 15657
15429 result = CompileRun("var sum = 0;" 15658 result = CompileRun("var sum = 0;"
15430 "for (var i = 0; i < 8; i++) {" 15659 "for (var i = 0; i < 8; i++) {"
15431 " sum += pixels[i] = pixels[i] = -i;" 15660 " sum += pixels[i] = pixels[i] = -i;"
15432 "}" 15661 "}"
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
15771 16000
15772 free(pixel_data); 16001 free(pixel_data);
15773 } 16002 }
15774 16003
15775 16004
15776 THREADED_TEST(PixelArrayInfo) { 16005 THREADED_TEST(PixelArrayInfo) {
15777 LocalContext context; 16006 LocalContext context;
15778 v8::HandleScope scope(context->GetIsolate()); 16007 v8::HandleScope scope(context->GetIsolate());
15779 for (int size = 0; size < 100; size += 10) { 16008 for (int size = 0; size < 100; size += 10) {
15780 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(size)); 16009 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(size));
15781 v8::Handle<v8::Object> obj = v8::Object::New(); 16010 v8::Handle<v8::Object> obj = v8::Object::New(context->GetIsolate());
15782 obj->SetIndexedPropertiesToPixelData(pixel_data, size); 16011 obj->SetIndexedPropertiesToPixelData(pixel_data, size);
15783 CHECK(obj->HasIndexedPropertiesInPixelData()); 16012 CHECK(obj->HasIndexedPropertiesInPixelData());
15784 CHECK_EQ(pixel_data, obj->GetIndexedPropertiesPixelData()); 16013 CHECK_EQ(pixel_data, obj->GetIndexedPropertiesPixelData());
15785 CHECK_EQ(size, obj->GetIndexedPropertiesPixelDataLength()); 16014 CHECK_EQ(size, obj->GetIndexedPropertiesPixelDataLength());
15786 free(pixel_data); 16015 free(pixel_data);
15787 } 16016 }
15788 } 16017 }
15789 16018
15790 16019
15791 static void NotHandledIndexedPropertyGetter( 16020 static void NotHandledIndexedPropertyGetter(
15792 uint32_t index, 16021 uint32_t index,
15793 const v8::PropertyCallbackInfo<v8::Value>& info) { 16022 const v8::PropertyCallbackInfo<v8::Value>& info) {
15794 ApiTestFuzzer::Fuzz(); 16023 ApiTestFuzzer::Fuzz();
15795 } 16024 }
15796 16025
15797 16026
15798 static void NotHandledIndexedPropertySetter( 16027 static void NotHandledIndexedPropertySetter(
15799 uint32_t index, 16028 uint32_t index,
15800 Local<Value> value, 16029 Local<Value> value,
15801 const v8::PropertyCallbackInfo<v8::Value>& info) { 16030 const v8::PropertyCallbackInfo<v8::Value>& info) {
15802 ApiTestFuzzer::Fuzz(); 16031 ApiTestFuzzer::Fuzz();
15803 } 16032 }
15804 16033
15805 16034
15806 THREADED_TEST(PixelArrayWithInterceptor) { 16035 THREADED_TEST(PixelArrayWithInterceptor) {
15807 LocalContext context; 16036 LocalContext context;
15808 i::Factory* factory = CcTest::i_isolate()->factory(); 16037 i::Factory* factory = CcTest::i_isolate()->factory();
15809 v8::HandleScope scope(context->GetIsolate()); 16038 v8::Isolate* isolate = context->GetIsolate();
16039 v8::HandleScope scope(isolate);
15810 const int kElementCount = 260; 16040 const int kElementCount = 260;
15811 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount)); 16041 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount));
15812 i::Handle<i::ExternalPixelArray> pixels = 16042 i::Handle<i::ExternalPixelArray> pixels =
15813 i::Handle<i::ExternalPixelArray>::cast( 16043 i::Handle<i::ExternalPixelArray>::cast(
15814 factory->NewExternalArray(kElementCount, 16044 factory->NewExternalArray(kElementCount,
15815 v8::kExternalPixelArray, 16045 v8::kExternalPixelArray,
15816 pixel_data)); 16046 pixel_data));
15817 for (int i = 0; i < kElementCount; i++) { 16047 for (int i = 0; i < kElementCount; i++) {
15818 pixels->set(i, i % 256); 16048 pixels->set(i, i % 256);
15819 } 16049 }
15820 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); 16050 v8::Handle<v8::ObjectTemplate> templ =
16051 v8::ObjectTemplate::New(context->GetIsolate());
15821 templ->SetIndexedPropertyHandler(NotHandledIndexedPropertyGetter, 16052 templ->SetIndexedPropertyHandler(NotHandledIndexedPropertyGetter,
15822 NotHandledIndexedPropertySetter); 16053 NotHandledIndexedPropertySetter);
15823 v8::Handle<v8::Object> obj = templ->NewInstance(); 16054 v8::Handle<v8::Object> obj = templ->NewInstance();
15824 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount); 16055 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount);
15825 context->Global()->Set(v8_str("pixels"), obj); 16056 context->Global()->Set(v8_str("pixels"), obj);
15826 v8::Handle<v8::Value> result = CompileRun("pixels[1]"); 16057 v8::Handle<v8::Value> result = CompileRun("pixels[1]");
15827 CHECK_EQ(1, result->Int32Value()); 16058 CHECK_EQ(1, result->Int32Value());
15828 result = CompileRun("var sum = 0;" 16059 result = CompileRun("var sum = 0;"
15829 "for (var i = 0; i < 8; i++) {" 16060 "for (var i = 0; i < 8; i++) {"
15830 " sum += pixels[i] = pixels[i] = -i;" 16061 " sum += pixels[i] = pixels[i] = -i;"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
15867 16098
15868 template <class ExternalArrayClass, class ElementType> 16099 template <class ExternalArrayClass, class ElementType>
15869 static void ObjectWithExternalArrayTestHelper( 16100 static void ObjectWithExternalArrayTestHelper(
15870 Handle<Context> context, 16101 Handle<Context> context,
15871 v8::Handle<Object> obj, 16102 v8::Handle<Object> obj,
15872 int element_count, 16103 int element_count,
15873 v8::ExternalArrayType array_type, 16104 v8::ExternalArrayType array_type,
15874 int64_t low, int64_t high) { 16105 int64_t low, int64_t high) {
15875 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); 16106 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj);
15876 i::Isolate* isolate = jsobj->GetIsolate(); 16107 i::Isolate* isolate = jsobj->GetIsolate();
15877 obj->Set(v8_str("field"), v8::Int32::New(1503)); 16108 obj->Set(v8_str("field"),
16109 v8::Int32::New(reinterpret_cast<v8::Isolate*>(isolate), 1503));
15878 context->Global()->Set(v8_str("ext_array"), obj); 16110 context->Global()->Set(v8_str("ext_array"), obj);
15879 v8::Handle<v8::Value> result = CompileRun("ext_array.field"); 16111 v8::Handle<v8::Value> result = CompileRun("ext_array.field");
15880 CHECK_EQ(1503, result->Int32Value()); 16112 CHECK_EQ(1503, result->Int32Value());
15881 result = CompileRun("ext_array[1]"); 16113 result = CompileRun("ext_array[1]");
15882 CHECK_EQ(1, result->Int32Value()); 16114 CHECK_EQ(1, result->Int32Value());
15883 16115
15884 // Check pass through of assigned smis 16116 // Check pass through of assigned smis
15885 result = CompileRun("var sum = 0;" 16117 result = CompileRun("var sum = 0;"
15886 "for (var i = 0; i < 8; i++) {" 16118 "for (var i = 0; i < 8; i++) {"
15887 " sum += ext_array[i] = ext_array[i] = -i;" 16119 " sum += ext_array[i] = ext_array[i] = -i;"
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
16187 array->set(i, static_cast<ElementType>(i)); 16419 array->set(i, static_cast<ElementType>(i));
16188 } 16420 }
16189 // Force GC to trigger verification. 16421 // Force GC to trigger verification.
16190 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 16422 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
16191 for (int i = 0; i < kElementCount; i++) { 16423 for (int i = 0; i < kElementCount; i++) {
16192 CHECK_EQ(static_cast<int64_t>(i), 16424 CHECK_EQ(static_cast<int64_t>(i),
16193 static_cast<int64_t>(array->get_scalar(i))); 16425 static_cast<int64_t>(array->get_scalar(i)));
16194 CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(array_data[i])); 16426 CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(array_data[i]));
16195 } 16427 }
16196 16428
16197 v8::Handle<v8::Object> obj = v8::Object::New(); 16429 v8::Handle<v8::Object> obj = v8::Object::New(context->GetIsolate());
16198 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); 16430 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj);
16199 // Set the elements to be the external array. 16431 // Set the elements to be the external array.
16200 obj->SetIndexedPropertiesToExternalArrayData(array_data, 16432 obj->SetIndexedPropertiesToExternalArrayData(array_data,
16201 array_type, 16433 array_type,
16202 kElementCount); 16434 kElementCount);
16203 CHECK_EQ(1, 16435 CHECK_EQ(1,
16204 static_cast<int>( 16436 static_cast<int>(
16205 jsobj->GetElement(isolate, 1)->ToObjectChecked()->Number())); 16437 jsobj->GetElement(isolate, 1)->ToObjectChecked()->Number()));
16206 16438
16207 ObjectWithExternalArrayTestHelper<ExternalArrayClass, ElementType>( 16439 ObjectWithExternalArrayTestHelper<ExternalArrayClass, ElementType>(
16208 context.local(), obj, kElementCount, array_type, low, high); 16440 context.local(), obj, kElementCount, array_type, low, high);
16209 16441
16210 v8::Handle<v8::Value> result; 16442 v8::Handle<v8::Value> result;
16211 16443
16212 // Test more complex manipulations which cause eax to contain values 16444 // Test more complex manipulations which cause eax to contain values
16213 // that won't be completely overwritten by loads from the arrays. 16445 // that won't be completely overwritten by loads from the arrays.
16214 // This catches bugs in the instructions used for the KeyedLoadIC 16446 // This catches bugs in the instructions used for the KeyedLoadIC
16215 // for byte and word types. 16447 // for byte and word types.
16216 { 16448 {
16217 const int kXSize = 300; 16449 const int kXSize = 300;
16218 const int kYSize = 300; 16450 const int kYSize = 300;
16219 const int kLargeElementCount = kXSize * kYSize * 4; 16451 const int kLargeElementCount = kXSize * kYSize * 4;
16220 ElementType* large_array_data = 16452 ElementType* large_array_data =
16221 static_cast<ElementType*>(malloc(kLargeElementCount * element_size)); 16453 static_cast<ElementType*>(malloc(kLargeElementCount * element_size));
16222 v8::Handle<v8::Object> large_obj = v8::Object::New(); 16454 v8::Handle<v8::Object> large_obj = v8::Object::New(context->GetIsolate());
16223 // Set the elements to be the external array. 16455 // Set the elements to be the external array.
16224 large_obj->SetIndexedPropertiesToExternalArrayData(large_array_data, 16456 large_obj->SetIndexedPropertiesToExternalArrayData(large_array_data,
16225 array_type, 16457 array_type,
16226 kLargeElementCount); 16458 kLargeElementCount);
16227 context->Global()->Set(v8_str("large_array"), large_obj); 16459 context->Global()->Set(v8_str("large_array"), large_obj);
16228 // Initialize contents of a few rows. 16460 // Initialize contents of a few rows.
16229 for (int x = 0; x < 300; x++) { 16461 for (int x = 0; x < 300; x++) {
16230 int row = 0; 16462 int row = 0;
16231 int offset = row * 300 * 4; 16463 int offset = row * 300 * 4;
16232 large_array_data[offset + 4 * x + 0] = (ElementType) 127; 16464 large_array_data[offset + 4 * x + 0] = (ElementType) 127;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
16285 16517
16286 // The "" property descriptor is overloaded to store information about 16518 // The "" property descriptor is overloaded to store information about
16287 // the external array. Ensure that setting and accessing the "" property 16519 // the external array. Ensure that setting and accessing the "" property
16288 // works (it should overwrite the information cached about the external 16520 // works (it should overwrite the information cached about the external
16289 // array in the DescriptorArray) in various situations. 16521 // array in the DescriptorArray) in various situations.
16290 result = CompileRun("ext_array[''] = 23; ext_array['']"); 16522 result = CompileRun("ext_array[''] = 23; ext_array['']");
16291 CHECK_EQ(23, result->Int32Value()); 16523 CHECK_EQ(23, result->Int32Value());
16292 16524
16293 // Property "" set after the external array is associated with the object. 16525 // Property "" set after the external array is associated with the object.
16294 { 16526 {
16295 v8::Handle<v8::Object> obj2 = v8::Object::New(); 16527 v8::Handle<v8::Object> obj2 = v8::Object::New(context->GetIsolate());
16296 obj2->Set(v8_str("ee_test_field"), v8::Int32::New(256)); 16528 obj2->Set(v8_str("ee_test_field"),
16297 obj2->Set(v8_str(""), v8::Int32::New(1503)); 16529 v8::Int32::New(context->GetIsolate(), 256));
16530 obj2->Set(v8_str(""), v8::Int32::New(context->GetIsolate(), 1503));
16298 // Set the elements to be the external array. 16531 // Set the elements to be the external array.
16299 obj2->SetIndexedPropertiesToExternalArrayData(array_data, 16532 obj2->SetIndexedPropertiesToExternalArrayData(array_data,
16300 array_type, 16533 array_type,
16301 kElementCount); 16534 kElementCount);
16302 context->Global()->Set(v8_str("ext_array"), obj2); 16535 context->Global()->Set(v8_str("ext_array"), obj2);
16303 result = CompileRun("ext_array['']"); 16536 result = CompileRun("ext_array['']");
16304 CHECK_EQ(1503, result->Int32Value()); 16537 CHECK_EQ(1503, result->Int32Value());
16305 } 16538 }
16306 16539
16307 // Property "" set after the external array is associated with the object. 16540 // Property "" set after the external array is associated with the object.
16308 { 16541 {
16309 v8::Handle<v8::Object> obj2 = v8::Object::New(); 16542 v8::Handle<v8::Object> obj2 = v8::Object::New(context->GetIsolate());
16310 obj2->Set(v8_str("ee_test_field_2"), v8::Int32::New(256)); 16543 obj2->Set(v8_str("ee_test_field_2"),
16544 v8::Int32::New(context->GetIsolate(), 256));
16311 // Set the elements to be the external array. 16545 // Set the elements to be the external array.
16312 obj2->SetIndexedPropertiesToExternalArrayData(array_data, 16546 obj2->SetIndexedPropertiesToExternalArrayData(array_data,
16313 array_type, 16547 array_type,
16314 kElementCount); 16548 kElementCount);
16315 obj2->Set(v8_str(""), v8::Int32::New(1503)); 16549 obj2->Set(v8_str(""), v8::Int32::New(context->GetIsolate(), 1503));
16316 context->Global()->Set(v8_str("ext_array"), obj2); 16550 context->Global()->Set(v8_str("ext_array"), obj2);
16317 result = CompileRun("ext_array['']"); 16551 result = CompileRun("ext_array['']");
16318 CHECK_EQ(1503, result->Int32Value()); 16552 CHECK_EQ(1503, result->Int32Value());
16319 } 16553 }
16320 16554
16321 // Should reuse the map from previous test. 16555 // Should reuse the map from previous test.
16322 { 16556 {
16323 v8::Handle<v8::Object> obj2 = v8::Object::New(); 16557 v8::Handle<v8::Object> obj2 = v8::Object::New(context->GetIsolate());
16324 obj2->Set(v8_str("ee_test_field_2"), v8::Int32::New(256)); 16558 obj2->Set(v8_str("ee_test_field_2"),
16559 v8::Int32::New(context->GetIsolate(), 256));
16325 // Set the elements to be the external array. Should re-use the map 16560 // Set the elements to be the external array. Should re-use the map
16326 // from previous test. 16561 // from previous test.
16327 obj2->SetIndexedPropertiesToExternalArrayData(array_data, 16562 obj2->SetIndexedPropertiesToExternalArrayData(array_data,
16328 array_type, 16563 array_type,
16329 kElementCount); 16564 kElementCount);
16330 context->Global()->Set(v8_str("ext_array"), obj2); 16565 context->Global()->Set(v8_str("ext_array"), obj2);
16331 result = CompileRun("ext_array['']"); 16566 result = CompileRun("ext_array['']");
16332 } 16567 }
16333 16568
16334 // Property "" is a constant function that shouldn't not be interfered with 16569 // Property "" is a constant function that shouldn't not be interfered with
16335 // when an external array is set. 16570 // when an external array is set.
16336 { 16571 {
16337 v8::Handle<v8::Object> obj2 = v8::Object::New(); 16572 v8::Handle<v8::Object> obj2 = v8::Object::New(context->GetIsolate());
16338 // Start 16573 // Start
16339 obj2->Set(v8_str("ee_test_field3"), v8::Int32::New(256)); 16574 obj2->Set(v8_str("ee_test_field3"),
16575 v8::Int32::New(context->GetIsolate(), 256));
16340 16576
16341 // Add a constant function to an object. 16577 // Add a constant function to an object.
16342 context->Global()->Set(v8_str("ext_array"), obj2); 16578 context->Global()->Set(v8_str("ext_array"), obj2);
16343 result = CompileRun("ext_array[''] = function() {return 1503;};" 16579 result = CompileRun("ext_array[''] = function() {return 1503;};"
16344 "ext_array['']();"); 16580 "ext_array['']();");
16345 16581
16346 // Add an external array transition to the same map that 16582 // Add an external array transition to the same map that
16347 // has the constant transition. 16583 // has the constant transition.
16348 v8::Handle<v8::Object> obj3 = v8::Object::New(); 16584 v8::Handle<v8::Object> obj3 = v8::Object::New(context->GetIsolate());
16349 obj3->Set(v8_str("ee_test_field3"), v8::Int32::New(256)); 16585 obj3->Set(v8_str("ee_test_field3"),
16586 v8::Int32::New(context->GetIsolate(), 256));
16350 obj3->SetIndexedPropertiesToExternalArrayData(array_data, 16587 obj3->SetIndexedPropertiesToExternalArrayData(array_data,
16351 array_type, 16588 array_type,
16352 kElementCount); 16589 kElementCount);
16353 context->Global()->Set(v8_str("ext_array"), obj3); 16590 context->Global()->Set(v8_str("ext_array"), obj3);
16354 } 16591 }
16355 16592
16356 // If a external array transition is in the map, it should get clobbered 16593 // If a external array transition is in the map, it should get clobbered
16357 // by a constant function. 16594 // by a constant function.
16358 { 16595 {
16359 // Add an external array transition. 16596 // Add an external array transition.
16360 v8::Handle<v8::Object> obj3 = v8::Object::New(); 16597 v8::Handle<v8::Object> obj3 = v8::Object::New(context->GetIsolate());
16361 obj3->Set(v8_str("ee_test_field4"), v8::Int32::New(256)); 16598 obj3->Set(v8_str("ee_test_field4"),
16599 v8::Int32::New(context->GetIsolate(), 256));
16362 obj3->SetIndexedPropertiesToExternalArrayData(array_data, 16600 obj3->SetIndexedPropertiesToExternalArrayData(array_data,
16363 array_type, 16601 array_type,
16364 kElementCount); 16602 kElementCount);
16365 16603
16366 // Add a constant function to the same map that just got an external array 16604 // Add a constant function to the same map that just got an external array
16367 // transition. 16605 // transition.
16368 v8::Handle<v8::Object> obj2 = v8::Object::New(); 16606 v8::Handle<v8::Object> obj2 = v8::Object::New(context->GetIsolate());
16369 obj2->Set(v8_str("ee_test_field4"), v8::Int32::New(256)); 16607 obj2->Set(v8_str("ee_test_field4"),
16608 v8::Int32::New(context->GetIsolate(), 256));
16370 context->Global()->Set(v8_str("ext_array"), obj2); 16609 context->Global()->Set(v8_str("ext_array"), obj2);
16371 result = CompileRun("ext_array[''] = function() {return 1503;};" 16610 result = CompileRun("ext_array[''] = function() {return 1503;};"
16372 "ext_array['']();"); 16611 "ext_array['']();");
16373 } 16612 }
16374 16613
16375 free(array_data); 16614 free(array_data);
16376 } 16615 }
16377 16616
16378 16617
16379 THREADED_TEST(ExternalByteArray) { 16618 THREADED_TEST(ExternalByteArray) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
16458 TestExternalFloatArray(); 16697 TestExternalFloatArray();
16459 } 16698 }
16460 16699
16461 16700
16462 void ExternalArrayInfoTestHelper(v8::ExternalArrayType array_type) { 16701 void ExternalArrayInfoTestHelper(v8::ExternalArrayType array_type) {
16463 LocalContext context; 16702 LocalContext context;
16464 v8::HandleScope scope(context->GetIsolate()); 16703 v8::HandleScope scope(context->GetIsolate());
16465 for (int size = 0; size < 100; size += 10) { 16704 for (int size = 0; size < 100; size += 10) {
16466 int element_size = ExternalArrayElementSize(array_type); 16705 int element_size = ExternalArrayElementSize(array_type);
16467 void* external_data = malloc(size * element_size); 16706 void* external_data = malloc(size * element_size);
16468 v8::Handle<v8::Object> obj = v8::Object::New(); 16707 v8::Handle<v8::Object> obj = v8::Object::New(context->GetIsolate());
16469 obj->SetIndexedPropertiesToExternalArrayData( 16708 obj->SetIndexedPropertiesToExternalArrayData(
16470 external_data, array_type, size); 16709 external_data, array_type, size);
16471 CHECK(obj->HasIndexedPropertiesInExternalArrayData()); 16710 CHECK(obj->HasIndexedPropertiesInExternalArrayData());
16472 CHECK_EQ(external_data, obj->GetIndexedPropertiesExternalArrayData()); 16711 CHECK_EQ(external_data, obj->GetIndexedPropertiesExternalArrayData());
16473 CHECK_EQ(array_type, obj->GetIndexedPropertiesExternalArrayDataType()); 16712 CHECK_EQ(array_type, obj->GetIndexedPropertiesExternalArrayDataType());
16474 CHECK_EQ(size, obj->GetIndexedPropertiesExternalArrayDataLength()); 16713 CHECK_EQ(size, obj->GetIndexedPropertiesExternalArrayDataLength());
16475 free(external_data); 16714 free(external_data);
16476 } 16715 }
16477 } 16716 }
16478 16717
16479 16718
16480 THREADED_TEST(ExternalArrayInfo) { 16719 THREADED_TEST(ExternalArrayInfo) {
16481 ExternalArrayInfoTestHelper(v8::kExternalByteArray); 16720 ExternalArrayInfoTestHelper(v8::kExternalByteArray);
16482 ExternalArrayInfoTestHelper(v8::kExternalUnsignedByteArray); 16721 ExternalArrayInfoTestHelper(v8::kExternalUnsignedByteArray);
16483 ExternalArrayInfoTestHelper(v8::kExternalShortArray); 16722 ExternalArrayInfoTestHelper(v8::kExternalShortArray);
16484 ExternalArrayInfoTestHelper(v8::kExternalUnsignedShortArray); 16723 ExternalArrayInfoTestHelper(v8::kExternalUnsignedShortArray);
16485 ExternalArrayInfoTestHelper(v8::kExternalIntArray); 16724 ExternalArrayInfoTestHelper(v8::kExternalIntArray);
16486 ExternalArrayInfoTestHelper(v8::kExternalUnsignedIntArray); 16725 ExternalArrayInfoTestHelper(v8::kExternalUnsignedIntArray);
16487 ExternalArrayInfoTestHelper(v8::kExternalFloatArray); 16726 ExternalArrayInfoTestHelper(v8::kExternalFloatArray);
16488 ExternalArrayInfoTestHelper(v8::kExternalDoubleArray); 16727 ExternalArrayInfoTestHelper(v8::kExternalDoubleArray);
16489 ExternalArrayInfoTestHelper(v8::kExternalPixelArray); 16728 ExternalArrayInfoTestHelper(v8::kExternalPixelArray);
16490 } 16729 }
16491 16730
16492 16731
16493 void ExternalArrayLimitTestHelper(v8::ExternalArrayType array_type, int size) { 16732 void ExtArrayLimitsHelper(v8::Isolate* isolate,
16494 v8::Handle<v8::Object> obj = v8::Object::New(); 16733 v8::ExternalArrayType array_type,
16734 int size) {
16735 v8::Handle<v8::Object> obj = v8::Object::New(isolate);
16495 v8::V8::SetFatalErrorHandler(StoringErrorCallback); 16736 v8::V8::SetFatalErrorHandler(StoringErrorCallback);
16496 last_location = last_message = NULL; 16737 last_location = last_message = NULL;
16497 obj->SetIndexedPropertiesToExternalArrayData(NULL, array_type, size); 16738 obj->SetIndexedPropertiesToExternalArrayData(NULL, array_type, size);
16498 CHECK(!obj->HasIndexedPropertiesInExternalArrayData()); 16739 CHECK(!obj->HasIndexedPropertiesInExternalArrayData());
16499 CHECK_NE(NULL, last_location); 16740 CHECK_NE(NULL, last_location);
16500 CHECK_NE(NULL, last_message); 16741 CHECK_NE(NULL, last_message);
16501 } 16742 }
16502 16743
16503 16744
16504 TEST(ExternalArrayLimits) { 16745 TEST(ExternalArrayLimits) {
16505 LocalContext context; 16746 LocalContext context;
16506 v8::HandleScope scope(context->GetIsolate()); 16747 v8::Isolate* isolate = context->GetIsolate();
16507 ExternalArrayLimitTestHelper(v8::kExternalByteArray, 0x40000000); 16748 v8::HandleScope scope(isolate);
16508 ExternalArrayLimitTestHelper(v8::kExternalByteArray, 0xffffffff); 16749 ExtArrayLimitsHelper(isolate, v8::kExternalByteArray, 0x40000000);
16509 ExternalArrayLimitTestHelper(v8::kExternalUnsignedByteArray, 0x40000000); 16750 ExtArrayLimitsHelper(isolate, v8::kExternalByteArray, 0xffffffff);
16510 ExternalArrayLimitTestHelper(v8::kExternalUnsignedByteArray, 0xffffffff); 16751 ExtArrayLimitsHelper(isolate, v8::kExternalUnsignedByteArray, 0x40000000);
16511 ExternalArrayLimitTestHelper(v8::kExternalShortArray, 0x40000000); 16752 ExtArrayLimitsHelper(isolate, v8::kExternalUnsignedByteArray, 0xffffffff);
16512 ExternalArrayLimitTestHelper(v8::kExternalShortArray, 0xffffffff); 16753 ExtArrayLimitsHelper(isolate, v8::kExternalShortArray, 0x40000000);
16513 ExternalArrayLimitTestHelper(v8::kExternalUnsignedShortArray, 0x40000000); 16754 ExtArrayLimitsHelper(isolate, v8::kExternalShortArray, 0xffffffff);
16514 ExternalArrayLimitTestHelper(v8::kExternalUnsignedShortArray, 0xffffffff); 16755 ExtArrayLimitsHelper(isolate, v8::kExternalUnsignedShortArray, 0x40000000);
16515 ExternalArrayLimitTestHelper(v8::kExternalIntArray, 0x40000000); 16756 ExtArrayLimitsHelper(isolate, v8::kExternalUnsignedShortArray, 0xffffffff);
16516 ExternalArrayLimitTestHelper(v8::kExternalIntArray, 0xffffffff); 16757 ExtArrayLimitsHelper(isolate, v8::kExternalIntArray, 0x40000000);
16517 ExternalArrayLimitTestHelper(v8::kExternalUnsignedIntArray, 0x40000000); 16758 ExtArrayLimitsHelper(isolate, v8::kExternalIntArray, 0xffffffff);
16518 ExternalArrayLimitTestHelper(v8::kExternalUnsignedIntArray, 0xffffffff); 16759 ExtArrayLimitsHelper(isolate, v8::kExternalUnsignedIntArray, 0x40000000);
16519 ExternalArrayLimitTestHelper(v8::kExternalFloatArray, 0x40000000); 16760 ExtArrayLimitsHelper(isolate, v8::kExternalUnsignedIntArray, 0xffffffff);
16520 ExternalArrayLimitTestHelper(v8::kExternalFloatArray, 0xffffffff); 16761 ExtArrayLimitsHelper(isolate, v8::kExternalFloatArray, 0x40000000);
16521 ExternalArrayLimitTestHelper(v8::kExternalDoubleArray, 0x40000000); 16762 ExtArrayLimitsHelper(isolate, v8::kExternalFloatArray, 0xffffffff);
16522 ExternalArrayLimitTestHelper(v8::kExternalDoubleArray, 0xffffffff); 16763 ExtArrayLimitsHelper(isolate, v8::kExternalDoubleArray, 0x40000000);
16523 ExternalArrayLimitTestHelper(v8::kExternalPixelArray, 0x40000000); 16764 ExtArrayLimitsHelper(isolate, v8::kExternalDoubleArray, 0xffffffff);
16524 ExternalArrayLimitTestHelper(v8::kExternalPixelArray, 0xffffffff); 16765 ExtArrayLimitsHelper(isolate, v8::kExternalPixelArray, 0x40000000);
16766 ExtArrayLimitsHelper(isolate, v8::kExternalPixelArray, 0xffffffff);
16525 } 16767 }
16526 16768
16527 16769
16528 template <typename ElementType, typename TypedArray, 16770 template <typename ElementType, typename TypedArray,
16529 class ExternalArrayClass> 16771 class ExternalArrayClass>
16530 void TypedArrayTestHelper(v8::ExternalArrayType array_type, 16772 void TypedArrayTestHelper(v8::ExternalArrayType array_type,
16531 int64_t low, int64_t high) { 16773 int64_t low, int64_t high) {
16532 const int kElementCount = 50; 16774 const int kElementCount = 50;
16533 16775
16534 i::ScopedVector<ElementType> backing_store(kElementCount+2); 16776 i::ScopedVector<ElementType> backing_store(kElementCount+2);
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
16666 16908
16667 THREADED_TEST(ScriptContextDependence) { 16909 THREADED_TEST(ScriptContextDependence) {
16668 LocalContext c1; 16910 LocalContext c1;
16669 v8::HandleScope scope(c1->GetIsolate()); 16911 v8::HandleScope scope(c1->GetIsolate());
16670 const char *source = "foo"; 16912 const char *source = "foo";
16671 v8::Handle<v8::Script> dep = 16913 v8::Handle<v8::Script> dep =
16672 v8::Script::Compile(v8::String::NewFromUtf8(c1->GetIsolate(), source)); 16914 v8::Script::Compile(v8::String::NewFromUtf8(c1->GetIsolate(), source));
16673 v8::Handle<v8::Script> indep = 16915 v8::Handle<v8::Script> indep =
16674 v8::Script::New(v8::String::NewFromUtf8(c1->GetIsolate(), source)); 16916 v8::Script::New(v8::String::NewFromUtf8(c1->GetIsolate(), source));
16675 c1->Global()->Set(v8::String::NewFromUtf8(c1->GetIsolate(), "foo"), 16917 c1->Global()->Set(v8::String::NewFromUtf8(c1->GetIsolate(), "foo"),
16676 v8::Integer::New(100)); 16918 v8::Integer::New(c1->GetIsolate(), 100));
16677 CHECK_EQ(dep->Run()->Int32Value(), 100); 16919 CHECK_EQ(dep->Run()->Int32Value(), 100);
16678 CHECK_EQ(indep->Run()->Int32Value(), 100); 16920 CHECK_EQ(indep->Run()->Int32Value(), 100);
16679 LocalContext c2; 16921 LocalContext c2;
16680 c2->Global()->Set(v8::String::NewFromUtf8(c2->GetIsolate(), "foo"), 16922 c2->Global()->Set(v8::String::NewFromUtf8(c2->GetIsolate(), "foo"),
16681 v8::Integer::New(101)); 16923 v8::Integer::New(c2->GetIsolate(), 101));
16682 CHECK_EQ(dep->Run()->Int32Value(), 100); 16924 CHECK_EQ(dep->Run()->Int32Value(), 100);
16683 CHECK_EQ(indep->Run()->Int32Value(), 101); 16925 CHECK_EQ(indep->Run()->Int32Value(), 101);
16684 } 16926 }
16685 16927
16686 16928
16687 THREADED_TEST(StackTrace) { 16929 THREADED_TEST(StackTrace) {
16688 LocalContext context; 16930 LocalContext context;
16689 v8::HandleScope scope(context->GetIsolate()); 16931 v8::HandleScope scope(context->GetIsolate());
16690 v8::TryCatch try_catch; 16932 v8::TryCatch try_catch;
16691 const char *source = "function foo() { FAIL.FAIL; }; foo();"; 16933 const char *source = "function foo() { FAIL.FAIL; }; foo();";
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
16774 17016
16775 17017
16776 // Tests the C++ StackTrace API. 17018 // Tests the C++ StackTrace API.
16777 // TODO(3074796): Reenable this as a THREADED_TEST once it passes. 17019 // TODO(3074796): Reenable this as a THREADED_TEST once it passes.
16778 // THREADED_TEST(CaptureStackTrace) { 17020 // THREADED_TEST(CaptureStackTrace) {
16779 TEST(CaptureStackTrace) { 17021 TEST(CaptureStackTrace) {
16780 v8::Isolate* isolate = CcTest::isolate(); 17022 v8::Isolate* isolate = CcTest::isolate();
16781 v8::HandleScope scope(isolate); 17023 v8::HandleScope scope(isolate);
16782 v8::Handle<v8::String> origin = 17024 v8::Handle<v8::String> origin =
16783 v8::String::NewFromUtf8(isolate, "capture-stack-trace-test"); 17025 v8::String::NewFromUtf8(isolate, "capture-stack-trace-test");
16784 Local<ObjectTemplate> templ = ObjectTemplate::New(); 17026 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
16785 templ->Set(v8_str("AnalyzeStackInNativeCode"), 17027 templ->Set(v8_str("AnalyzeStackInNativeCode"),
16786 v8::FunctionTemplate::New(isolate, AnalyzeStackInNativeCode)); 17028 v8::FunctionTemplate::New(isolate, AnalyzeStackInNativeCode));
16787 LocalContext context(0, templ); 17029 LocalContext context(0, templ);
16788 17030
16789 // Test getting OVERVIEW information. Should ignore information that is not 17031 // Test getting OVERVIEW information. Should ignore information that is not
16790 // script name, function name, line number, and column offset. 17032 // script name, function name, line number, and column offset.
16791 const char *overview_source = 17033 const char *overview_source =
16792 "function bar() {\n" 17034 "function bar() {\n"
16793 " var y; AnalyzeStackInNativeCode(1);\n" 17035 " var y; AnalyzeStackInNativeCode(1);\n"
16794 "}\n" 17036 "}\n"
(...skipping 14 matching lines...) Expand all
16809 "function bat() {AnalyzeStackInNativeCode(2);\n" 17051 "function bat() {AnalyzeStackInNativeCode(2);\n"
16810 "}\n" 17052 "}\n"
16811 "\n" 17053 "\n"
16812 "function baz() {\n" 17054 "function baz() {\n"
16813 " bat();\n" 17055 " bat();\n"
16814 "}\n" 17056 "}\n"
16815 "eval('new baz();');"; 17057 "eval('new baz();');";
16816 v8::Handle<v8::String> detailed_src = 17058 v8::Handle<v8::String> detailed_src =
16817 v8::String::NewFromUtf8(isolate, detailed_source); 17059 v8::String::NewFromUtf8(isolate, detailed_source);
16818 // Make the script using a non-zero line and column offset. 17060 // Make the script using a non-zero line and column offset.
16819 v8::Handle<v8::Integer> line_offset = v8::Integer::New(3); 17061 v8::Handle<v8::Integer> line_offset = v8::Integer::New(isolate, 3);
16820 v8::Handle<v8::Integer> column_offset = v8::Integer::New(5); 17062 v8::Handle<v8::Integer> column_offset = v8::Integer::New(isolate, 5);
16821 v8::ScriptOrigin detailed_origin(origin, line_offset, column_offset); 17063 v8::ScriptOrigin detailed_origin(origin, line_offset, column_offset);
16822 v8::Handle<v8::Script> detailed_script( 17064 v8::Handle<v8::Script> detailed_script(
16823 v8::Script::New(detailed_src, &detailed_origin)); 17065 v8::Script::New(detailed_src, &detailed_origin));
16824 v8::Handle<Value> detailed_result(detailed_script->Run()); 17066 v8::Handle<Value> detailed_result(detailed_script->Run());
16825 CHECK(!detailed_result.IsEmpty()); 17067 CHECK(!detailed_result.IsEmpty());
16826 CHECK(detailed_result->IsObject()); 17068 CHECK(detailed_result->IsObject());
16827 } 17069 }
16828 17070
16829 17071
16830 static void StackTraceForUncaughtExceptionListener( 17072 static void StackTraceForUncaughtExceptionListener(
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
17025 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); 17267 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL();
17026 CHECK(!name.IsEmpty()); 17268 CHECK(!name.IsEmpty());
17027 CHECK_EQ(url, name); 17269 CHECK_EQ(url, name);
17028 } 17270 }
17029 } 17271 }
17030 17272
17031 17273
17032 TEST(SourceURLInStackTrace) { 17274 TEST(SourceURLInStackTrace) {
17033 v8::Isolate* isolate = CcTest::isolate(); 17275 v8::Isolate* isolate = CcTest::isolate();
17034 v8::HandleScope scope(isolate); 17276 v8::HandleScope scope(isolate);
17035 Local<ObjectTemplate> templ = ObjectTemplate::New(); 17277 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
17036 templ->Set(v8_str("AnalyzeStackOfEvalWithSourceURL"), 17278 templ->Set(v8_str("AnalyzeStackOfEvalWithSourceURL"),
17037 v8::FunctionTemplate::New(isolate, 17279 v8::FunctionTemplate::New(isolate,
17038 AnalyzeStackOfEvalWithSourceURL)); 17280 AnalyzeStackOfEvalWithSourceURL));
17039 LocalContext context(0, templ); 17281 LocalContext context(0, templ);
17040 17282
17041 const char *source = 17283 const char *source =
17042 "function outer() {\n" 17284 "function outer() {\n"
17043 "function bar() {\n" 17285 "function bar() {\n"
17044 " AnalyzeStackOfEvalWithSourceURL();\n" 17286 " AnalyzeStackOfEvalWithSourceURL();\n"
17045 "}\n" 17287 "}\n"
(...skipping 23 matching lines...) Expand all
17069 CHECK_EQ(2, stackTrace->GetFrameCount()); 17311 CHECK_EQ(2, stackTrace->GetFrameCount());
17070 for (int i = 0; i < 2; i++) { 17312 for (int i = 0; i < 2; i++) {
17071 scriptIdInStack[i] = stackTrace->GetFrame(i)->GetScriptId(); 17313 scriptIdInStack[i] = stackTrace->GetFrame(i)->GetScriptId();
17072 } 17314 }
17073 } 17315 }
17074 17316
17075 17317
17076 TEST(ScriptIdInStackTrace) { 17318 TEST(ScriptIdInStackTrace) {
17077 v8::Isolate* isolate = CcTest::isolate(); 17319 v8::Isolate* isolate = CcTest::isolate();
17078 v8::HandleScope scope(isolate); 17320 v8::HandleScope scope(isolate);
17079 Local<ObjectTemplate> templ = ObjectTemplate::New(); 17321 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
17080 templ->Set(v8_str("AnalyzeScriptIdInStack"), 17322 templ->Set(v8_str("AnalyzeScriptIdInStack"),
17081 v8::FunctionTemplate::New(isolate, AnalyzeScriptIdInStack)); 17323 v8::FunctionTemplate::New(isolate, AnalyzeScriptIdInStack));
17082 LocalContext context(0, templ); 17324 LocalContext context(0, templ);
17083 17325
17084 v8::Handle<v8::String> scriptSource = v8::String::NewFromUtf8( 17326 v8::Handle<v8::String> scriptSource = v8::String::NewFromUtf8(
17085 isolate, 17327 isolate,
17086 "function foo() {\n" 17328 "function foo() {\n"
17087 " AnalyzeScriptIdInStack();" 17329 " AnalyzeScriptIdInStack();"
17088 "}\n" 17330 "}\n"
17089 "foo();\n"); 17331 "foo();\n");
(...skipping 18 matching lines...) Expand all
17108 for (int i = 0; i < 3; i++) { 17350 for (int i = 0; i < 3; i++) {
17109 v8::Handle<v8::String> name = 17351 v8::Handle<v8::String> name =
17110 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); 17352 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL();
17111 CHECK(!name.IsEmpty()); 17353 CHECK(!name.IsEmpty());
17112 CHECK_EQ(url, name); 17354 CHECK_EQ(url, name);
17113 } 17355 }
17114 } 17356 }
17115 17357
17116 17358
17117 TEST(InlineScriptWithSourceURLInStackTrace) { 17359 TEST(InlineScriptWithSourceURLInStackTrace) {
17118 v8::HandleScope scope(CcTest::isolate()); 17360 v8::Isolate* isolate = CcTest::isolate();
17119 Local<ObjectTemplate> templ = ObjectTemplate::New(); 17361 v8::HandleScope scope(isolate);
17362 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
17120 templ->Set(v8_str("AnalyzeStackOfInlineScriptWithSourceURL"), 17363 templ->Set(v8_str("AnalyzeStackOfInlineScriptWithSourceURL"),
17121 v8::FunctionTemplate::New( 17364 v8::FunctionTemplate::New(
17122 CcTest::isolate(), AnalyzeStackOfInlineScriptWithSourceURL)); 17365 CcTest::isolate(), AnalyzeStackOfInlineScriptWithSourceURL));
17123 LocalContext context(0, templ); 17366 LocalContext context(0, templ);
17124 17367
17125 const char *source = 17368 const char *source =
17126 "function outer() {\n" 17369 "function outer() {\n"
17127 "function bar() {\n" 17370 "function bar() {\n"
17128 " AnalyzeStackOfInlineScriptWithSourceURL();\n" 17371 " AnalyzeStackOfInlineScriptWithSourceURL();\n"
17129 "}\n" 17372 "}\n"
(...skipping 23 matching lines...) Expand all
17153 for (int i = 0; i < 3; i++) { 17396 for (int i = 0; i < 3; i++) {
17154 v8::Handle<v8::String> name = 17397 v8::Handle<v8::String> name =
17155 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); 17398 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL();
17156 CHECK(!name.IsEmpty()); 17399 CHECK(!name.IsEmpty());
17157 CHECK_EQ(url, name); 17400 CHECK_EQ(url, name);
17158 } 17401 }
17159 } 17402 }
17160 17403
17161 17404
17162 TEST(DynamicWithSourceURLInStackTrace) { 17405 TEST(DynamicWithSourceURLInStackTrace) {
17163 v8::HandleScope scope(CcTest::isolate()); 17406 v8::Isolate* isolate = CcTest::isolate();
17164 Local<ObjectTemplate> templ = ObjectTemplate::New(); 17407 v8::HandleScope scope(isolate);
17408 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
17165 templ->Set(v8_str("AnalyzeStackOfDynamicScriptWithSourceURL"), 17409 templ->Set(v8_str("AnalyzeStackOfDynamicScriptWithSourceURL"),
17166 v8::FunctionTemplate::New( 17410 v8::FunctionTemplate::New(
17167 CcTest::isolate(), AnalyzeStackOfDynamicScriptWithSourceURL)); 17411 CcTest::isolate(), AnalyzeStackOfDynamicScriptWithSourceURL));
17168 LocalContext context(0, templ); 17412 LocalContext context(0, templ);
17169 17413
17170 const char *source = 17414 const char *source =
17171 "function outer() {\n" 17415 "function outer() {\n"
17172 "function bar() {\n" 17416 "function bar() {\n"
17173 " AnalyzeStackOfDynamicScriptWithSourceURL();\n" 17417 " AnalyzeStackOfDynamicScriptWithSourceURL();\n"
17174 "}\n" 17418 "}\n"
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
17546 i::OS::MemCopy(&target, &value, sizeof(target)); 17790 i::OS::MemCopy(&target, &value, sizeof(target));
17547 return target; 17791 return target;
17548 } 17792 }
17549 17793
17550 17794
17551 static double DoubleToDateTime(double input) { 17795 static double DoubleToDateTime(double input) {
17552 double date_limit = 864e13; 17796 double date_limit = 864e13;
17553 if (std::isnan(input) || input < -date_limit || input > date_limit) { 17797 if (std::isnan(input) || input < -date_limit || input > date_limit) {
17554 return i::OS::nan_value(); 17798 return i::OS::nan_value();
17555 } 17799 }
17556 return (input < 0) ? -(floor(-input)) : floor(input); 17800 return (input < 0) ? -(std::floor(-input)) : std::floor(input);
17557 } 17801 }
17558 17802
17559 17803
17560 // We don't have a consistent way to write 64-bit constants syntactically, so we 17804 // We don't have a consistent way to write 64-bit constants syntactically, so we
17561 // split them into two 32-bit constants and combine them programmatically. 17805 // split them into two 32-bit constants and combine them programmatically.
17562 static double DoubleFromBits(uint32_t high_bits, uint32_t low_bits) { 17806 static double DoubleFromBits(uint32_t high_bits, uint32_t low_bits) {
17563 return DoubleFromBits((static_cast<uint64_t>(high_bits) << 32) | low_bits); 17807 return DoubleFromBits((static_cast<uint64_t>(high_bits) << 32) | low_bits);
17564 } 17808 }
17565 17809
17566 17810
17567 THREADED_TEST(QuietSignalingNaNs) { 17811 THREADED_TEST(QuietSignalingNaNs) {
17568 LocalContext context; 17812 LocalContext context;
17569 v8::HandleScope scope(context->GetIsolate()); 17813 v8::Isolate* isolate = context->GetIsolate();
17814 v8::HandleScope scope(isolate);
17570 v8::TryCatch try_catch; 17815 v8::TryCatch try_catch;
17571 17816
17572 // Special double values. 17817 // Special double values.
17573 double snan = DoubleFromBits(0x7ff00000, 0x00000001); 17818 double snan = DoubleFromBits(0x7ff00000, 0x00000001);
17574 double qnan = DoubleFromBits(0x7ff80000, 0x00000000); 17819 double qnan = DoubleFromBits(0x7ff80000, 0x00000000);
17575 double infinity = DoubleFromBits(0x7ff00000, 0x00000000); 17820 double infinity = DoubleFromBits(0x7ff00000, 0x00000000);
17576 double max_normal = DoubleFromBits(0x7fefffff, 0xffffffffu); 17821 double max_normal = DoubleFromBits(0x7fefffff, 0xffffffffu);
17577 double min_normal = DoubleFromBits(0x00100000, 0x00000000); 17822 double min_normal = DoubleFromBits(0x00100000, 0x00000000);
17578 double max_denormal = DoubleFromBits(0x000fffff, 0xffffffffu); 17823 double max_denormal = DoubleFromBits(0x000fffff, 0xffffffffu);
17579 double min_denormal = DoubleFromBits(0x00000000, 0x00000001); 17824 double min_denormal = DoubleFromBits(0x00000000, 0x00000001);
(...skipping 23 matching lines...) Expand all
17603 -infinity, 17848 -infinity,
17604 -qnan, 17849 -qnan,
17605 -snan 17850 -snan
17606 }; 17851 };
17607 int num_test_values = 20; 17852 int num_test_values = 20;
17608 17853
17609 for (int i = 0; i < num_test_values; i++) { 17854 for (int i = 0; i < num_test_values; i++) {
17610 double test_value = test_values[i]; 17855 double test_value = test_values[i];
17611 17856
17612 // Check that Number::New preserves non-NaNs and quiets SNaNs. 17857 // Check that Number::New preserves non-NaNs and quiets SNaNs.
17613 v8::Handle<v8::Value> number = v8::Number::New(test_value); 17858 v8::Handle<v8::Value> number = v8::Number::New(isolate, test_value);
17614 double stored_number = number->NumberValue(); 17859 double stored_number = number->NumberValue();
17615 if (!std::isnan(test_value)) { 17860 if (!std::isnan(test_value)) {
17616 CHECK_EQ(test_value, stored_number); 17861 CHECK_EQ(test_value, stored_number);
17617 } else { 17862 } else {
17618 uint64_t stored_bits = DoubleToBits(stored_number); 17863 uint64_t stored_bits = DoubleToBits(stored_number);
17619 // Check if quiet nan (bits 51..62 all set). 17864 // Check if quiet nan (bits 51..62 all set).
17620 #if defined(V8_TARGET_ARCH_MIPS) && !defined(USE_SIMULATOR) 17865 #if defined(V8_TARGET_ARCH_MIPS) && !defined(USE_SIMULATOR)
17621 // Most significant fraction bit for quiet nan is set to 0 17866 // Most significant fraction bit for quiet nan is set to 0
17622 // on MIPS architecture. Allowed by IEEE-754. 17867 // on MIPS architecture. Allowed by IEEE-754.
17623 CHECK_EQ(0xffe, static_cast<int>((stored_bits >> 51) & 0xfff)); 17868 CHECK_EQ(0xffe, static_cast<int>((stored_bits >> 51) & 0xfff));
17624 #else 17869 #else
17625 CHECK_EQ(0xfff, static_cast<int>((stored_bits >> 51) & 0xfff)); 17870 CHECK_EQ(0xfff, static_cast<int>((stored_bits >> 51) & 0xfff));
17626 #endif 17871 #endif
17627 } 17872 }
17628 17873
17629 // Check that Date::New preserves non-NaNs in the date range and 17874 // Check that Date::New preserves non-NaNs in the date range and
17630 // quiets SNaNs. 17875 // quiets SNaNs.
17631 v8::Handle<v8::Value> date = 17876 v8::Handle<v8::Value> date =
17632 v8::Date::New(context->GetIsolate(), test_value); 17877 v8::Date::New(isolate, test_value);
17633 double expected_stored_date = DoubleToDateTime(test_value); 17878 double expected_stored_date = DoubleToDateTime(test_value);
17634 double stored_date = date->NumberValue(); 17879 double stored_date = date->NumberValue();
17635 if (!std::isnan(expected_stored_date)) { 17880 if (!std::isnan(expected_stored_date)) {
17636 CHECK_EQ(expected_stored_date, stored_date); 17881 CHECK_EQ(expected_stored_date, stored_date);
17637 } else { 17882 } else {
17638 uint64_t stored_bits = DoubleToBits(stored_date); 17883 uint64_t stored_bits = DoubleToBits(stored_date);
17639 // Check if quiet nan (bits 51..62 all set). 17884 // Check if quiet nan (bits 51..62 all set).
17640 #if defined(V8_TARGET_ARCH_MIPS) && !defined(USE_SIMULATOR) 17885 #if defined(V8_TARGET_ARCH_MIPS) && !defined(USE_SIMULATOR)
17641 // Most significant fraction bit for quiet nan is set to 0 17886 // Most significant fraction bit for quiet nan is set to 0
17642 // on MIPS architecture. Allowed by IEEE-754. 17887 // on MIPS architecture. Allowed by IEEE-754.
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
17894 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); 18139 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f")));
17895 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast( 18140 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast(
17896 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "g"))); 18141 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "g")));
17897 CHECK_EQ(0, f->GetScriptLineNumber()); 18142 CHECK_EQ(0, f->GetScriptLineNumber());
17898 CHECK_EQ(2, g->GetScriptLineNumber()); 18143 CHECK_EQ(2, g->GetScriptLineNumber());
17899 } 18144 }
17900 18145
17901 18146
17902 THREADED_TEST(ScriptColumnNumber) { 18147 THREADED_TEST(ScriptColumnNumber) {
17903 LocalContext env; 18148 LocalContext env;
17904 v8::HandleScope scope(env->GetIsolate()); 18149 v8::Isolate* isolate = env->GetIsolate();
18150 v8::HandleScope scope(isolate);
17905 v8::ScriptOrigin origin = 18151 v8::ScriptOrigin origin =
17906 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "test"), 18152 v8::ScriptOrigin(v8::String::NewFromUtf8(isolate, "test"),
17907 v8::Integer::New(3), v8::Integer::New(2)); 18153 v8::Integer::New(isolate, 3),
18154 v8::Integer::New(isolate, 2));
17908 v8::Handle<v8::String> script = v8::String::NewFromUtf8( 18155 v8::Handle<v8::String> script = v8::String::NewFromUtf8(
17909 env->GetIsolate(), "function foo() {}\n\n function bar() {}"); 18156 isolate, "function foo() {}\n\n function bar() {}");
17910 v8::Script::Compile(script, &origin)->Run(); 18157 v8::Script::Compile(script, &origin)->Run();
17911 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( 18158 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast(
17912 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo"))); 18159 env->Global()->Get(v8::String::NewFromUtf8(isolate, "foo")));
17913 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast( 18160 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast(
17914 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "bar"))); 18161 env->Global()->Get(v8::String::NewFromUtf8(isolate, "bar")));
17915 CHECK_EQ(14, foo->GetScriptColumnNumber()); 18162 CHECK_EQ(14, foo->GetScriptColumnNumber());
17916 CHECK_EQ(17, bar->GetScriptColumnNumber()); 18163 CHECK_EQ(17, bar->GetScriptColumnNumber());
17917 } 18164 }
17918 18165
17919 18166
17920 THREADED_TEST(FunctionIsBuiltin) { 18167 THREADED_TEST(FunctionIsBuiltin) {
17921 LocalContext env; 18168 LocalContext env;
17922 v8::HandleScope scope(env->GetIsolate()); 18169 v8::Isolate* isolate = env->GetIsolate();
18170 v8::HandleScope scope(isolate);
17923 v8::Local<v8::Function> f; 18171 v8::Local<v8::Function> f;
17924 f = v8::Local<v8::Function>::Cast(CompileRun("Math.floor")); 18172 f = v8::Local<v8::Function>::Cast(CompileRun("Math.floor"));
17925 CHECK(f->IsBuiltin()); 18173 CHECK(f->IsBuiltin());
17926 f = v8::Local<v8::Function>::Cast(CompileRun("Object")); 18174 f = v8::Local<v8::Function>::Cast(CompileRun("Object"));
17927 CHECK(f->IsBuiltin()); 18175 CHECK(f->IsBuiltin());
17928 f = v8::Local<v8::Function>::Cast(CompileRun("Object.__defineSetter__")); 18176 f = v8::Local<v8::Function>::Cast(CompileRun("Object.__defineSetter__"));
17929 CHECK(f->IsBuiltin()); 18177 CHECK(f->IsBuiltin());
17930 f = v8::Local<v8::Function>::Cast(CompileRun("Array.prototype.toString")); 18178 f = v8::Local<v8::Function>::Cast(CompileRun("Array.prototype.toString"));
17931 CHECK(f->IsBuiltin()); 18179 CHECK(f->IsBuiltin());
17932 f = v8::Local<v8::Function>::Cast(CompileRun("function a() {}; a;")); 18180 f = v8::Local<v8::Function>::Cast(CompileRun("function a() {}; a;"));
17933 CHECK(!f->IsBuiltin()); 18181 CHECK(!f->IsBuiltin());
17934 } 18182 }
17935 18183
17936 18184
17937 THREADED_TEST(FunctionGetScriptId) { 18185 THREADED_TEST(FunctionGetScriptId) {
17938 LocalContext env; 18186 LocalContext env;
17939 v8::HandleScope scope(env->GetIsolate()); 18187 v8::Isolate* isolate = env->GetIsolate();
18188 v8::HandleScope scope(isolate);
17940 v8::ScriptOrigin origin = 18189 v8::ScriptOrigin origin =
17941 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "test"), 18190 v8::ScriptOrigin(v8::String::NewFromUtf8(isolate, "test"),
17942 v8::Integer::New(3), v8::Integer::New(2)); 18191 v8::Integer::New(isolate, 3),
18192 v8::Integer::New(isolate, 2));
17943 v8::Handle<v8::String> scriptSource = v8::String::NewFromUtf8( 18193 v8::Handle<v8::String> scriptSource = v8::String::NewFromUtf8(
17944 env->GetIsolate(), "function foo() {}\n\n function bar() {}"); 18194 isolate, "function foo() {}\n\n function bar() {}");
17945 v8::Local<v8::Script> script(v8::Script::Compile(scriptSource, &origin)); 18195 v8::Local<v8::Script> script(v8::Script::Compile(scriptSource, &origin));
17946 script->Run(); 18196 script->Run();
17947 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( 18197 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast(
17948 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo"))); 18198 env->Global()->Get(v8::String::NewFromUtf8(isolate, "foo")));
17949 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast( 18199 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast(
17950 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "bar"))); 18200 env->Global()->Get(v8::String::NewFromUtf8(isolate, "bar")));
17951 CHECK_EQ(script->GetId(), foo->ScriptId()); 18201 CHECK_EQ(script->GetId(), foo->ScriptId());
17952 CHECK_EQ(script->GetId(), bar->ScriptId()); 18202 CHECK_EQ(script->GetId(), bar->ScriptId());
17953 } 18203 }
17954 18204
17955 18205
17956 THREADED_TEST(FunctionGetBoundFunction) { 18206 THREADED_TEST(FunctionGetBoundFunction) {
17957 LocalContext env; 18207 LocalContext env;
17958 v8::HandleScope scope(env->GetIsolate()); 18208 v8::HandleScope scope(env->GetIsolate());
17959 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::NewFromUtf8( 18209 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::NewFromUtf8(
17960 env->GetIsolate(), "test")); 18210 env->GetIsolate(), "test"));
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
18013 const v8::PropertyCallbackInfo<v8::Value>& info) { 18263 const v8::PropertyCallbackInfo<v8::Value>& info) {
18014 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); 18264 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject());
18015 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); 18265 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject());
18016 if (!name->Equals(v8_str("foo"))) return; 18266 if (!name->Equals(v8_str("foo"))) return;
18017 info.This()->Set(v8_str("y"), v8_num(23)); 18267 info.This()->Set(v8_str("y"), v8_num(23));
18018 info.GetReturnValue().Set(v8_num(23)); 18268 info.GetReturnValue().Set(v8_num(23));
18019 } 18269 }
18020 18270
18021 18271
18022 TEST(SetterOnConstructorPrototype) { 18272 TEST(SetterOnConstructorPrototype) {
18023 v8::HandleScope scope(CcTest::isolate()); 18273 v8::Isolate* isolate = CcTest::isolate();
18024 Local<ObjectTemplate> templ = ObjectTemplate::New(); 18274 v8::HandleScope scope(isolate);
18275 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
18025 templ->SetAccessor(v8_str("x"), 18276 templ->SetAccessor(v8_str("x"),
18026 GetterWhichReturns42, 18277 GetterWhichReturns42,
18027 SetterWhichSetsYOnThisTo23); 18278 SetterWhichSetsYOnThisTo23);
18028 LocalContext context; 18279 LocalContext context;
18029 context->Global()->Set(v8_str("P"), templ->NewInstance()); 18280 context->Global()->Set(v8_str("P"), templ->NewInstance());
18030 CompileRun("function C1() {" 18281 CompileRun("function C1() {"
18031 " this.x = 23;" 18282 " this.x = 23;"
18032 "};" 18283 "};"
18033 "C1.prototype = P;" 18284 "C1.prototype = P;"
18034 "function C2() {" 18285 "function C2() {"
(...skipping 30 matching lines...) Expand all
18065 Local<String> name, 18316 Local<String> name,
18066 Local<Value> value, 18317 Local<Value> value,
18067 const v8::PropertyCallbackInfo<v8::Value>& info) { 18318 const v8::PropertyCallbackInfo<v8::Value>& info) {
18068 if (name->Equals(v8_str("x"))) { 18319 if (name->Equals(v8_str("x"))) {
18069 info.This()->Set(v8_str("y"), v8_num(23)); 18320 info.This()->Set(v8_str("y"), v8_num(23));
18070 } 18321 }
18071 } 18322 }
18072 18323
18073 18324
18074 THREADED_TEST(InterceptorOnConstructorPrototype) { 18325 THREADED_TEST(InterceptorOnConstructorPrototype) {
18075 v8::HandleScope scope(CcTest::isolate()); 18326 v8::Isolate* isolate = CcTest::isolate();
18076 Local<ObjectTemplate> templ = ObjectTemplate::New(); 18327 v8::HandleScope scope(isolate);
18328 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
18077 templ->SetNamedPropertyHandler(NamedPropertyGetterWhichReturns42, 18329 templ->SetNamedPropertyHandler(NamedPropertyGetterWhichReturns42,
18078 NamedPropertySetterWhichSetsYOnThisTo23); 18330 NamedPropertySetterWhichSetsYOnThisTo23);
18079 LocalContext context; 18331 LocalContext context;
18080 context->Global()->Set(v8_str("P"), templ->NewInstance()); 18332 context->Global()->Set(v8_str("P"), templ->NewInstance());
18081 CompileRun("function C1() {" 18333 CompileRun("function C1() {"
18082 " this.x = 23;" 18334 " this.x = 23;"
18083 "};" 18335 "};"
18084 "C1.prototype = P;" 18336 "C1.prototype = P;"
18085 "function C2() {" 18337 "function C2() {"
18086 " this.x = 23" 18338 " this.x = 23"
(...skipping 18 matching lines...) Expand all
18105 } 18357 }
18106 18358
18107 18359
18108 TEST(Regress618) { 18360 TEST(Regress618) {
18109 const char* source = "function C1() {" 18361 const char* source = "function C1() {"
18110 " this.x = 23;" 18362 " this.x = 23;"
18111 "};" 18363 "};"
18112 "C1.prototype = P;"; 18364 "C1.prototype = P;";
18113 18365
18114 LocalContext context; 18366 LocalContext context;
18115 v8::HandleScope scope(context->GetIsolate()); 18367 v8::Isolate* isolate = context->GetIsolate();
18368 v8::HandleScope scope(isolate);
18116 v8::Local<v8::Script> script; 18369 v8::Local<v8::Script> script;
18117 18370
18118 // Use a simple object as prototype. 18371 // Use a simple object as prototype.
18119 v8::Local<v8::Object> prototype = v8::Object::New(); 18372 v8::Local<v8::Object> prototype = v8::Object::New(isolate);
18120 prototype->Set(v8_str("y"), v8_num(42)); 18373 prototype->Set(v8_str("y"), v8_num(42));
18121 context->Global()->Set(v8_str("P"), prototype); 18374 context->Global()->Set(v8_str("P"), prototype);
18122 18375
18123 // This compile will add the code to the compilation cache. 18376 // This compile will add the code to the compilation cache.
18124 CompileRun(source); 18377 CompileRun(source);
18125 18378
18126 script = v8::Script::Compile(v8_str("new C1();")); 18379 script = v8::Script::Compile(v8_str("new C1();"));
18127 // Allow enough iterations for the inobject slack tracking logic 18380 // Allow enough iterations for the inobject slack tracking logic
18128 // to finalize instance size and install the fast construct stub. 18381 // to finalize instance size and install the fast construct stub.
18129 for (int i = 0; i < 256; i++) { 18382 for (int i = 0; i < 256; i++) {
18130 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); 18383 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run());
18131 CHECK_EQ(23, c1->Get(v8_str("x"))->Int32Value()); 18384 CHECK_EQ(23, c1->Get(v8_str("x"))->Int32Value());
18132 CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value()); 18385 CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value());
18133 } 18386 }
18134 18387
18135 // Use an API object with accessors as prototype. 18388 // Use an API object with accessors as prototype.
18136 Local<ObjectTemplate> templ = ObjectTemplate::New(); 18389 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
18137 templ->SetAccessor(v8_str("x"), 18390 templ->SetAccessor(v8_str("x"),
18138 GetterWhichReturns42, 18391 GetterWhichReturns42,
18139 SetterWhichSetsYOnThisTo23); 18392 SetterWhichSetsYOnThisTo23);
18140 context->Global()->Set(v8_str("P"), templ->NewInstance()); 18393 context->Global()->Set(v8_str("P"), templ->NewInstance());
18141 18394
18142 // This compile will get the code from the compilation cache. 18395 // This compile will get the code from the compilation cache.
18143 CompileRun(source); 18396 CompileRun(source);
18144 18397
18145 script = v8::Script::Compile(v8_str("new C1();")); 18398 script = v8::Script::Compile(v8_str("new C1();"));
18146 for (int i = 0; i < 10; i++) { 18399 for (int i = 0; i < 10; i++) {
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
18563 } 18816 }
18564 18817
18565 18818
18566 TEST(GCInFailedAccessCheckCallback) { 18819 TEST(GCInFailedAccessCheckCallback) {
18567 // Install a failed access check callback that performs a GC on each 18820 // Install a failed access check callback that performs a GC on each
18568 // invocation. Then force the callback to be called from va 18821 // invocation. Then force the callback to be called from va
18569 18822
18570 v8::V8::Initialize(); 18823 v8::V8::Initialize();
18571 v8::V8::SetFailedAccessCheckCallbackFunction(&FailedAccessCheckCallbackGC); 18824 v8::V8::SetFailedAccessCheckCallbackFunction(&FailedAccessCheckCallbackGC);
18572 18825
18573 v8::HandleScope scope(CcTest::isolate()); 18826 v8::Isolate* isolate = CcTest::isolate();
18827 v8::HandleScope scope(isolate);
18574 18828
18575 // Create an ObjectTemplate for global objects and install access 18829 // Create an ObjectTemplate for global objects and install access
18576 // check callbacks that will block access. 18830 // check callbacks that will block access.
18577 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 18831 v8::Handle<v8::ObjectTemplate> global_template =
18832 v8::ObjectTemplate::New(isolate);
18578 global_template->SetAccessCheckCallbacks(NamedGetAccessBlocker, 18833 global_template->SetAccessCheckCallbacks(NamedGetAccessBlocker,
18579 IndexedGetAccessBlocker, 18834 IndexedGetAccessBlocker,
18580 v8::Handle<v8::Value>(), 18835 v8::Handle<v8::Value>(),
18581 false); 18836 false);
18582 18837
18583 // Create a context and set an x property on it's global object. 18838 // Create a context and set an x property on it's global object.
18584 LocalContext context0(NULL, global_template); 18839 LocalContext context0(NULL, global_template);
18585 context0->Global()->Set(v8_str("x"), v8_num(42)); 18840 context0->Global()->Set(v8_str("x"), v8_num(42));
18586 v8::Handle<v8::Object> global0 = context0->Global(); 18841 v8::Handle<v8::Object> global0 = context0->Global();
18587 18842
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
19173 19428
19174 int counter_; 19429 int counter_;
19175 v8::Persistent<v8::Object>* object_; 19430 v8::Persistent<v8::Object>* object_;
19176 }; 19431 };
19177 19432
19178 19433
19179 TEST(PersistentHandleVisitor) { 19434 TEST(PersistentHandleVisitor) {
19180 LocalContext context; 19435 LocalContext context;
19181 v8::Isolate* isolate = context->GetIsolate(); 19436 v8::Isolate* isolate = context->GetIsolate();
19182 v8::HandleScope scope(isolate); 19437 v8::HandleScope scope(isolate);
19183 v8::Persistent<v8::Object> object(isolate, v8::Object::New()); 19438 v8::Persistent<v8::Object> object(isolate, v8::Object::New(isolate));
19184 CHECK_EQ(0, object.WrapperClassId()); 19439 CHECK_EQ(0, object.WrapperClassId());
19185 object.SetWrapperClassId(42); 19440 object.SetWrapperClassId(42);
19186 CHECK_EQ(42, object.WrapperClassId()); 19441 CHECK_EQ(42, object.WrapperClassId());
19187 19442
19188 Visitor42 visitor(&object); 19443 Visitor42 visitor(&object);
19189 v8::V8::VisitHandlesWithClassIds(&visitor); 19444 v8::V8::VisitHandlesWithClassIds(&visitor);
19190 CHECK_EQ(1, visitor.counter_); 19445 CHECK_EQ(1, visitor.counter_);
19191 19446
19192 object.Reset(); 19447 object.Reset();
19193 } 19448 }
19194 19449
19195 19450
19196 TEST(WrapperClassId) { 19451 TEST(WrapperClassId) {
19197 LocalContext context; 19452 LocalContext context;
19198 v8::Isolate* isolate = context->GetIsolate(); 19453 v8::Isolate* isolate = context->GetIsolate();
19199 v8::HandleScope scope(isolate); 19454 v8::HandleScope scope(isolate);
19200 v8::Persistent<v8::Object> object(isolate, v8::Object::New()); 19455 v8::Persistent<v8::Object> object(isolate, v8::Object::New(isolate));
19201 CHECK_EQ(0, object.WrapperClassId()); 19456 CHECK_EQ(0, object.WrapperClassId());
19202 object.SetWrapperClassId(65535); 19457 object.SetWrapperClassId(65535);
19203 CHECK_EQ(65535, object.WrapperClassId()); 19458 CHECK_EQ(65535, object.WrapperClassId());
19204 object.Reset(); 19459 object.Reset();
19205 } 19460 }
19206 19461
19207 19462
19208 TEST(PersistentHandleInNewSpaceVisitor) { 19463 TEST(PersistentHandleInNewSpaceVisitor) {
19209 LocalContext context; 19464 LocalContext context;
19210 v8::Isolate* isolate = context->GetIsolate(); 19465 v8::Isolate* isolate = context->GetIsolate();
19211 v8::HandleScope scope(isolate); 19466 v8::HandleScope scope(isolate);
19212 v8::Persistent<v8::Object> object1(isolate, v8::Object::New()); 19467 v8::Persistent<v8::Object> object1(isolate, v8::Object::New(isolate));
19213 CHECK_EQ(0, object1.WrapperClassId()); 19468 CHECK_EQ(0, object1.WrapperClassId());
19214 object1.SetWrapperClassId(42); 19469 object1.SetWrapperClassId(42);
19215 CHECK_EQ(42, object1.WrapperClassId()); 19470 CHECK_EQ(42, object1.WrapperClassId());
19216 19471
19217 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 19472 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
19218 19473
19219 v8::Persistent<v8::Object> object2(isolate, v8::Object::New()); 19474 v8::Persistent<v8::Object> object2(isolate, v8::Object::New(isolate));
19220 CHECK_EQ(0, object2.WrapperClassId()); 19475 CHECK_EQ(0, object2.WrapperClassId());
19221 object2.SetWrapperClassId(42); 19476 object2.SetWrapperClassId(42);
19222 CHECK_EQ(42, object2.WrapperClassId()); 19477 CHECK_EQ(42, object2.WrapperClassId());
19223 19478
19224 Visitor42 visitor(&object2); 19479 Visitor42 visitor(&object2);
19225 v8::V8::VisitHandlesForPartialDependence(isolate, &visitor); 19480 v8::V8::VisitHandlesForPartialDependence(isolate, &visitor);
19226 CHECK_EQ(1, visitor.counter_); 19481 CHECK_EQ(1, visitor.counter_);
19227 19482
19228 object1.Reset(); 19483 object1.Reset();
19229 object2.Reset(); 19484 object2.Reset();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
19280 v8::RegExp::kMultiline)); 19535 v8::RegExp::kMultiline));
19281 CHECK(re->IsRegExp()); 19536 CHECK(re->IsRegExp());
19282 CHECK(re->GetSource()->Equals(v8_str("foobarbaz"))); 19537 CHECK(re->GetSource()->Equals(v8_str("foobarbaz")));
19283 CHECK_EQ(v8::RegExp::kIgnoreCase | v8::RegExp::kMultiline, 19538 CHECK_EQ(v8::RegExp::kIgnoreCase | v8::RegExp::kMultiline,
19284 static_cast<int>(re->GetFlags())); 19539 static_cast<int>(re->GetFlags()));
19285 19540
19286 context->Global()->Set(v8_str("re"), re); 19541 context->Global()->Set(v8_str("re"), re);
19287 ExpectTrue("re.test('FoobarbaZ')"); 19542 ExpectTrue("re.test('FoobarbaZ')");
19288 19543
19289 // RegExps are objects on which you can set properties. 19544 // RegExps are objects on which you can set properties.
19290 re->Set(v8_str("property"), v8::Integer::New(32)); 19545 re->Set(v8_str("property"), v8::Integer::New(context->GetIsolate(), 32));
19291 v8::Handle<v8::Value> value(CompileRun("re.property")); 19546 v8::Handle<v8::Value> value(CompileRun("re.property"));
19292 CHECK_EQ(32, value->Int32Value()); 19547 CHECK_EQ(32, value->Int32Value());
19293 19548
19294 v8::TryCatch try_catch; 19549 v8::TryCatch try_catch;
19295 re = v8::RegExp::New(v8_str("foo["), v8::RegExp::kNone); 19550 re = v8::RegExp::New(v8_str("foo["), v8::RegExp::kNone);
19296 CHECK(re.IsEmpty()); 19551 CHECK(re.IsEmpty());
19297 CHECK(try_catch.HasCaught()); 19552 CHECK(try_catch.HasCaught());
19298 context->Global()->Set(v8_str("ex"), try_catch.Exception()); 19553 context->Global()->Set(v8_str("ex"), try_catch.Exception());
19299 ExpectTrue("ex instanceof SyntaxError"); 19554 ExpectTrue("ex instanceof SyntaxError");
19300 } 19555 }
(...skipping 26 matching lines...) Expand all
19327 19582
19328 static void Enumerator(const v8::PropertyCallbackInfo<v8::Array>& info) { 19583 static void Enumerator(const v8::PropertyCallbackInfo<v8::Array>& info) {
19329 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate()); 19584 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate());
19330 result->Set(0, v8_str("universalAnswer")); 19585 result->Set(0, v8_str("universalAnswer"));
19331 info.GetReturnValue().Set(result); 19586 info.GetReturnValue().Set(result);
19332 } 19587 }
19333 19588
19334 19589
19335 TEST(NamedEnumeratorAndForIn) { 19590 TEST(NamedEnumeratorAndForIn) {
19336 LocalContext context; 19591 LocalContext context;
19337 v8::HandleScope handle_scope(context->GetIsolate()); 19592 v8::Isolate* isolate = context->GetIsolate();
19593 v8::HandleScope handle_scope(isolate);
19338 v8::Context::Scope context_scope(context.local()); 19594 v8::Context::Scope context_scope(context.local());
19339 19595
19340 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(); 19596 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(isolate);
19341 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator); 19597 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator);
19342 context->Global()->Set(v8_str("o"), tmpl->NewInstance()); 19598 context->Global()->Set(v8_str("o"), tmpl->NewInstance());
19343 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( 19599 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun(
19344 "var result = []; for (var k in o) result.push(k); result")); 19600 "var result = []; for (var k in o) result.push(k); result"));
19345 CHECK_EQ(1, result->Length()); 19601 CHECK_EQ(1, result->Length());
19346 CHECK_EQ(v8_str("universalAnswer"), result->Get(0)); 19602 CHECK_EQ(v8_str("universalAnswer"), result->Get(0));
19347 } 19603 }
19348 19604
19349 19605
19350 TEST(DefinePropertyPostDetach) { 19606 TEST(DefinePropertyPostDetach) {
19351 LocalContext context; 19607 LocalContext context;
19352 v8::HandleScope scope(context->GetIsolate()); 19608 v8::HandleScope scope(context->GetIsolate());
19353 v8::Handle<v8::Object> proxy = context->Global(); 19609 v8::Handle<v8::Object> proxy = context->Global();
19354 v8::Handle<v8::Function> define_property = 19610 v8::Handle<v8::Function> define_property =
19355 CompileRun("(function() {" 19611 CompileRun("(function() {"
19356 " Object.defineProperty(" 19612 " Object.defineProperty("
19357 " this," 19613 " this,"
19358 " 1," 19614 " 1,"
19359 " { configurable: true, enumerable: true, value: 3 });" 19615 " { configurable: true, enumerable: true, value: 3 });"
19360 "})").As<Function>(); 19616 "})").As<Function>();
19361 context->DetachGlobal(); 19617 context->DetachGlobal();
19362 define_property->Call(proxy, 0, NULL); 19618 define_property->Call(proxy, 0, NULL);
19363 } 19619 }
19364 19620
19365 19621
19366 static void InstallContextId(v8::Handle<Context> context, int id) { 19622 static void InstallContextId(v8::Handle<Context> context, int id) {
19367 Context::Scope scope(context); 19623 Context::Scope scope(context);
19368 CompileRun("Object.prototype").As<Object>()-> 19624 CompileRun("Object.prototype").As<Object>()->
19369 Set(v8_str("context_id"), v8::Integer::New(id)); 19625 Set(v8_str("context_id"), v8::Integer::New(context->GetIsolate(), id));
19370 } 19626 }
19371 19627
19372 19628
19373 static void CheckContextId(v8::Handle<Object> object, int expected) { 19629 static void CheckContextId(v8::Handle<Object> object, int expected) {
19374 CHECK_EQ(expected, object->Get(v8_str("context_id"))->Int32Value()); 19630 CHECK_EQ(expected, object->Get(v8_str("context_id"))->Int32Value());
19375 } 19631 }
19376 19632
19377 19633
19378 THREADED_TEST(CreationContext) { 19634 THREADED_TEST(CreationContext) {
19379 v8::Isolate* isolate = CcTest::isolate(); 19635 v8::Isolate* isolate = CcTest::isolate();
19380 HandleScope handle_scope(isolate); 19636 HandleScope handle_scope(isolate);
19381 Handle<Context> context1 = Context::New(isolate); 19637 Handle<Context> context1 = Context::New(isolate);
19382 InstallContextId(context1, 1); 19638 InstallContextId(context1, 1);
19383 Handle<Context> context2 = Context::New(isolate); 19639 Handle<Context> context2 = Context::New(isolate);
19384 InstallContextId(context2, 2); 19640 InstallContextId(context2, 2);
19385 Handle<Context> context3 = Context::New(isolate); 19641 Handle<Context> context3 = Context::New(isolate);
19386 InstallContextId(context3, 3); 19642 InstallContextId(context3, 3);
19387 19643
19388 Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(isolate); 19644 Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(isolate);
19389 19645
19390 Local<Object> object1; 19646 Local<Object> object1;
19391 Local<Function> func1; 19647 Local<Function> func1;
19392 { 19648 {
19393 Context::Scope scope(context1); 19649 Context::Scope scope(context1);
19394 object1 = Object::New(); 19650 object1 = Object::New(isolate);
19395 func1 = tmpl->GetFunction(); 19651 func1 = tmpl->GetFunction();
19396 } 19652 }
19397 19653
19398 Local<Object> object2; 19654 Local<Object> object2;
19399 Local<Function> func2; 19655 Local<Function> func2;
19400 { 19656 {
19401 Context::Scope scope(context2); 19657 Context::Scope scope(context2);
19402 object2 = Object::New(); 19658 object2 = Object::New(isolate);
19403 func2 = tmpl->GetFunction(); 19659 func2 = tmpl->GetFunction();
19404 } 19660 }
19405 19661
19406 Local<Object> instance1; 19662 Local<Object> instance1;
19407 Local<Object> instance2; 19663 Local<Object> instance2;
19408 19664
19409 { 19665 {
19410 Context::Scope scope(context3); 19666 Context::Scope scope(context3);
19411 instance1 = func1->NewInstance(); 19667 instance1 = func1->NewInstance();
19412 instance2 = func2->NewInstance(); 19668 instance2 = func2->NewInstance();
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
19511 19767
19512 void HasOwnPropertyAccessorGetter( 19768 void HasOwnPropertyAccessorGetter(
19513 Local<String> property, 19769 Local<String> property,
19514 const v8::PropertyCallbackInfo<v8::Value>& info) { 19770 const v8::PropertyCallbackInfo<v8::Value>& info) {
19515 info.GetReturnValue().Set(v8_str("yes")); 19771 info.GetReturnValue().Set(v8_str("yes"));
19516 } 19772 }
19517 19773
19518 19774
19519 TEST(HasOwnProperty) { 19775 TEST(HasOwnProperty) {
19520 LocalContext env; 19776 LocalContext env;
19521 v8::HandleScope scope(env->GetIsolate()); 19777 v8::Isolate* isolate = env->GetIsolate();
19778 v8::HandleScope scope(isolate);
19522 { // Check normal properties and defined getters. 19779 { // Check normal properties and defined getters.
19523 Handle<Value> value = CompileRun( 19780 Handle<Value> value = CompileRun(
19524 "function Foo() {" 19781 "function Foo() {"
19525 " this.foo = 11;" 19782 " this.foo = 11;"
19526 " this.__defineGetter__('baz', function() { return 1; });" 19783 " this.__defineGetter__('baz', function() { return 1; });"
19527 "};" 19784 "};"
19528 "function Bar() { " 19785 "function Bar() { "
19529 " this.bar = 13;" 19786 " this.bar = 13;"
19530 " this.__defineGetter__('bla', function() { return 2; });" 19787 " this.__defineGetter__('bla', function() { return 2; });"
19531 "};" 19788 "};"
19532 "Bar.prototype = new Foo();" 19789 "Bar.prototype = new Foo();"
19533 "new Bar();"); 19790 "new Bar();");
19534 CHECK(value->IsObject()); 19791 CHECK(value->IsObject());
19535 Handle<Object> object = value->ToObject(); 19792 Handle<Object> object = value->ToObject();
19536 CHECK(object->Has(v8_str("foo"))); 19793 CHECK(object->Has(v8_str("foo")));
19537 CHECK(!object->HasOwnProperty(v8_str("foo"))); 19794 CHECK(!object->HasOwnProperty(v8_str("foo")));
19538 CHECK(object->HasOwnProperty(v8_str("bar"))); 19795 CHECK(object->HasOwnProperty(v8_str("bar")));
19539 CHECK(object->Has(v8_str("baz"))); 19796 CHECK(object->Has(v8_str("baz")));
19540 CHECK(!object->HasOwnProperty(v8_str("baz"))); 19797 CHECK(!object->HasOwnProperty(v8_str("baz")));
19541 CHECK(object->HasOwnProperty(v8_str("bla"))); 19798 CHECK(object->HasOwnProperty(v8_str("bla")));
19542 } 19799 }
19543 { // Check named getter interceptors. 19800 { // Check named getter interceptors.
19544 Handle<ObjectTemplate> templ = ObjectTemplate::New(); 19801 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate);
19545 templ->SetNamedPropertyHandler(HasOwnPropertyNamedPropertyGetter); 19802 templ->SetNamedPropertyHandler(HasOwnPropertyNamedPropertyGetter);
19546 Handle<Object> instance = templ->NewInstance(); 19803 Handle<Object> instance = templ->NewInstance();
19547 CHECK(!instance->HasOwnProperty(v8_str("42"))); 19804 CHECK(!instance->HasOwnProperty(v8_str("42")));
19548 CHECK(instance->HasOwnProperty(v8_str("foo"))); 19805 CHECK(instance->HasOwnProperty(v8_str("foo")));
19549 CHECK(!instance->HasOwnProperty(v8_str("bar"))); 19806 CHECK(!instance->HasOwnProperty(v8_str("bar")));
19550 } 19807 }
19551 { // Check indexed getter interceptors. 19808 { // Check indexed getter interceptors.
19552 Handle<ObjectTemplate> templ = ObjectTemplate::New(); 19809 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate);
19553 templ->SetIndexedPropertyHandler(HasOwnPropertyIndexedPropertyGetter); 19810 templ->SetIndexedPropertyHandler(HasOwnPropertyIndexedPropertyGetter);
19554 Handle<Object> instance = templ->NewInstance(); 19811 Handle<Object> instance = templ->NewInstance();
19555 CHECK(instance->HasOwnProperty(v8_str("42"))); 19812 CHECK(instance->HasOwnProperty(v8_str("42")));
19556 CHECK(!instance->HasOwnProperty(v8_str("43"))); 19813 CHECK(!instance->HasOwnProperty(v8_str("43")));
19557 CHECK(!instance->HasOwnProperty(v8_str("foo"))); 19814 CHECK(!instance->HasOwnProperty(v8_str("foo")));
19558 } 19815 }
19559 { // Check named query interceptors. 19816 { // Check named query interceptors.
19560 Handle<ObjectTemplate> templ = ObjectTemplate::New(); 19817 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate);
19561 templ->SetNamedPropertyHandler(0, 0, HasOwnPropertyNamedPropertyQuery); 19818 templ->SetNamedPropertyHandler(0, 0, HasOwnPropertyNamedPropertyQuery);
19562 Handle<Object> instance = templ->NewInstance(); 19819 Handle<Object> instance = templ->NewInstance();
19563 CHECK(instance->HasOwnProperty(v8_str("foo"))); 19820 CHECK(instance->HasOwnProperty(v8_str("foo")));
19564 CHECK(!instance->HasOwnProperty(v8_str("bar"))); 19821 CHECK(!instance->HasOwnProperty(v8_str("bar")));
19565 } 19822 }
19566 { // Check indexed query interceptors. 19823 { // Check indexed query interceptors.
19567 Handle<ObjectTemplate> templ = ObjectTemplate::New(); 19824 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate);
19568 templ->SetIndexedPropertyHandler(0, 0, HasOwnPropertyIndexedPropertyQuery); 19825 templ->SetIndexedPropertyHandler(0, 0, HasOwnPropertyIndexedPropertyQuery);
19569 Handle<Object> instance = templ->NewInstance(); 19826 Handle<Object> instance = templ->NewInstance();
19570 CHECK(instance->HasOwnProperty(v8_str("42"))); 19827 CHECK(instance->HasOwnProperty(v8_str("42")));
19571 CHECK(!instance->HasOwnProperty(v8_str("41"))); 19828 CHECK(!instance->HasOwnProperty(v8_str("41")));
19572 } 19829 }
19573 { // Check callbacks. 19830 { // Check callbacks.
19574 Handle<ObjectTemplate> templ = ObjectTemplate::New(); 19831 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate);
19575 templ->SetAccessor(v8_str("foo"), HasOwnPropertyAccessorGetter); 19832 templ->SetAccessor(v8_str("foo"), HasOwnPropertyAccessorGetter);
19576 Handle<Object> instance = templ->NewInstance(); 19833 Handle<Object> instance = templ->NewInstance();
19577 CHECK(instance->HasOwnProperty(v8_str("foo"))); 19834 CHECK(instance->HasOwnProperty(v8_str("foo")));
19578 CHECK(!instance->HasOwnProperty(v8_str("bar"))); 19835 CHECK(!instance->HasOwnProperty(v8_str("bar")));
19579 } 19836 }
19580 { // Check that query wins on disagreement. 19837 { // Check that query wins on disagreement.
19581 Handle<ObjectTemplate> templ = ObjectTemplate::New(); 19838 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate);
19582 templ->SetNamedPropertyHandler(HasOwnPropertyNamedPropertyGetter, 19839 templ->SetNamedPropertyHandler(HasOwnPropertyNamedPropertyGetter,
19583 0, 19840 0,
19584 HasOwnPropertyNamedPropertyQuery2); 19841 HasOwnPropertyNamedPropertyQuery2);
19585 Handle<Object> instance = templ->NewInstance(); 19842 Handle<Object> instance = templ->NewInstance();
19586 CHECK(!instance->HasOwnProperty(v8_str("foo"))); 19843 CHECK(!instance->HasOwnProperty(v8_str("foo")));
19587 CHECK(instance->HasOwnProperty(v8_str("bar"))); 19844 CHECK(instance->HasOwnProperty(v8_str("bar")));
19588 } 19845 }
19589 } 19846 }
19590 19847
19591 19848
19592 TEST(IndexedInterceptorWithStringProto) { 19849 TEST(IndexedInterceptorWithStringProto) {
19593 v8::HandleScope scope(CcTest::isolate()); 19850 v8::Isolate* isolate = CcTest::isolate();
19594 Handle<ObjectTemplate> templ = ObjectTemplate::New(); 19851 v8::HandleScope scope(isolate);
19852 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate);
19595 templ->SetIndexedPropertyHandler(NULL, 19853 templ->SetIndexedPropertyHandler(NULL,
19596 NULL, 19854 NULL,
19597 HasOwnPropertyIndexedPropertyQuery); 19855 HasOwnPropertyIndexedPropertyQuery);
19598 LocalContext context; 19856 LocalContext context;
19599 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 19857 context->Global()->Set(v8_str("obj"), templ->NewInstance());
19600 CompileRun("var s = new String('foobar'); obj.__proto__ = s;"); 19858 CompileRun("var s = new String('foobar'); obj.__proto__ = s;");
19601 // These should be intercepted. 19859 // These should be intercepted.
19602 CHECK(CompileRun("42 in obj")->BooleanValue()); 19860 CHECK(CompileRun("42 in obj")->BooleanValue());
19603 CHECK(CompileRun("'42' in obj")->BooleanValue()); 19861 CHECK(CompileRun("'42' in obj")->BooleanValue());
19604 // These should fall through to the String prototype. 19862 // These should fall through to the String prototype.
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
19711 v8::FunctionTemplate::New(isolate, NonObjectThis); 19969 v8::FunctionTemplate::New(isolate, NonObjectThis);
19712 Handle<Function> function = templ->GetFunction(); 19970 Handle<Function> function = templ->GetFunction();
19713 context->Global()->Set(v8_str("f"), function); 19971 context->Global()->Set(v8_str("f"), function);
19714 TryCatch try_catch; 19972 TryCatch try_catch;
19715 CompileRun("f.call(2)"); 19973 CompileRun("f.call(2)");
19716 } 19974 }
19717 19975
19718 19976
19719 // Regression test for issue 1470. 19977 // Regression test for issue 1470.
19720 THREADED_TEST(ReadOnlyIndexedProperties) { 19978 THREADED_TEST(ReadOnlyIndexedProperties) {
19721 v8::HandleScope scope(CcTest::isolate()); 19979 v8::Isolate* isolate = CcTest::isolate();
19722 Local<ObjectTemplate> templ = ObjectTemplate::New(); 19980 v8::HandleScope scope(isolate);
19981 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
19723 19982
19724 LocalContext context; 19983 LocalContext context;
19725 Local<v8::Object> obj = templ->NewInstance(); 19984 Local<v8::Object> obj = templ->NewInstance();
19726 context->Global()->Set(v8_str("obj"), obj); 19985 context->Global()->Set(v8_str("obj"), obj);
19727 obj->Set(v8_str("1"), v8_str("DONT_CHANGE"), v8::ReadOnly); 19986 obj->Set(v8_str("1"), v8_str("DONT_CHANGE"), v8::ReadOnly);
19728 obj->Set(v8_str("1"), v8_str("foobar")); 19987 obj->Set(v8_str("1"), v8_str("foobar"));
19729 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_str("1"))); 19988 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_str("1")));
19730 obj->Set(v8_num(2), v8_str("DONT_CHANGE"), v8::ReadOnly); 19989 obj->Set(v8_num(2), v8_str("DONT_CHANGE"), v8::ReadOnly);
19731 obj->Set(v8_num(2), v8_str("foobar")); 19990 obj->Set(v8_num(2), v8_str("foobar"));
19732 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_num(2))); 19991 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_num(2)));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
19780 20039
19781 return true; 20040 return true;
19782 } 20041 }
19783 20042
19784 20043
19785 THREADED_TEST(Regress93759) { 20044 THREADED_TEST(Regress93759) {
19786 v8::Isolate* isolate = CcTest::isolate(); 20045 v8::Isolate* isolate = CcTest::isolate();
19787 HandleScope scope(isolate); 20046 HandleScope scope(isolate);
19788 20047
19789 // Template for object with security check. 20048 // Template for object with security check.
19790 Local<ObjectTemplate> no_proto_template = v8::ObjectTemplate::New(); 20049 Local<ObjectTemplate> no_proto_template = v8::ObjectTemplate::New(isolate);
19791 // We don't do indexing, so any callback can be used for that. 20050 // We don't do indexing, so any callback can be used for that.
19792 no_proto_template->SetAccessCheckCallbacks( 20051 no_proto_template->SetAccessCheckCallbacks(
19793 BlockProtoNamedSecurityTestCallback, 20052 BlockProtoNamedSecurityTestCallback,
19794 IndexedSecurityTestCallback); 20053 IndexedSecurityTestCallback);
19795 20054
19796 // Templates for objects with hidden prototypes and possibly security check. 20055 // Templates for objects with hidden prototypes and possibly security check.
19797 Local<FunctionTemplate> hidden_proto_template = 20056 Local<FunctionTemplate> hidden_proto_template =
19798 v8::FunctionTemplate::New(isolate); 20057 v8::FunctionTemplate::New(isolate);
19799 hidden_proto_template->SetHiddenPrototype(true); 20058 hidden_proto_template->SetHiddenPrototype(true);
19800 20059
19801 Local<FunctionTemplate> protected_hidden_proto_template = 20060 Local<FunctionTemplate> protected_hidden_proto_template =
19802 v8::FunctionTemplate::New(isolate); 20061 v8::FunctionTemplate::New(isolate);
19803 protected_hidden_proto_template->InstanceTemplate()->SetAccessCheckCallbacks( 20062 protected_hidden_proto_template->InstanceTemplate()->SetAccessCheckCallbacks(
19804 BlockProtoNamedSecurityTestCallback, 20063 BlockProtoNamedSecurityTestCallback,
19805 IndexedSecurityTestCallback); 20064 IndexedSecurityTestCallback);
19806 protected_hidden_proto_template->SetHiddenPrototype(true); 20065 protected_hidden_proto_template->SetHiddenPrototype(true);
19807 20066
19808 // Context for "foreign" objects used in test. 20067 // Context for "foreign" objects used in test.
19809 Local<Context> context = v8::Context::New(isolate); 20068 Local<Context> context = v8::Context::New(isolate);
19810 context->Enter(); 20069 context->Enter();
19811 20070
19812 // Plain object, no security check. 20071 // Plain object, no security check.
19813 Local<Object> simple_object = Object::New(); 20072 Local<Object> simple_object = Object::New(isolate);
19814 20073
19815 // Object with explicit security check. 20074 // Object with explicit security check.
19816 Local<Object> protected_object = 20075 Local<Object> protected_object =
19817 no_proto_template->NewInstance(); 20076 no_proto_template->NewInstance();
19818 20077
19819 // JSGlobalProxy object, always have security check. 20078 // JSGlobalProxy object, always have security check.
19820 Local<Object> proxy_object = 20079 Local<Object> proxy_object =
19821 context->Global(); 20080 context->Global();
19822 20081
19823 // Global object, the prototype of proxy_object. No security checks. 20082 // Global object, the prototype of proxy_object. No security checks.
19824 Local<Object> global_object = 20083 Local<Object> global_object =
19825 proxy_object->GetPrototype()->ToObject(); 20084 proxy_object->GetPrototype()->ToObject();
19826 20085
19827 // Hidden prototype without security check. 20086 // Hidden prototype without security check.
19828 Local<Object> hidden_prototype = 20087 Local<Object> hidden_prototype =
19829 hidden_proto_template->GetFunction()->NewInstance(); 20088 hidden_proto_template->GetFunction()->NewInstance();
19830 Local<Object> object_with_hidden = 20089 Local<Object> object_with_hidden =
19831 Object::New(); 20090 Object::New(isolate);
19832 object_with_hidden->SetPrototype(hidden_prototype); 20091 object_with_hidden->SetPrototype(hidden_prototype);
19833 20092
19834 // Hidden prototype with security check on the hidden prototype. 20093 // Hidden prototype with security check on the hidden prototype.
19835 Local<Object> protected_hidden_prototype = 20094 Local<Object> protected_hidden_prototype =
19836 protected_hidden_proto_template->GetFunction()->NewInstance(); 20095 protected_hidden_proto_template->GetFunction()->NewInstance();
19837 Local<Object> object_with_protected_hidden = 20096 Local<Object> object_with_protected_hidden =
19838 Object::New(); 20097 Object::New(isolate);
19839 object_with_protected_hidden->SetPrototype(protected_hidden_prototype); 20098 object_with_protected_hidden->SetPrototype(protected_hidden_prototype);
19840 20099
19841 context->Exit(); 20100 context->Exit();
19842 20101
19843 // Template for object for second context. Values to test are put on it as 20102 // Template for object for second context. Values to test are put on it as
19844 // properties. 20103 // properties.
19845 Local<ObjectTemplate> global_template = ObjectTemplate::New(); 20104 Local<ObjectTemplate> global_template = ObjectTemplate::New(isolate);
19846 global_template->Set(v8_str("simple"), simple_object); 20105 global_template->Set(v8_str("simple"), simple_object);
19847 global_template->Set(v8_str("protected"), protected_object); 20106 global_template->Set(v8_str("protected"), protected_object);
19848 global_template->Set(v8_str("global"), global_object); 20107 global_template->Set(v8_str("global"), global_object);
19849 global_template->Set(v8_str("proxy"), proxy_object); 20108 global_template->Set(v8_str("proxy"), proxy_object);
19850 global_template->Set(v8_str("hidden"), object_with_hidden); 20109 global_template->Set(v8_str("hidden"), object_with_hidden);
19851 global_template->Set(v8_str("phidden"), object_with_protected_hidden); 20110 global_template->Set(v8_str("phidden"), object_with_protected_hidden);
19852 20111
19853 LocalContext context2(NULL, global_template); 20112 LocalContext context2(NULL, global_template);
19854 20113
19855 Local<Value> result1 = CompileRun("Object.getPrototypeOf(simple)"); 20114 Local<Value> result1 = CompileRun("Object.getPrototypeOf(simple)");
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
19985 "Function.prototype.apply.call(func)"); 20244 "Function.prototype.apply.call(func)");
19986 TestReceiver(i, foreign_context->Global(), 20245 TestReceiver(i, foreign_context->Global(),
19987 "Function.prototype.apply.apply(func)"); 20246 "Function.prototype.apply.apply(func)");
19988 // Making calls through built-in functions. 20247 // Making calls through built-in functions.
19989 TestReceiver(i, foreign_context->Global(), "[1].map(func)[0]"); 20248 TestReceiver(i, foreign_context->Global(), "[1].map(func)[0]");
19990 // ToString(func()) is func()[0], i.e., the returned this.id. 20249 // ToString(func()) is func()[0], i.e., the returned this.id.
19991 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/,func)[1]"))); 20250 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/,func)[1]")));
19992 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[1]"))); 20251 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[1]")));
19993 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[3]"))); 20252 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[3]")));
19994 20253
19995 // TODO(1547): Make the following also return "i".
19996 // Calling with environment record as base. 20254 // Calling with environment record as base.
19997 TestReceiver(o, context->Global(), "func()"); 20255 TestReceiver(i, foreign_context->Global(), "func()");
19998 // Calling with no base. 20256 // Calling with no base.
19999 TestReceiver(o, context->Global(), "(1,func)()"); 20257 TestReceiver(i, foreign_context->Global(), "(1,func)()");
20000 } 20258 }
20001 20259
20002 20260
20003 uint8_t callback_fired = 0; 20261 uint8_t callback_fired = 0;
20004 20262
20005 20263
20006 void CallCompletedCallback1() { 20264 void CallCompletedCallback1() {
20007 i::OS::Print("Firing callback 1.\n"); 20265 i::OS::Print("Firing callback 1.\n");
20008 callback_fired ^= 1; // Toggle first bit. 20266 callback_fired ^= 1; // Toggle first bit.
20009 } 20267 }
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
20237 isolate->Dispose(); 20495 isolate->Dispose();
20238 } 20496 }
20239 20497
20240 20498
20241 TEST(StringEmpty) { 20499 TEST(StringEmpty) {
20242 LocalContext context; 20500 LocalContext context;
20243 i::Factory* factory = CcTest::i_isolate()->factory(); 20501 i::Factory* factory = CcTest::i_isolate()->factory();
20244 v8::Isolate* isolate = CcTest::isolate(); 20502 v8::Isolate* isolate = CcTest::isolate();
20245 v8::HandleScope scope(isolate); 20503 v8::HandleScope scope(isolate);
20246 i::Handle<i::Object> empty_string = factory->empty_string(); 20504 i::Handle<i::Object> empty_string = factory->empty_string();
20247 CHECK(*v8::Utils::OpenHandle(*v8::String::Empty()) == *empty_string);
20248 CHECK(*v8::Utils::OpenHandle(*v8::String::Empty(isolate)) == *empty_string); 20505 CHECK(*v8::Utils::OpenHandle(*v8::String::Empty(isolate)) == *empty_string);
20249 } 20506 }
20250 20507
20251 20508
20252 static int instance_checked_getter_count = 0; 20509 static int instance_checked_getter_count = 0;
20253 static void InstanceCheckedGetter( 20510 static void InstanceCheckedGetter(
20254 Local<String> name, 20511 Local<String> name,
20255 const v8::PropertyCallbackInfo<v8::Value>& info) { 20512 const v8::PropertyCallbackInfo<v8::Value>& info) {
20256 CHECK_EQ(name, v8_str("foo")); 20513 CHECK_EQ(name, v8_str("foo"));
20257 instance_checked_getter_count++; 20514 instance_checked_getter_count++;
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
20463 CHECK_EQ(6, message->GetLineNumber()); 20720 CHECK_EQ(6, message->GetLineNumber());
20464 } 20721 }
20465 } 20722 }
20466 20723
20467 20724
20468 static void Helper137002(bool do_store, 20725 static void Helper137002(bool do_store,
20469 bool polymorphic, 20726 bool polymorphic,
20470 bool remove_accessor, 20727 bool remove_accessor,
20471 bool interceptor) { 20728 bool interceptor) {
20472 LocalContext context; 20729 LocalContext context;
20473 Local<ObjectTemplate> templ = ObjectTemplate::New(); 20730 Local<ObjectTemplate> templ = ObjectTemplate::New(context->GetIsolate());
20474 if (interceptor) { 20731 if (interceptor) {
20475 templ->SetNamedPropertyHandler(FooGetInterceptor, FooSetInterceptor); 20732 templ->SetNamedPropertyHandler(FooGetInterceptor, FooSetInterceptor);
20476 } else { 20733 } else {
20477 templ->SetAccessor(v8_str("foo"), 20734 templ->SetAccessor(v8_str("foo"),
20478 GetterWhichReturns42, 20735 GetterWhichReturns42,
20479 SetterWhichSetsYOnThisTo23); 20736 SetterWhichSetsYOnThisTo23);
20480 } 20737 }
20481 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 20738 context->Global()->Set(v8_str("obj"), templ->NewInstance());
20482 20739
20483 // Turn monomorphic on slow object with native accessor, then turn 20740 // Turn monomorphic on slow object with native accessor, then turn
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
20518 v8::HandleScope scope(CcTest::isolate()); 20775 v8::HandleScope scope(CcTest::isolate());
20519 for (int i = 0; i < 16; i++) { 20776 for (int i = 0; i < 16; i++) {
20520 Helper137002(i & 8, i & 4, i & 2, i & 1); 20777 Helper137002(i & 8, i & 4, i & 2, i & 1);
20521 } 20778 }
20522 } 20779 }
20523 20780
20524 20781
20525 THREADED_TEST(Regress137002b) { 20782 THREADED_TEST(Regress137002b) {
20526 i::FLAG_allow_natives_syntax = true; 20783 i::FLAG_allow_natives_syntax = true;
20527 LocalContext context; 20784 LocalContext context;
20528 v8::HandleScope scope(context->GetIsolate()); 20785 v8::Isolate* isolate = context->GetIsolate();
20529 Local<ObjectTemplate> templ = ObjectTemplate::New(); 20786 v8::HandleScope scope(isolate);
20787 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
20530 templ->SetAccessor(v8_str("foo"), 20788 templ->SetAccessor(v8_str("foo"),
20531 GetterWhichReturns42, 20789 GetterWhichReturns42,
20532 SetterWhichSetsYOnThisTo23); 20790 SetterWhichSetsYOnThisTo23);
20533 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 20791 context->Global()->Set(v8_str("obj"), templ->NewInstance());
20534 20792
20535 // Turn monomorphic on slow object with native accessor, then just 20793 // Turn monomorphic on slow object with native accessor, then just
20536 // delete the property and fail. 20794 // delete the property and fail.
20537 CompileRun("function load(x) { return x.foo; }" 20795 CompileRun("function load(x) { return x.foo; }"
20538 "function store(x) { x.foo = void 0; }" 20796 "function store(x) { x.foo = void 0; }"
20539 "function keyed_load(x, key) { return x[key]; }" 20797 "function keyed_load(x, key) { return x[key]; }"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
20586 CHECK(context->Global()->Get(v8_str("keyed_load_result"))->IsUndefined()); 20844 CHECK(context->Global()->Get(v8_str("keyed_load_result"))->IsUndefined());
20587 CHECK(context->Global()->Get(v8_str("keyed_load_result2"))->IsUndefined()); 20845 CHECK(context->Global()->Get(v8_str("keyed_load_result2"))->IsUndefined());
20588 CHECK(context->Global()->Get(v8_str("y_from_obj"))->IsUndefined()); 20846 CHECK(context->Global()->Get(v8_str("y_from_obj"))->IsUndefined());
20589 CHECK(context->Global()->Get(v8_str("y_from_subobj"))->IsUndefined()); 20847 CHECK(context->Global()->Get(v8_str("y_from_subobj"))->IsUndefined());
20590 } 20848 }
20591 20849
20592 20850
20593 THREADED_TEST(Regress142088) { 20851 THREADED_TEST(Regress142088) {
20594 i::FLAG_allow_natives_syntax = true; 20852 i::FLAG_allow_natives_syntax = true;
20595 LocalContext context; 20853 LocalContext context;
20596 v8::HandleScope scope(context->GetIsolate()); 20854 v8::Isolate* isolate = context->GetIsolate();
20597 Local<ObjectTemplate> templ = ObjectTemplate::New(); 20855 v8::HandleScope scope(isolate);
20856 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
20598 templ->SetAccessor(v8_str("foo"), 20857 templ->SetAccessor(v8_str("foo"),
20599 GetterWhichReturns42, 20858 GetterWhichReturns42,
20600 SetterWhichSetsYOnThisTo23); 20859 SetterWhichSetsYOnThisTo23);
20601 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 20860 context->Global()->Set(v8_str("obj"), templ->NewInstance());
20602 20861
20603 CompileRun("function load(x) { return x.foo; }" 20862 CompileRun("function load(x) { return x.foo; }"
20604 "var o = Object.create(obj);" 20863 "var o = Object.create(obj);"
20605 "%OptimizeObjectForAddingMultipleProperties(obj, 1);" 20864 "%OptimizeObjectForAddingMultipleProperties(obj, 1);"
20606 "load(o); load(o); load(o); load(o);"); 20865 "load(o); load(o); load(o); load(o);");
20607 } 20866 }
(...skipping 18 matching lines...) Expand all
20626 v8::HandleScope scope(context->GetIsolate()); 20885 v8::HandleScope scope(context->GetIsolate());
20627 Handle<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate()); 20886 Handle<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate());
20628 AddInterceptor(templ, EmptyInterceptorGetter, EmptyInterceptorSetter); 20887 AddInterceptor(templ, EmptyInterceptorGetter, EmptyInterceptorSetter);
20629 context->Global()->Set(v8_str("Bug"), templ->GetFunction()); 20888 context->Global()->Set(v8_str("Bug"), templ->GetFunction());
20630 CompileRun("Number.prototype.__proto__ = new Bug; var x = 0; x.foo();"); 20889 CompileRun("Number.prototype.__proto__ = new Bug; var x = 0; x.foo();");
20631 } 20890 }
20632 20891
20633 20892
20634 THREADED_TEST(Regress157124) { 20893 THREADED_TEST(Regress157124) {
20635 LocalContext context; 20894 LocalContext context;
20636 v8::HandleScope scope(context->GetIsolate()); 20895 v8::Isolate* isolate = context->GetIsolate();
20637 Local<ObjectTemplate> templ = ObjectTemplate::New(); 20896 v8::HandleScope scope(isolate);
20897 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
20638 Local<Object> obj = templ->NewInstance(); 20898 Local<Object> obj = templ->NewInstance();
20639 obj->GetIdentityHash(); 20899 obj->GetIdentityHash();
20640 obj->DeleteHiddenValue(v8_str("Bug")); 20900 obj->DeleteHiddenValue(v8_str("Bug"));
20641 } 20901 }
20642 20902
20643 20903
20644 THREADED_TEST(Regress2535) { 20904 THREADED_TEST(Regress2535) {
20645 i::FLAG_harmony_collections = true; 20905 i::FLAG_harmony_collections = true;
20646 LocalContext context; 20906 LocalContext context;
20647 v8::HandleScope scope(context->GetIsolate()); 20907 v8::HandleScope scope(context->GetIsolate());
20648 Local<Value> set_value = CompileRun("new Set();"); 20908 Local<Value> set_value = CompileRun("new Set();");
20649 Local<Object> set_object(Local<Object>::Cast(set_value)); 20909 Local<Object> set_object(Local<Object>::Cast(set_value));
20650 CHECK_EQ(0, set_object->InternalFieldCount()); 20910 CHECK_EQ(0, set_object->InternalFieldCount());
20651 Local<Value> map_value = CompileRun("new Map();"); 20911 Local<Value> map_value = CompileRun("new Map();");
20652 Local<Object> map_object(Local<Object>::Cast(map_value)); 20912 Local<Object> map_object(Local<Object>::Cast(map_value));
20653 CHECK_EQ(0, map_object->InternalFieldCount()); 20913 CHECK_EQ(0, map_object->InternalFieldCount());
20654 } 20914 }
20655 20915
20656 20916
20657 THREADED_TEST(Regress2746) { 20917 THREADED_TEST(Regress2746) {
20658 LocalContext context; 20918 LocalContext context;
20659 v8::Isolate* isolate = context->GetIsolate(); 20919 v8::Isolate* isolate = context->GetIsolate();
20660 v8::HandleScope scope(isolate); 20920 v8::HandleScope scope(isolate);
20661 Local<Object> obj = Object::New(); 20921 Local<Object> obj = Object::New(isolate);
20662 Local<String> key = String::NewFromUtf8(context->GetIsolate(), "key"); 20922 Local<String> key = String::NewFromUtf8(context->GetIsolate(), "key");
20663 obj->SetHiddenValue(key, v8::Undefined(isolate)); 20923 obj->SetHiddenValue(key, v8::Undefined(isolate));
20664 Local<Value> value = obj->GetHiddenValue(key); 20924 Local<Value> value = obj->GetHiddenValue(key);
20665 CHECK(!value.IsEmpty()); 20925 CHECK(!value.IsEmpty());
20666 CHECK(value->IsUndefined()); 20926 CHECK(value->IsUndefined());
20667 } 20927 }
20668 20928
20669 20929
20670 THREADED_TEST(Regress260106) { 20930 THREADED_TEST(Regress260106) {
20671 LocalContext context; 20931 LocalContext context;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
20782 } 21042 }
20783 21043
20784 21044
20785 void UnreachableCallback(const v8::FunctionCallbackInfo<v8::Value>& args) { 21045 void UnreachableCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
20786 CHECK(false); 21046 CHECK(false);
20787 } 21047 }
20788 21048
20789 21049
20790 TEST(JSONStringifyAccessCheck) { 21050 TEST(JSONStringifyAccessCheck) {
20791 v8::V8::Initialize(); 21051 v8::V8::Initialize();
20792 v8::HandleScope scope(CcTest::isolate()); 21052 v8::Isolate* isolate = CcTest::isolate();
21053 v8::HandleScope scope(isolate);
20793 21054
20794 // Create an ObjectTemplate for global objects and install access 21055 // Create an ObjectTemplate for global objects and install access
20795 // check callbacks that will block access. 21056 // check callbacks that will block access.
20796 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 21057 v8::Handle<v8::ObjectTemplate> global_template =
21058 v8::ObjectTemplate::New(isolate);
20797 global_template->SetAccessCheckCallbacks(NamedAccessAlwaysBlocked, 21059 global_template->SetAccessCheckCallbacks(NamedAccessAlwaysBlocked,
20798 IndexAccessAlwaysBlocked); 21060 IndexAccessAlwaysBlocked);
20799 21061
20800 // Create a context and set an x property on it's global object. 21062 // Create a context and set an x property on it's global object.
20801 LocalContext context0(NULL, global_template); 21063 LocalContext context0(NULL, global_template);
20802 v8::Handle<v8::Object> global0 = context0->Global(); 21064 v8::Handle<v8::Object> global0 = context0->Global();
20803 global0->Set(v8_str("x"), v8_num(42)); 21065 global0->Set(v8_str("x"), v8_num(42));
20804 ExpectString("JSON.stringify(this)", "{\"x\":42}"); 21066 ExpectString("JSON.stringify(this)", "{\"x\":42}");
20805 21067
20806 for (int i = 0; i < 2; i++) { 21068 for (int i = 0; i < 2; i++) {
20807 if (i == 1) { 21069 if (i == 1) {
20808 // Install a toJSON function on the second run. 21070 // Install a toJSON function on the second run.
20809 v8::Handle<v8::FunctionTemplate> toJSON = 21071 v8::Handle<v8::FunctionTemplate> toJSON =
20810 v8::FunctionTemplate::New(CcTest::isolate(), UnreachableCallback); 21072 v8::FunctionTemplate::New(isolate, UnreachableCallback);
20811 21073
20812 global0->Set(v8_str("toJSON"), toJSON->GetFunction()); 21074 global0->Set(v8_str("toJSON"), toJSON->GetFunction());
20813 } 21075 }
20814 // Create a context with a different security token so that the 21076 // Create a context with a different security token so that the
20815 // failed access check callback will be called on each access. 21077 // failed access check callback will be called on each access.
20816 LocalContext context1(NULL, global_template); 21078 LocalContext context1(NULL, global_template);
20817 context1->Global()->Set(v8_str("other"), global0); 21079 context1->Global()->Set(v8_str("other"), global0);
20818 21080
20819 ExpectString("JSON.stringify(other)", "{}"); 21081 ExpectString("JSON.stringify(other)", "{}");
20820 ExpectString("JSON.stringify({ 'a' : other, 'b' : ['c'] })", 21082 ExpectString("JSON.stringify({ 'a' : other, 'b' : ['c'] })",
20821 "{\"a\":{},\"b\":[\"c\"]}"); 21083 "{\"a\":{},\"b\":[\"c\"]}");
20822 ExpectString("JSON.stringify([other, 'b', 'c'])", 21084 ExpectString("JSON.stringify([other, 'b', 'c'])",
20823 "[{},\"b\",\"c\"]"); 21085 "[{},\"b\",\"c\"]");
20824 21086
20825 v8::Handle<v8::Array> array = v8::Array::New(CcTest::isolate(), 2); 21087 v8::Handle<v8::Array> array = v8::Array::New(isolate, 2);
20826 array->Set(0, v8_str("a")); 21088 array->Set(0, v8_str("a"));
20827 array->Set(1, v8_str("b")); 21089 array->Set(1, v8_str("b"));
20828 context1->Global()->Set(v8_str("array"), array); 21090 context1->Global()->Set(v8_str("array"), array);
20829 ExpectString("JSON.stringify(array)", "[\"a\",\"b\"]"); 21091 ExpectString("JSON.stringify(array)", "[\"a\",\"b\"]");
20830 array->TurnOnAccessCheck(); 21092 array->TurnOnAccessCheck();
20831 ExpectString("JSON.stringify(array)", "[]"); 21093 ExpectString("JSON.stringify(array)", "[]");
20832 ExpectString("JSON.stringify([array])", "[[]]"); 21094 ExpectString("JSON.stringify([array])", "[[]]");
20833 ExpectString("JSON.stringify({'a' : array})", "{\"a\":[]}"); 21095 ExpectString("JSON.stringify({'a' : array})", "{\"a\":[]}");
20834 } 21096 }
20835 } 21097 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
20880 CompileRun("try { [1, 2, 3].sort(); } catch (e) { catcher(e) };"); 21142 CompileRun("try { [1, 2, 3].sort(); } catch (e) { catcher(e) };");
20881 CHECK(!access_check_fail_thrown); 21143 CHECK(!access_check_fail_thrown);
20882 CHECK(!catch_callback_called); 21144 CHECK(!catch_callback_called);
20883 } 21145 }
20884 21146
20885 21147
20886 TEST(AccessCheckThrows) { 21148 TEST(AccessCheckThrows) {
20887 i::FLAG_allow_natives_syntax = true; 21149 i::FLAG_allow_natives_syntax = true;
20888 v8::V8::Initialize(); 21150 v8::V8::Initialize();
20889 v8::V8::SetFailedAccessCheckCallbackFunction(&FailedAccessCheckThrows); 21151 v8::V8::SetFailedAccessCheckCallbackFunction(&FailedAccessCheckThrows);
20890 v8::HandleScope scope(CcTest::isolate()); 21152 v8::Isolate* isolate = CcTest::isolate();
21153 v8::HandleScope scope(isolate);
20891 21154
20892 // Create an ObjectTemplate for global objects and install access 21155 // Create an ObjectTemplate for global objects and install access
20893 // check callbacks that will block access. 21156 // check callbacks that will block access.
20894 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 21157 v8::Handle<v8::ObjectTemplate> global_template =
21158 v8::ObjectTemplate::New(isolate);
20895 global_template->SetAccessCheckCallbacks(NamedAccessAlwaysBlocked, 21159 global_template->SetAccessCheckCallbacks(NamedAccessAlwaysBlocked,
20896 IndexAccessAlwaysBlocked); 21160 IndexAccessAlwaysBlocked);
20897 21161
20898 // Create a context and set an x property on it's global object. 21162 // Create a context and set an x property on it's global object.
20899 LocalContext context0(NULL, global_template); 21163 LocalContext context0(NULL, global_template);
20900 context0->Global()->Set(v8_str("x"), v8_num(42)); 21164 context0->Global()->Set(v8_str("x"), v8_num(42));
20901 v8::Handle<v8::Object> global0 = context0->Global(); 21165 v8::Handle<v8::Object> global0 = context0->Global();
20902 21166
20903 // Create a context with a different security token so that the 21167 // Create a context with a different security token so that the
20904 // failed access check callback will be called on each access. 21168 // failed access check callback will be called on each access.
20905 LocalContext context1(NULL, global_template); 21169 LocalContext context1(NULL, global_template);
20906 context1->Global()->Set(v8_str("other"), global0); 21170 context1->Global()->Set(v8_str("other"), global0);
20907 21171
20908 v8::Handle<v8::FunctionTemplate> catcher_fun = 21172 v8::Handle<v8::FunctionTemplate> catcher_fun =
20909 v8::FunctionTemplate::New(CcTest::isolate(), CatcherCallback); 21173 v8::FunctionTemplate::New(isolate, CatcherCallback);
20910 context1->Global()->Set(v8_str("catcher"), catcher_fun->GetFunction()); 21174 context1->Global()->Set(v8_str("catcher"), catcher_fun->GetFunction());
20911 21175
20912 v8::Handle<v8::FunctionTemplate> has_own_property_fun = 21176 v8::Handle<v8::FunctionTemplate> has_own_property_fun =
20913 v8::FunctionTemplate::New(CcTest::isolate(), HasOwnPropertyCallback); 21177 v8::FunctionTemplate::New(isolate, HasOwnPropertyCallback);
20914 context1->Global()->Set(v8_str("has_own_property"), 21178 context1->Global()->Set(v8_str("has_own_property"),
20915 has_own_property_fun->GetFunction()); 21179 has_own_property_fun->GetFunction());
20916 21180
20917 { v8::TryCatch try_catch; 21181 { v8::TryCatch try_catch;
20918 access_check_fail_thrown = false; 21182 access_check_fail_thrown = false;
20919 CompileRun("other.x;"); 21183 CompileRun("other.x;");
20920 CHECK(access_check_fail_thrown); 21184 CHECK(access_check_fail_thrown);
20921 CHECK(try_catch.HasCaught()); 21185 CHECK(try_catch.HasCaught());
20922 } 21186 }
20923 21187
20924 CheckCorrectThrow("other.x"); 21188 CheckCorrectThrow("other.x");
20925 CheckCorrectThrow("other[1]"); 21189 CheckCorrectThrow("other[1]");
20926 CheckCorrectThrow("JSON.stringify(other)"); 21190 CheckCorrectThrow("JSON.stringify(other)");
20927 CheckCorrectThrow("has_own_property(other, 'x')"); 21191 CheckCorrectThrow("has_own_property(other, 'x')");
20928 CheckCorrectThrow("%GetProperty(other, 'x')"); 21192 CheckCorrectThrow("%GetProperty(other, 'x')");
20929 CheckCorrectThrow("%SetProperty(other, 'x', 'foo', 1, 0)"); 21193 CheckCorrectThrow("%SetProperty(other, 'x', 'foo', 1, 0)");
20930 CheckCorrectThrow("%IgnoreAttributesAndSetProperty(other, 'x', 'foo')"); 21194 CheckCorrectThrow("%IgnoreAttributesAndSetProperty(other, 'x', 'foo')");
20931 CheckCorrectThrow("%DeleteProperty(other, 'x', 0)"); 21195 CheckCorrectThrow("%DeleteProperty(other, 'x', 0)");
20932 CheckCorrectThrow("%DeleteProperty(other, '1', 0)"); 21196 CheckCorrectThrow("%DeleteProperty(other, '1', 0)");
20933 CheckCorrectThrow("%HasLocalProperty(other, 'x')"); 21197 CheckCorrectThrow("%HasLocalProperty(other, 'x')");
20934 CheckCorrectThrow("%HasProperty(other, 'x')"); 21198 CheckCorrectThrow("%HasProperty(other, 'x')");
20935 CheckCorrectThrow("%HasElement(other, 1)"); 21199 CheckCorrectThrow("%HasElement(other, 1)");
20936 CheckCorrectThrow("%IsPropertyEnumerable(other, 'x')"); 21200 CheckCorrectThrow("%IsPropertyEnumerable(other, 'x')");
20937 CheckCorrectThrow("%GetPropertyNames(other)"); 21201 CheckCorrectThrow("%GetPropertyNames(other)");
20938 CheckCorrectThrow("%GetLocalPropertyNames(other, true)"); 21202 // PROPERTY_ATTRIBUTES_NONE = 0
21203 CheckCorrectThrow("%GetLocalPropertyNames(other, 0)");
20939 CheckCorrectThrow("%DefineOrRedefineAccessorProperty(" 21204 CheckCorrectThrow("%DefineOrRedefineAccessorProperty("
20940 "other, 'x', null, null, 1)"); 21205 "other, 'x', null, null, 1)");
20941 21206
20942 // Reset the failed access check callback so it does not influence 21207 // Reset the failed access check callback so it does not influence
20943 // the other tests. 21208 // the other tests.
20944 v8::V8::SetFailedAccessCheckCallbackFunction(NULL); 21209 v8::V8::SetFailedAccessCheckCallbackFunction(NULL);
20945 } 21210 }
20946 21211
20947 21212
20948 THREADED_TEST(Regress256330) { 21213 THREADED_TEST(Regress256330) {
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
21309 static void FunctionNewCallback(const v8::FunctionCallbackInfo<Value>& info) { 21574 static void FunctionNewCallback(const v8::FunctionCallbackInfo<Value>& info) {
21310 CHECK_EQ(function_new_expected_env, info.Data()); 21575 CHECK_EQ(function_new_expected_env, info.Data());
21311 info.GetReturnValue().Set(17); 21576 info.GetReturnValue().Set(17);
21312 } 21577 }
21313 21578
21314 21579
21315 THREADED_TEST(FunctionNew) { 21580 THREADED_TEST(FunctionNew) {
21316 LocalContext env; 21581 LocalContext env;
21317 v8::Isolate* isolate = env->GetIsolate(); 21582 v8::Isolate* isolate = env->GetIsolate();
21318 v8::HandleScope scope(isolate); 21583 v8::HandleScope scope(isolate);
21319 Local<Object> data = v8::Object::New(); 21584 Local<Object> data = v8::Object::New(isolate);
21320 function_new_expected_env = data; 21585 function_new_expected_env = data;
21321 Local<Function> func = Function::New(isolate, FunctionNewCallback, data); 21586 Local<Function> func = Function::New(isolate, FunctionNewCallback, data);
21322 env->Global()->Set(v8_str("func"), func); 21587 env->Global()->Set(v8_str("func"), func);
21323 Local<Value> result = CompileRun("func();"); 21588 Local<Value> result = CompileRun("func();");
21324 CHECK_EQ(v8::Integer::New(17, isolate), result); 21589 CHECK_EQ(v8::Integer::New(isolate, 17), result);
21325 // Verify function not cached 21590 // Verify function not cached
21326 int serial_number = 21591 int serial_number =
21327 i::Smi::cast(v8::Utils::OpenHandle(*func) 21592 i::Smi::cast(v8::Utils::OpenHandle(*func)
21328 ->shared()->get_api_func_data()->serial_number())->value(); 21593 ->shared()->get_api_func_data()->serial_number())->value();
21329 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 21594 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
21330 i::Object* elm = i_isolate->native_context()->function_cache() 21595 i::Object* elm = i_isolate->native_context()->function_cache()
21331 ->GetElementNoExceptionThrown(i_isolate, serial_number); 21596 ->GetElementNoExceptionThrown(i_isolate, serial_number);
21332 CHECK(elm->IsUndefined()); 21597 CHECK(elm->IsUndefined());
21333 // Verify that each Function::New creates a new function instance 21598 // Verify that each Function::New creates a new function instance
21334 Local<Object> data2 = v8::Object::New(); 21599 Local<Object> data2 = v8::Object::New(isolate);
21335 function_new_expected_env = data2; 21600 function_new_expected_env = data2;
21336 Local<Function> func2 = Function::New(isolate, FunctionNewCallback, data2); 21601 Local<Function> func2 = Function::New(isolate, FunctionNewCallback, data2);
21337 CHECK(!func2->IsNull()); 21602 CHECK(!func2->IsNull());
21338 CHECK_NE(func, func2); 21603 CHECK_NE(func, func2);
21339 env->Global()->Set(v8_str("func2"), func2); 21604 env->Global()->Set(v8_str("func2"), func2);
21340 Local<Value> result2 = CompileRun("func2();"); 21605 Local<Value> result2 = CompileRun("func2();");
21341 CHECK_EQ(v8::Integer::New(17, isolate), result2); 21606 CHECK_EQ(v8::Integer::New(isolate, 17), result2);
21342 } 21607 }
21343 21608
21344 21609
21345 TEST(EscapeableHandleScope) { 21610 TEST(EscapeableHandleScope) {
21346 HandleScope outer_scope(CcTest::isolate()); 21611 HandleScope outer_scope(CcTest::isolate());
21347 LocalContext context; 21612 LocalContext context;
21348 const int runs = 10; 21613 const int runs = 10;
21349 Local<String> values[runs]; 21614 Local<String> values[runs];
21350 for (int i = 0; i < runs; i++) { 21615 for (int i = 0; i < runs; i++) {
21351 v8::EscapableHandleScope inner_scope(CcTest::isolate()); 21616 v8::EscapableHandleScope inner_scope(CcTest::isolate());
21352 Local<String> value; 21617 Local<String> value;
21353 if (i != 0) value = v8_str("escape value"); 21618 if (i != 0) value = v8_str("escape value");
21354 values[i] = inner_scope.Escape(value); 21619 values[i] = inner_scope.Escape(value);
21355 } 21620 }
21356 for (int i = 0; i < runs; i++) { 21621 for (int i = 0; i < runs; i++) {
21357 Local<String> expected; 21622 Local<String> expected;
21358 if (i != 0) { 21623 if (i != 0) {
21359 CHECK_EQ(v8_str("escape value"), values[i]); 21624 CHECK_EQ(v8_str("escape value"), values[i]);
21360 } else { 21625 } else {
21361 CHECK(values[i].IsEmpty()); 21626 CHECK(values[i].IsEmpty());
21362 } 21627 }
21363 } 21628 }
21364 } 21629 }
OLDNEW
« no previous file with comments | « test/cctest/test-accessors.cc ('k') | test/cctest/test-assembler-arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698