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

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

Issue 119323006: Revert r18449 "Reland r18383: More API cleanup." and r18450 "Unbreak build." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 11 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-ia32.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(args.GetIsolate(), i), args[i]); 156 result->Set(v8::Integer::New(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(args.GetIsolate(), i), args[i]); 167 result->Set(v8::Integer::New(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(isolate); 414 Local<v8::Object> obj = v8::Object::New();
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(env->GetIsolate()); 429 Local<v8::Object> obj = v8::Object::New();
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 752 matching lines...) Expand 10 before | Expand all | Expand 10 after
1192 case kEmptyStringReturnValue: 1192 case kEmptyStringReturnValue:
1193 info.GetReturnValue().SetEmptyString(); 1193 info.GetReturnValue().SetEmptyString();
1194 break; 1194 break;
1195 } 1195 }
1196 } 1196 }
1197 1197
1198 template<> 1198 template<>
1199 void FastReturnValueCallback<Object>( 1199 void FastReturnValueCallback<Object>(
1200 const v8::FunctionCallbackInfo<v8::Value>& info) { 1200 const v8::FunctionCallbackInfo<v8::Value>& info) {
1201 v8::Handle<v8::Object> object; 1201 v8::Handle<v8::Object> object;
1202 if (!fast_return_value_object_is_empty) { 1202 if (!fast_return_value_object_is_empty) object = Object::New();
1203 object = Object::New(info.GetIsolate());
1204 }
1205 info.GetReturnValue().Set(object); 1203 info.GetReturnValue().Set(object);
1206 } 1204 }
1207 1205
1208 template<typename T> 1206 template<typename T>
1209 Handle<Value> TestFastReturnValues() { 1207 Handle<Value> TestFastReturnValues() {
1210 LocalContext env; 1208 LocalContext env;
1211 v8::EscapableHandleScope scope(env->GetIsolate()); 1209 v8::EscapableHandleScope scope(env->GetIsolate());
1212 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); 1210 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New();
1213 v8::FunctionCallback callback = &FastReturnValueCallback<T>; 1211 v8::FunctionCallback callback = &FastReturnValueCallback<T>;
1214 object_template->Set(env->GetIsolate(), "callback", 1212 object_template->Set(env->GetIsolate(), "callback",
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1332 1330
1333 1331
1334 static void TestExternalPointerWrapping() { 1332 static void TestExternalPointerWrapping() {
1335 LocalContext env; 1333 LocalContext env;
1336 v8::Isolate* isolate = env->GetIsolate(); 1334 v8::Isolate* isolate = env->GetIsolate();
1337 v8::HandleScope scope(isolate); 1335 v8::HandleScope scope(isolate);
1338 1336
1339 v8::Handle<v8::Value> data = 1337 v8::Handle<v8::Value> data =
1340 v8::External::New(isolate, expected_ptr); 1338 v8::External::New(isolate, expected_ptr);
1341 1339
1342 v8::Handle<v8::Object> obj = v8::Object::New(isolate); 1340 v8::Handle<v8::Object> obj = v8::Object::New();
1343 obj->Set(v8_str("func"), 1341 obj->Set(v8_str("func"),
1344 v8::FunctionTemplate::New(isolate, callback, data)->GetFunction()); 1342 v8::FunctionTemplate::New(isolate, callback, data)->GetFunction());
1345 env->Global()->Set(v8_str("obj"), obj); 1343 env->Global()->Set(v8_str("obj"), obj);
1346 1344
1347 CHECK(CompileRun( 1345 CHECK(CompileRun(
1348 "function foo() {\n" 1346 "function foo() {\n"
1349 " for (var i = 0; i < 13; i++) obj.func();\n" 1347 " for (var i = 0; i < 13; i++) obj.func();\n"
1350 "}\n" 1348 "}\n"
1351 "foo(), true")->BooleanValue()); 1349 "foo(), true")->BooleanValue());
1352 } 1350 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1441 other_instance->FindInstanceInPrototypeChain(base)); 1439 other_instance->FindInstanceInPrototypeChain(base));
1442 CHECK_EQ(derived_instance2, 1440 CHECK_EQ(derived_instance2,
1443 other_instance->FindInstanceInPrototypeChain(derived)); 1441 other_instance->FindInstanceInPrototypeChain(derived));
1444 CHECK_EQ(other_instance, 1442 CHECK_EQ(other_instance,
1445 other_instance->FindInstanceInPrototypeChain(other)); 1443 other_instance->FindInstanceInPrototypeChain(other));
1446 } 1444 }
1447 1445
1448 1446
1449 THREADED_TEST(TinyInteger) { 1447 THREADED_TEST(TinyInteger) {
1450 LocalContext env; 1448 LocalContext env;
1451 v8::Isolate* isolate = env->GetIsolate(); 1449 v8::HandleScope scope(env->GetIsolate());
1452 v8::HandleScope scope(isolate); 1450 v8::Isolate* isolate = CcTest::isolate();
1453 1451
1454 int32_t value = 239; 1452 int32_t value = 239;
1455 Local<v8::Integer> value_obj = v8::Integer::New(isolate, value); 1453 Local<v8::Integer> value_obj = v8::Integer::New(value);
1456 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1454 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1457 1455
1458 value_obj = v8::Integer::New(isolate, value); 1456 value_obj = v8::Integer::New(value, isolate);
1459 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1457 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1460 } 1458 }
1461 1459
1462 1460
1463 THREADED_TEST(BigSmiInteger) { 1461 THREADED_TEST(BigSmiInteger) {
1464 LocalContext env; 1462 LocalContext env;
1465 v8::HandleScope scope(env->GetIsolate()); 1463 v8::HandleScope scope(env->GetIsolate());
1466 v8::Isolate* isolate = CcTest::isolate(); 1464 v8::Isolate* isolate = CcTest::isolate();
1467 1465
1468 int32_t value = i::Smi::kMaxValue; 1466 int32_t value = i::Smi::kMaxValue;
1469 // We cannot add one to a Smi::kMaxValue without wrapping. 1467 // We cannot add one to a Smi::kMaxValue without wrapping.
1470 if (i::SmiValuesAre31Bits()) { 1468 if (i::SmiValuesAre31Bits()) {
1471 CHECK(i::Smi::IsValid(value)); 1469 CHECK(i::Smi::IsValid(value));
1472 CHECK(!i::Smi::IsValid(value + 1)); 1470 CHECK(!i::Smi::IsValid(value + 1));
1473 1471
1474 Local<v8::Integer> value_obj = v8::Integer::New(isolate, value); 1472 Local<v8::Integer> value_obj = v8::Integer::New(value);
1475 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1473 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1476 1474
1477 value_obj = v8::Integer::New(isolate, value); 1475 value_obj = v8::Integer::New(value, isolate);
1478 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1476 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1479 } 1477 }
1480 } 1478 }
1481 1479
1482 1480
1483 THREADED_TEST(BigInteger) { 1481 THREADED_TEST(BigInteger) {
1484 LocalContext env; 1482 LocalContext env;
1485 v8::HandleScope scope(env->GetIsolate()); 1483 v8::HandleScope scope(env->GetIsolate());
1486 v8::Isolate* isolate = CcTest::isolate(); 1484 v8::Isolate* isolate = CcTest::isolate();
1487 1485
1488 // We cannot add one to a Smi::kMaxValue without wrapping. 1486 // We cannot add one to a Smi::kMaxValue without wrapping.
1489 if (i::SmiValuesAre31Bits()) { 1487 if (i::SmiValuesAre31Bits()) {
1490 // The casts allow this to compile, even if Smi::kMaxValue is 2^31-1. 1488 // The casts allow this to compile, even if Smi::kMaxValue is 2^31-1.
1491 // The code will not be run in that case, due to the "if" guard. 1489 // The code will not be run in that case, due to the "if" guard.
1492 int32_t value = 1490 int32_t value =
1493 static_cast<int32_t>(static_cast<uint32_t>(i::Smi::kMaxValue) + 1); 1491 static_cast<int32_t>(static_cast<uint32_t>(i::Smi::kMaxValue) + 1);
1494 CHECK(value > i::Smi::kMaxValue); 1492 CHECK(value > i::Smi::kMaxValue);
1495 CHECK(!i::Smi::IsValid(value)); 1493 CHECK(!i::Smi::IsValid(value));
1496 1494
1497 Local<v8::Integer> value_obj = v8::Integer::New(isolate, value); 1495 Local<v8::Integer> value_obj = v8::Integer::New(value);
1498 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1496 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1499 1497
1500 value_obj = v8::Integer::New(isolate, value); 1498 value_obj = v8::Integer::New(value, isolate);
1501 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1499 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1502 } 1500 }
1503 } 1501 }
1504 1502
1505 1503
1506 THREADED_TEST(TinyUnsignedInteger) { 1504 THREADED_TEST(TinyUnsignedInteger) {
1507 LocalContext env; 1505 LocalContext env;
1508 v8::HandleScope scope(env->GetIsolate()); 1506 v8::HandleScope scope(env->GetIsolate());
1509 v8::Isolate* isolate = CcTest::isolate(); 1507 v8::Isolate* isolate = CcTest::isolate();
1510 1508
1511 uint32_t value = 239; 1509 uint32_t value = 239;
1512 1510
1513 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(isolate, value); 1511 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(value);
1514 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1512 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1515 1513
1516 value_obj = v8::Integer::NewFromUnsigned(isolate, value); 1514 value_obj = v8::Integer::NewFromUnsigned(value, isolate);
1517 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1515 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1518 } 1516 }
1519 1517
1520 1518
1521 THREADED_TEST(BigUnsignedSmiInteger) { 1519 THREADED_TEST(BigUnsignedSmiInteger) {
1522 LocalContext env; 1520 LocalContext env;
1523 v8::HandleScope scope(env->GetIsolate()); 1521 v8::HandleScope scope(env->GetIsolate());
1524 v8::Isolate* isolate = CcTest::isolate(); 1522 v8::Isolate* isolate = CcTest::isolate();
1525 1523
1526 uint32_t value = static_cast<uint32_t>(i::Smi::kMaxValue); 1524 uint32_t value = static_cast<uint32_t>(i::Smi::kMaxValue);
1527 CHECK(i::Smi::IsValid(value)); 1525 CHECK(i::Smi::IsValid(value));
1528 CHECK(!i::Smi::IsValid(value + 1)); 1526 CHECK(!i::Smi::IsValid(value + 1));
1529 1527
1530 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(isolate, value); 1528 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(value);
1531 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1529 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1532 1530
1533 value_obj = v8::Integer::NewFromUnsigned(isolate, value); 1531 value_obj = v8::Integer::NewFromUnsigned(value, isolate);
1534 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1532 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1535 } 1533 }
1536 1534
1537 1535
1538 THREADED_TEST(BigUnsignedInteger) { 1536 THREADED_TEST(BigUnsignedInteger) {
1539 LocalContext env; 1537 LocalContext env;
1540 v8::HandleScope scope(env->GetIsolate()); 1538 v8::HandleScope scope(env->GetIsolate());
1541 v8::Isolate* isolate = CcTest::isolate(); 1539 v8::Isolate* isolate = CcTest::isolate();
1542 1540
1543 uint32_t value = static_cast<uint32_t>(i::Smi::kMaxValue) + 1; 1541 uint32_t value = static_cast<uint32_t>(i::Smi::kMaxValue) + 1;
1544 CHECK(value > static_cast<uint32_t>(i::Smi::kMaxValue)); 1542 CHECK(value > static_cast<uint32_t>(i::Smi::kMaxValue));
1545 CHECK(!i::Smi::IsValid(value)); 1543 CHECK(!i::Smi::IsValid(value));
1546 1544
1547 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(isolate, value); 1545 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(value);
1548 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1546 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1549 1547
1550 value_obj = v8::Integer::NewFromUnsigned(isolate, value); 1548 value_obj = v8::Integer::NewFromUnsigned(value, isolate);
1551 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1549 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1552 } 1550 }
1553 1551
1554 1552
1555 THREADED_TEST(OutOfSignedRangeUnsignedInteger) { 1553 THREADED_TEST(OutOfSignedRangeUnsignedInteger) {
1556 LocalContext env; 1554 LocalContext env;
1557 v8::HandleScope scope(env->GetIsolate()); 1555 v8::HandleScope scope(env->GetIsolate());
1558 v8::Isolate* isolate = CcTest::isolate(); 1556 v8::Isolate* isolate = CcTest::isolate();
1559 1557
1560 uint32_t INT32_MAX_AS_UINT = (1U << 31) - 1; 1558 uint32_t INT32_MAX_AS_UINT = (1U << 31) - 1;
1561 uint32_t value = INT32_MAX_AS_UINT + 1; 1559 uint32_t value = INT32_MAX_AS_UINT + 1;
1562 CHECK(value > INT32_MAX_AS_UINT); // No overflow. 1560 CHECK(value > INT32_MAX_AS_UINT); // No overflow.
1563 1561
1564 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(isolate, value); 1562 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(value);
1565 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1563 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1566 1564
1567 value_obj = v8::Integer::NewFromUnsigned(isolate, value); 1565 value_obj = v8::Integer::NewFromUnsigned(value, isolate);
1568 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1566 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1569 } 1567 }
1570 1568
1571 1569
1572 THREADED_TEST(IsNativeError) { 1570 THREADED_TEST(IsNativeError) {
1573 LocalContext env; 1571 LocalContext env;
1574 v8::HandleScope scope(env->GetIsolate()); 1572 v8::HandleScope scope(env->GetIsolate());
1575 v8::Handle<Value> syntax_error = CompileRun( 1573 v8::Handle<Value> syntax_error = CompileRun(
1576 "var out = 0; try { eval(\"#\"); } catch(x) { out = x; } out; "); 1574 "var out = 0; try { eval(\"#\"); } catch(x) { out = x; } out; ");
1577 CHECK(syntax_error->IsNativeError()); 1575 CHECK(syntax_error->IsNativeError());
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1703 CHECK(true_boolean_object->ValueOf()); 1701 CHECK(true_boolean_object->ValueOf());
1704 CHECK(!true_boolean_object->IsTrue()); 1702 CHECK(!true_boolean_object->IsTrue());
1705 CHECK(!true_boolean_object->IsFalse()); 1703 CHECK(!true_boolean_object->IsFalse());
1706 } 1704 }
1707 1705
1708 1706
1709 THREADED_TEST(Number) { 1707 THREADED_TEST(Number) {
1710 LocalContext env; 1708 LocalContext env;
1711 v8::HandleScope scope(env->GetIsolate()); 1709 v8::HandleScope scope(env->GetIsolate());
1712 double PI = 3.1415926; 1710 double PI = 3.1415926;
1713 Local<v8::Number> pi_obj = v8::Number::New(env->GetIsolate(), PI); 1711 Local<v8::Number> pi_obj = v8::Number::New(PI);
1714 CHECK_EQ(PI, pi_obj->NumberValue()); 1712 CHECK_EQ(PI, pi_obj->NumberValue());
1715 } 1713 }
1716 1714
1717 1715
1718 THREADED_TEST(ToNumber) { 1716 THREADED_TEST(ToNumber) {
1719 LocalContext env; 1717 LocalContext env;
1720 v8::Isolate* isolate = CcTest::isolate(); 1718 v8::Isolate* isolate = CcTest::isolate();
1721 v8::HandleScope scope(isolate); 1719 v8::HandleScope scope(isolate);
1722 Local<String> str = v8_str("3.1415926"); 1720 Local<String> str = v8_str("3.1415926");
1723 CHECK_EQ(3.1415926, str->NumberValue()); 1721 CHECK_EQ(3.1415926, str->NumberValue());
1724 v8::Handle<v8::Boolean> t = v8::True(isolate); 1722 v8::Handle<v8::Boolean> t = v8::True(isolate);
1725 CHECK_EQ(1.0, t->NumberValue()); 1723 CHECK_EQ(1.0, t->NumberValue());
1726 v8::Handle<v8::Boolean> f = v8::False(isolate); 1724 v8::Handle<v8::Boolean> f = v8::False(isolate);
1727 CHECK_EQ(0.0, f->NumberValue()); 1725 CHECK_EQ(0.0, f->NumberValue());
1728 } 1726 }
1729 1727
1730 1728
1731 THREADED_TEST(Date) { 1729 THREADED_TEST(Date) {
1732 LocalContext env; 1730 LocalContext env;
1733 v8::HandleScope scope(env->GetIsolate()); 1731 v8::HandleScope scope(env->GetIsolate());
1734 double PI = 3.1415926; 1732 double PI = 3.1415926;
1735 Local<Value> date = v8::Date::New(env->GetIsolate(), PI); 1733 Local<Value> date = v8::Date::New(env->GetIsolate(), PI);
1736 CHECK_EQ(3.0, date->NumberValue()); 1734 CHECK_EQ(3.0, date->NumberValue());
1737 date.As<v8::Date>()->Set(v8_str("property"), 1735 date.As<v8::Date>()->Set(v8_str("property"), v8::Integer::New(42));
1738 v8::Integer::New(env->GetIsolate(), 42));
1739 CHECK_EQ(42, date.As<v8::Date>()->Get(v8_str("property"))->Int32Value()); 1736 CHECK_EQ(42, date.As<v8::Date>()->Get(v8_str("property"))->Int32Value());
1740 } 1737 }
1741 1738
1742 1739
1743 THREADED_TEST(Boolean) { 1740 THREADED_TEST(Boolean) {
1744 LocalContext env; 1741 LocalContext env;
1745 v8::Isolate* isolate = env->GetIsolate(); 1742 v8::HandleScope scope(env->GetIsolate());
1746 v8::HandleScope scope(isolate); 1743 v8::Handle<v8::Boolean> t = v8::True(CcTest::isolate());
1747 v8::Handle<v8::Boolean> t = v8::True(isolate);
1748 CHECK(t->Value()); 1744 CHECK(t->Value());
1749 v8::Handle<v8::Boolean> f = v8::False(isolate); 1745 v8::Handle<v8::Boolean> f = v8::False(CcTest::isolate());
1750 CHECK(!f->Value()); 1746 CHECK(!f->Value());
1751 v8::Handle<v8::Primitive> u = v8::Undefined(isolate); 1747 v8::Handle<v8::Primitive> u = v8::Undefined(CcTest::isolate());
1752 CHECK(!u->BooleanValue()); 1748 CHECK(!u->BooleanValue());
1753 v8::Handle<v8::Primitive> n = v8::Null(isolate); 1749 v8::Handle<v8::Primitive> n = v8::Null(CcTest::isolate());
1754 CHECK(!n->BooleanValue()); 1750 CHECK(!n->BooleanValue());
1755 v8::Handle<String> str1 = v8_str(""); 1751 v8::Handle<String> str1 = v8_str("");
1756 CHECK(!str1->BooleanValue()); 1752 CHECK(!str1->BooleanValue());
1757 v8::Handle<String> str2 = v8_str("x"); 1753 v8::Handle<String> str2 = v8_str("x");
1758 CHECK(str2->BooleanValue()); 1754 CHECK(str2->BooleanValue());
1759 CHECK(!v8::Number::New(isolate, 0)->BooleanValue()); 1755 CHECK(!v8::Number::New(0)->BooleanValue());
1760 CHECK(v8::Number::New(isolate, -1)->BooleanValue()); 1756 CHECK(v8::Number::New(-1)->BooleanValue());
1761 CHECK(v8::Number::New(isolate, 1)->BooleanValue()); 1757 CHECK(v8::Number::New(1)->BooleanValue());
1762 CHECK(v8::Number::New(isolate, 42)->BooleanValue()); 1758 CHECK(v8::Number::New(42)->BooleanValue());
1763 CHECK(!v8_compile("NaN")->Run()->BooleanValue()); 1759 CHECK(!v8_compile("NaN")->Run()->BooleanValue());
1764 } 1760 }
1765 1761
1766 1762
1767 static void DummyCallHandler(const v8::FunctionCallbackInfo<v8::Value>& args) { 1763 static void DummyCallHandler(const v8::FunctionCallbackInfo<v8::Value>& args) {
1768 ApiTestFuzzer::Fuzz(); 1764 ApiTestFuzzer::Fuzz();
1769 args.GetReturnValue().Set(v8_num(13.4)); 1765 args.GetReturnValue().Set(v8_num(13.4));
1770 } 1766 }
1771 1767
1772 1768
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after
2441 2437
2442 v8::Handle<Script> call_recursively_script; 2438 v8::Handle<Script> call_recursively_script;
2443 static const int kTargetRecursionDepth = 200; // near maximum 2439 static const int kTargetRecursionDepth = 200; // near maximum
2444 2440
2445 2441
2446 static void CallScriptRecursivelyCall( 2442 static void CallScriptRecursivelyCall(
2447 const v8::FunctionCallbackInfo<v8::Value>& args) { 2443 const v8::FunctionCallbackInfo<v8::Value>& args) {
2448 ApiTestFuzzer::Fuzz(); 2444 ApiTestFuzzer::Fuzz();
2449 int depth = args.This()->Get(v8_str("depth"))->Int32Value(); 2445 int depth = args.This()->Get(v8_str("depth"))->Int32Value();
2450 if (depth == kTargetRecursionDepth) return; 2446 if (depth == kTargetRecursionDepth) return;
2451 args.This()->Set(v8_str("depth"), 2447 args.This()->Set(v8_str("depth"), v8::Integer::New(depth + 1));
2452 v8::Integer::New(args.GetIsolate(), depth + 1));
2453 args.GetReturnValue().Set(call_recursively_script->Run()); 2448 args.GetReturnValue().Set(call_recursively_script->Run());
2454 } 2449 }
2455 2450
2456 2451
2457 static void CallFunctionRecursivelyCall( 2452 static void CallFunctionRecursivelyCall(
2458 const v8::FunctionCallbackInfo<v8::Value>& args) { 2453 const v8::FunctionCallbackInfo<v8::Value>& args) {
2459 ApiTestFuzzer::Fuzz(); 2454 ApiTestFuzzer::Fuzz();
2460 int depth = args.This()->Get(v8_str("depth"))->Int32Value(); 2455 int depth = args.This()->Get(v8_str("depth"))->Int32Value();
2461 if (depth == kTargetRecursionDepth) { 2456 if (depth == kTargetRecursionDepth) {
2462 printf("[depth = %d]\n", depth); 2457 printf("[depth = %d]\n", depth);
2463 return; 2458 return;
2464 } 2459 }
2465 args.This()->Set(v8_str("depth"), 2460 args.This()->Set(v8_str("depth"), v8::Integer::New(depth + 1));
2466 v8::Integer::New(args.GetIsolate(), depth + 1));
2467 v8::Handle<Value> function = 2461 v8::Handle<Value> function =
2468 args.This()->Get(v8_str("callFunctionRecursively")); 2462 args.This()->Get(v8_str("callFunctionRecursively"));
2469 args.GetReturnValue().Set( 2463 args.GetReturnValue().Set(
2470 function.As<Function>()->Call(args.This(), 0, NULL)); 2464 function.As<Function>()->Call(args.This(), 0, NULL));
2471 } 2465 }
2472 2466
2473 2467
2474 THREADED_TEST(DeepCrossLanguageRecursion) { 2468 THREADED_TEST(DeepCrossLanguageRecursion) {
2475 v8::Isolate* isolate = CcTest::isolate(); 2469 v8::Isolate* isolate = CcTest::isolate();
2476 v8::HandleScope scope(isolate); 2470 v8::HandleScope scope(isolate);
2477 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(); 2471 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New();
2478 global->Set(v8_str("callScriptRecursively"), 2472 global->Set(v8_str("callScriptRecursively"),
2479 v8::FunctionTemplate::New(isolate, CallScriptRecursivelyCall)); 2473 v8::FunctionTemplate::New(isolate, CallScriptRecursivelyCall));
2480 global->Set(v8_str("callFunctionRecursively"), 2474 global->Set(v8_str("callFunctionRecursively"),
2481 v8::FunctionTemplate::New(isolate, CallFunctionRecursivelyCall)); 2475 v8::FunctionTemplate::New(isolate, CallFunctionRecursivelyCall));
2482 LocalContext env(NULL, global); 2476 LocalContext env(NULL, global);
2483 2477
2484 env->Global()->Set(v8_str("depth"), v8::Integer::New(isolate, 0)); 2478 env->Global()->Set(v8_str("depth"), v8::Integer::New(0));
2485 call_recursively_script = v8_compile("callScriptRecursively()"); 2479 call_recursively_script = v8_compile("callScriptRecursively()");
2486 call_recursively_script->Run(); 2480 call_recursively_script->Run();
2487 call_recursively_script = v8::Handle<Script>(); 2481 call_recursively_script = v8::Handle<Script>();
2488 2482
2489 env->Global()->Set(v8_str("depth"), v8::Integer::New(isolate, 0)); 2483 env->Global()->Set(v8_str("depth"), v8::Integer::New(0));
2490 Script::Compile(v8_str("callFunctionRecursively()"))->Run(); 2484 Script::Compile(v8_str("callFunctionRecursively()"))->Run();
2491 } 2485 }
2492 2486
2493 2487
2494 static void ThrowingPropertyHandlerGet( 2488 static void ThrowingPropertyHandlerGet(
2495 Local<String> key, 2489 Local<String> key,
2496 const v8::PropertyCallbackInfo<v8::Value>& info) { 2490 const v8::PropertyCallbackInfo<v8::Value>& info) {
2497 ApiTestFuzzer::Fuzz(); 2491 ApiTestFuzzer::Fuzz();
2498 info.GetReturnValue().Set(info.GetIsolate()->ThrowException(key)); 2492 info.GetReturnValue().Set(info.GetIsolate()->ThrowException(key));
2499 } 2493 }
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
2655 static void CheckEmbedderData(LocalContext* env, 2649 static void CheckEmbedderData(LocalContext* env,
2656 int index, 2650 int index,
2657 v8::Handle<Value> data) { 2651 v8::Handle<Value> data) {
2658 (*env)->SetEmbedderData(index, data); 2652 (*env)->SetEmbedderData(index, data);
2659 CHECK((*env)->GetEmbedderData(index)->StrictEquals(data)); 2653 CHECK((*env)->GetEmbedderData(index)->StrictEquals(data));
2660 } 2654 }
2661 2655
2662 2656
2663 THREADED_TEST(EmbedderData) { 2657 THREADED_TEST(EmbedderData) {
2664 LocalContext env; 2658 LocalContext env;
2665 v8::Isolate* isolate = env->GetIsolate(); 2659 v8::HandleScope scope(env->GetIsolate());
2666 v8::HandleScope scope(isolate);
2667 2660
2668 CheckEmbedderData( 2661 CheckEmbedderData(
2669 &env, 3, 2662 &env, 3,
2670 v8::String::NewFromUtf8(isolate, "The quick brown fox jumps")); 2663 v8::String::NewFromUtf8(env->GetIsolate(), "The quick brown fox jumps"));
2671 CheckEmbedderData(&env, 2, v8::String::NewFromUtf8(isolate, 2664 CheckEmbedderData(&env, 2, v8::String::NewFromUtf8(env->GetIsolate(),
2672 "over the lazy dog.")); 2665 "over the lazy dog."));
2673 CheckEmbedderData(&env, 1, v8::Number::New(isolate, 1.2345)); 2666 CheckEmbedderData(&env, 1, v8::Number::New(1.2345));
2674 CheckEmbedderData(&env, 0, v8::Boolean::New(isolate, true)); 2667 CheckEmbedderData(&env, 0, v8::Boolean::New(env->GetIsolate(), true));
2675 } 2668 }
2676 2669
2677 2670
2678 THREADED_TEST(IdentityHash) { 2671 THREADED_TEST(IdentityHash) {
2679 LocalContext env; 2672 LocalContext env;
2680 v8::Isolate* isolate = env->GetIsolate(); 2673 v8::HandleScope scope(env->GetIsolate());
2681 v8::HandleScope scope(isolate);
2682 2674
2683 // Ensure that the test starts with an fresh heap to test whether the hash 2675 // Ensure that the test starts with an fresh heap to test whether the hash
2684 // code is based on the address. 2676 // code is based on the address.
2685 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 2677 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
2686 Local<v8::Object> obj = v8::Object::New(isolate); 2678 Local<v8::Object> obj = v8::Object::New();
2687 int hash = obj->GetIdentityHash(); 2679 int hash = obj->GetIdentityHash();
2688 int hash1 = obj->GetIdentityHash(); 2680 int hash1 = obj->GetIdentityHash();
2689 CHECK_EQ(hash, hash1); 2681 CHECK_EQ(hash, hash1);
2690 int hash2 = v8::Object::New(isolate)->GetIdentityHash(); 2682 int hash2 = v8::Object::New()->GetIdentityHash();
2691 // Since the identity hash is essentially a random number two consecutive 2683 // Since the identity hash is essentially a random number two consecutive
2692 // objects should not be assigned the same hash code. If the test below fails 2684 // objects should not be assigned the same hash code. If the test below fails
2693 // the random number generator should be evaluated. 2685 // the random number generator should be evaluated.
2694 CHECK_NE(hash, hash2); 2686 CHECK_NE(hash, hash2);
2695 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 2687 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
2696 int hash3 = v8::Object::New(isolate)->GetIdentityHash(); 2688 int hash3 = v8::Object::New()->GetIdentityHash();
2697 // Make sure that the identity hash is not based on the initial address of 2689 // Make sure that the identity hash is not based on the initial address of
2698 // the object alone. If the test below fails the random number generator 2690 // the object alone. If the test below fails the random number generator
2699 // should be evaluated. 2691 // should be evaluated.
2700 CHECK_NE(hash, hash3); 2692 CHECK_NE(hash, hash3);
2701 int hash4 = obj->GetIdentityHash(); 2693 int hash4 = obj->GetIdentityHash();
2702 CHECK_EQ(hash, hash4); 2694 CHECK_EQ(hash, hash4);
2703 2695
2704 // Check identity hashes behaviour in the presence of JS accessors. 2696 // Check identity hashes behaviour in the presence of JS accessors.
2705 // Put a getter for 'v8::IdentityHash' on the Object's prototype: 2697 // Put a getter for 'v8::IdentityHash' on the Object's prototype:
2706 { 2698 {
2707 CompileRun("Object.prototype['v8::IdentityHash'] = 42;\n"); 2699 CompileRun("Object.prototype['v8::IdentityHash'] = 42;\n");
2708 Local<v8::Object> o1 = v8::Object::New(isolate); 2700 Local<v8::Object> o1 = v8::Object::New();
2709 Local<v8::Object> o2 = v8::Object::New(isolate); 2701 Local<v8::Object> o2 = v8::Object::New();
2710 CHECK_NE(o1->GetIdentityHash(), o2->GetIdentityHash()); 2702 CHECK_NE(o1->GetIdentityHash(), o2->GetIdentityHash());
2711 } 2703 }
2712 { 2704 {
2713 CompileRun( 2705 CompileRun(
2714 "function cnst() { return 42; };\n" 2706 "function cnst() { return 42; };\n"
2715 "Object.prototype.__defineGetter__('v8::IdentityHash', cnst);\n"); 2707 "Object.prototype.__defineGetter__('v8::IdentityHash', cnst);\n");
2716 Local<v8::Object> o1 = v8::Object::New(isolate); 2708 Local<v8::Object> o1 = v8::Object::New();
2717 Local<v8::Object> o2 = v8::Object::New(isolate); 2709 Local<v8::Object> o2 = v8::Object::New();
2718 CHECK_NE(o1->GetIdentityHash(), o2->GetIdentityHash()); 2710 CHECK_NE(o1->GetIdentityHash(), o2->GetIdentityHash());
2719 } 2711 }
2720 } 2712 }
2721 2713
2722 2714
2723 THREADED_TEST(SymbolProperties) { 2715 THREADED_TEST(SymbolProperties) {
2724 i::FLAG_harmony_symbols = true; 2716 i::FLAG_harmony_symbols = true;
2725 2717
2726 LocalContext env; 2718 LocalContext env;
2727 v8::Isolate* isolate = env->GetIsolate(); 2719 v8::Isolate* isolate = env->GetIsolate();
2728 v8::HandleScope scope(isolate); 2720 v8::HandleScope scope(isolate);
2729 2721
2730 v8::Local<v8::Object> obj = v8::Object::New(isolate); 2722 v8::Local<v8::Object> obj = v8::Object::New();
2731 v8::Local<v8::Symbol> sym1 = v8::Symbol::New(isolate); 2723 v8::Local<v8::Symbol> sym1 = v8::Symbol::New(isolate);
2732 v8::Local<v8::Symbol> sym2 = v8::Symbol::New(isolate, "my-symbol"); 2724 v8::Local<v8::Symbol> sym2 = v8::Symbol::New(isolate, "my-symbol");
2733 2725
2734 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 2726 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
2735 2727
2736 // Check basic symbol functionality. 2728 // Check basic symbol functionality.
2737 CHECK(sym1->IsSymbol()); 2729 CHECK(sym1->IsSymbol());
2738 CHECK(sym2->IsSymbol()); 2730 CHECK(sym2->IsSymbol());
2739 CHECK(!obj->IsSymbol()); 2731 CHECK(!obj->IsSymbol());
2740 2732
(...skipping 20 matching lines...) Expand all
2761 CHECK(!obj->IsSymbolObject()); 2753 CHECK(!obj->IsSymbolObject());
2762 CHECK(sym_obj->Equals(sym2)); 2754 CHECK(sym_obj->Equals(sym2));
2763 CHECK(!sym_obj->StrictEquals(sym2)); 2755 CHECK(!sym_obj->StrictEquals(sym2));
2764 CHECK(v8::SymbolObject::Cast(*sym_obj)->Equals(sym_obj)); 2756 CHECK(v8::SymbolObject::Cast(*sym_obj)->Equals(sym_obj));
2765 CHECK(v8::SymbolObject::Cast(*sym_obj)->ValueOf()->Equals(sym2)); 2757 CHECK(v8::SymbolObject::Cast(*sym_obj)->ValueOf()->Equals(sym2));
2766 2758
2767 // Make sure delete of a non-existent symbol property works. 2759 // Make sure delete of a non-existent symbol property works.
2768 CHECK(obj->Delete(sym1)); 2760 CHECK(obj->Delete(sym1));
2769 CHECK(!obj->Has(sym1)); 2761 CHECK(!obj->Has(sym1));
2770 2762
2771 CHECK(obj->Set(sym1, v8::Integer::New(isolate, 1503))); 2763 CHECK(obj->Set(sym1, v8::Integer::New(1503)));
2772 CHECK(obj->Has(sym1)); 2764 CHECK(obj->Has(sym1));
2773 CHECK_EQ(1503, obj->Get(sym1)->Int32Value()); 2765 CHECK_EQ(1503, obj->Get(sym1)->Int32Value());
2774 CHECK(obj->Set(sym1, v8::Integer::New(isolate, 2002))); 2766 CHECK(obj->Set(sym1, v8::Integer::New(2002)));
2775 CHECK(obj->Has(sym1)); 2767 CHECK(obj->Has(sym1));
2776 CHECK_EQ(2002, obj->Get(sym1)->Int32Value()); 2768 CHECK_EQ(2002, obj->Get(sym1)->Int32Value());
2777 CHECK_EQ(v8::None, obj->GetPropertyAttributes(sym1)); 2769 CHECK_EQ(v8::None, obj->GetPropertyAttributes(sym1));
2778 2770
2779 CHECK_EQ(0, obj->GetOwnPropertyNames()->Length()); 2771 CHECK_EQ(0, obj->GetOwnPropertyNames()->Length());
2780 int num_props = obj->GetPropertyNames()->Length(); 2772 int num_props = obj->GetPropertyNames()->Length();
2781 CHECK(obj->Set(v8::String::NewFromUtf8(isolate, "bla"), 2773 CHECK(
2782 v8::Integer::New(isolate, 20))); 2774 obj->Set(v8::String::NewFromUtf8(isolate, "bla"), v8::Integer::New(20)));
2783 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length()); 2775 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length());
2784 CHECK_EQ(num_props + 1, obj->GetPropertyNames()->Length()); 2776 CHECK_EQ(num_props + 1, obj->GetPropertyNames()->Length());
2785 2777
2786 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 2778 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
2787 2779
2788 // Add another property and delete it afterwards to force the object in 2780 // Add another property and delete it afterwards to force the object in
2789 // slow case. 2781 // slow case.
2790 CHECK(obj->Set(sym2, v8::Integer::New(isolate, 2008))); 2782 CHECK(obj->Set(sym2, v8::Integer::New(2008)));
2791 CHECK_EQ(2002, obj->Get(sym1)->Int32Value()); 2783 CHECK_EQ(2002, obj->Get(sym1)->Int32Value());
2792 CHECK_EQ(2008, obj->Get(sym2)->Int32Value()); 2784 CHECK_EQ(2008, obj->Get(sym2)->Int32Value());
2793 CHECK_EQ(2002, obj->Get(sym1)->Int32Value()); 2785 CHECK_EQ(2002, obj->Get(sym1)->Int32Value());
2794 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length()); 2786 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length());
2795 2787
2796 CHECK(obj->Has(sym1)); 2788 CHECK(obj->Has(sym1));
2797 CHECK(obj->Has(sym2)); 2789 CHECK(obj->Has(sym2));
2798 CHECK(obj->Delete(sym2)); 2790 CHECK(obj->Delete(sym2));
2799 CHECK(obj->Has(sym1)); 2791 CHECK(obj->Has(sym1));
2800 CHECK(!obj->Has(sym2)); 2792 CHECK(!obj->Has(sym2));
2801 CHECK_EQ(2002, obj->Get(sym1)->Int32Value()); 2793 CHECK_EQ(2002, obj->Get(sym1)->Int32Value());
2802 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length()); 2794 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length());
2803 2795
2804 // Symbol properties are inherited. 2796 // Symbol properties are inherited.
2805 v8::Local<v8::Object> child = v8::Object::New(isolate); 2797 v8::Local<v8::Object> child = v8::Object::New();
2806 child->SetPrototype(obj); 2798 child->SetPrototype(obj);
2807 CHECK(child->Has(sym1)); 2799 CHECK(child->Has(sym1));
2808 CHECK_EQ(2002, child->Get(sym1)->Int32Value()); 2800 CHECK_EQ(2002, child->Get(sym1)->Int32Value());
2809 CHECK_EQ(0, child->GetOwnPropertyNames()->Length()); 2801 CHECK_EQ(0, child->GetOwnPropertyNames()->Length());
2810 } 2802 }
2811 2803
2812 2804
2813 THREADED_TEST(PrivateProperties) { 2805 THREADED_TEST(PrivateProperties) {
2814 LocalContext env; 2806 LocalContext env;
2815 v8::Isolate* isolate = env->GetIsolate(); 2807 v8::Isolate* isolate = env->GetIsolate();
2816 v8::HandleScope scope(isolate); 2808 v8::HandleScope scope(isolate);
2817 2809
2818 v8::Local<v8::Object> obj = v8::Object::New(isolate); 2810 v8::Local<v8::Object> obj = v8::Object::New();
2819 v8::Local<v8::Private> priv1 = v8::Private::New(isolate); 2811 v8::Local<v8::Private> priv1 = v8::Private::New(isolate);
2820 v8::Local<v8::Private> priv2 = v8::Private::New(isolate, "my-private"); 2812 v8::Local<v8::Private> priv2 = v8::Private::New(isolate, "my-private");
2821 2813
2822 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 2814 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
2823 2815
2824 CHECK(priv2->Name()->Equals(v8::String::NewFromUtf8(isolate, "my-private"))); 2816 CHECK(priv2->Name()->Equals(v8::String::NewFromUtf8(isolate, "my-private")));
2825 2817
2826 // Make sure delete of a non-existent private symbol property works. 2818 // Make sure delete of a non-existent private symbol property works.
2827 CHECK(obj->DeletePrivate(priv1)); 2819 CHECK(obj->DeletePrivate(priv1));
2828 CHECK(!obj->HasPrivate(priv1)); 2820 CHECK(!obj->HasPrivate(priv1));
2829 2821
2830 CHECK(obj->SetPrivate(priv1, v8::Integer::New(isolate, 1503))); 2822 CHECK(obj->SetPrivate(priv1, v8::Integer::New(1503)));
2831 CHECK(obj->HasPrivate(priv1)); 2823 CHECK(obj->HasPrivate(priv1));
2832 CHECK_EQ(1503, obj->GetPrivate(priv1)->Int32Value()); 2824 CHECK_EQ(1503, obj->GetPrivate(priv1)->Int32Value());
2833 CHECK(obj->SetPrivate(priv1, v8::Integer::New(isolate, 2002))); 2825 CHECK(obj->SetPrivate(priv1, v8::Integer::New(2002)));
2834 CHECK(obj->HasPrivate(priv1)); 2826 CHECK(obj->HasPrivate(priv1));
2835 CHECK_EQ(2002, obj->GetPrivate(priv1)->Int32Value()); 2827 CHECK_EQ(2002, obj->GetPrivate(priv1)->Int32Value());
2836 2828
2837 CHECK_EQ(0, obj->GetOwnPropertyNames()->Length()); 2829 CHECK_EQ(0, obj->GetOwnPropertyNames()->Length());
2838 int num_props = obj->GetPropertyNames()->Length(); 2830 int num_props = obj->GetPropertyNames()->Length();
2839 CHECK(obj->Set(v8::String::NewFromUtf8(isolate, "bla"), 2831 CHECK(
2840 v8::Integer::New(isolate, 20))); 2832 obj->Set(v8::String::NewFromUtf8(isolate, "bla"), v8::Integer::New(20)));
2841 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length()); 2833 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length());
2842 CHECK_EQ(num_props + 1, obj->GetPropertyNames()->Length()); 2834 CHECK_EQ(num_props + 1, obj->GetPropertyNames()->Length());
2843 2835
2844 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 2836 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
2845 2837
2846 // Add another property and delete it afterwards to force the object in 2838 // Add another property and delete it afterwards to force the object in
2847 // slow case. 2839 // slow case.
2848 CHECK(obj->SetPrivate(priv2, v8::Integer::New(isolate, 2008))); 2840 CHECK(obj->SetPrivate(priv2, v8::Integer::New(2008)));
2849 CHECK_EQ(2002, obj->GetPrivate(priv1)->Int32Value()); 2841 CHECK_EQ(2002, obj->GetPrivate(priv1)->Int32Value());
2850 CHECK_EQ(2008, obj->GetPrivate(priv2)->Int32Value()); 2842 CHECK_EQ(2008, obj->GetPrivate(priv2)->Int32Value());
2851 CHECK_EQ(2002, obj->GetPrivate(priv1)->Int32Value()); 2843 CHECK_EQ(2002, obj->GetPrivate(priv1)->Int32Value());
2852 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length()); 2844 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length());
2853 2845
2854 CHECK(obj->HasPrivate(priv1)); 2846 CHECK(obj->HasPrivate(priv1));
2855 CHECK(obj->HasPrivate(priv2)); 2847 CHECK(obj->HasPrivate(priv2));
2856 CHECK(obj->DeletePrivate(priv2)); 2848 CHECK(obj->DeletePrivate(priv2));
2857 CHECK(obj->HasPrivate(priv1)); 2849 CHECK(obj->HasPrivate(priv1));
2858 CHECK(!obj->HasPrivate(priv2)); 2850 CHECK(!obj->HasPrivate(priv2));
2859 CHECK_EQ(2002, obj->GetPrivate(priv1)->Int32Value()); 2851 CHECK_EQ(2002, obj->GetPrivate(priv1)->Int32Value());
2860 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length()); 2852 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length());
2861 2853
2862 // Private properties are inherited (for the time being). 2854 // Private properties are inherited (for the time being).
2863 v8::Local<v8::Object> child = v8::Object::New(isolate); 2855 v8::Local<v8::Object> child = v8::Object::New();
2864 child->SetPrototype(obj); 2856 child->SetPrototype(obj);
2865 CHECK(child->HasPrivate(priv1)); 2857 CHECK(child->HasPrivate(priv1));
2866 CHECK_EQ(2002, child->GetPrivate(priv1)->Int32Value()); 2858 CHECK_EQ(2002, child->GetPrivate(priv1)->Int32Value());
2867 CHECK_EQ(0, child->GetOwnPropertyNames()->Length()); 2859 CHECK_EQ(0, child->GetOwnPropertyNames()->Length());
2868 } 2860 }
2869 2861
2870 2862
2871 class ScopedArrayBufferContents { 2863 class ScopedArrayBufferContents {
2872 public: 2864 public:
2873 explicit ScopedArrayBufferContents( 2865 explicit ScopedArrayBufferContents(
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
3127 CheckIsTypedArrayVarNeutered("f64a"); 3119 CheckIsTypedArrayVarNeutered("f64a");
3128 3120
3129 CHECK(CompileRun("dv.byteLength == 0 && dv.byteOffset == 0")->IsTrue()); 3121 CHECK(CompileRun("dv.byteLength == 0 && dv.byteOffset == 0")->IsTrue());
3130 CheckDataViewIsNeutered(dv); 3122 CheckDataViewIsNeutered(dv);
3131 } 3123 }
3132 3124
3133 3125
3134 3126
3135 THREADED_TEST(HiddenProperties) { 3127 THREADED_TEST(HiddenProperties) {
3136 LocalContext env; 3128 LocalContext env;
3137 v8::Isolate* isolate = env->GetIsolate(); 3129 v8::HandleScope scope(env->GetIsolate());
3138 v8::HandleScope scope(isolate);
3139 3130
3140 v8::Local<v8::Object> obj = v8::Object::New(env->GetIsolate()); 3131 v8::Local<v8::Object> obj = v8::Object::New();
3141 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); 3132 v8::Local<v8::String> key = v8_str("api-test::hidden-key");
3142 v8::Local<v8::String> empty = v8_str(""); 3133 v8::Local<v8::String> empty = v8_str("");
3143 v8::Local<v8::String> prop_name = v8_str("prop_name"); 3134 v8::Local<v8::String> prop_name = v8_str("prop_name");
3144 3135
3145 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 3136 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
3146 3137
3147 // Make sure delete of a non-existent hidden value works 3138 // Make sure delete of a non-existent hidden value works
3148 CHECK(obj->DeleteHiddenValue(key)); 3139 CHECK(obj->DeleteHiddenValue(key));
3149 3140
3150 CHECK(obj->SetHiddenValue(key, v8::Integer::New(isolate, 1503))); 3141 CHECK(obj->SetHiddenValue(key, v8::Integer::New(1503)));
3151 CHECK_EQ(1503, obj->GetHiddenValue(key)->Int32Value()); 3142 CHECK_EQ(1503, obj->GetHiddenValue(key)->Int32Value());
3152 CHECK(obj->SetHiddenValue(key, v8::Integer::New(isolate, 2002))); 3143 CHECK(obj->SetHiddenValue(key, v8::Integer::New(2002)));
3153 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); 3144 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value());
3154 3145
3155 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 3146 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
3156 3147
3157 // Make sure we do not find the hidden property. 3148 // Make sure we do not find the hidden property.
3158 CHECK(!obj->Has(empty)); 3149 CHECK(!obj->Has(empty));
3159 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); 3150 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value());
3160 CHECK(obj->Get(empty)->IsUndefined()); 3151 CHECK(obj->Get(empty)->IsUndefined());
3161 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); 3152 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value());
3162 CHECK(obj->Set(empty, v8::Integer::New(isolate, 2003))); 3153 CHECK(obj->Set(empty, v8::Integer::New(2003)));
3163 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); 3154 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value());
3164 CHECK_EQ(2003, obj->Get(empty)->Int32Value()); 3155 CHECK_EQ(2003, obj->Get(empty)->Int32Value());
3165 3156
3166 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 3157 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
3167 3158
3168 // Add another property and delete it afterwards to force the object in 3159 // Add another property and delete it afterwards to force the object in
3169 // slow case. 3160 // slow case.
3170 CHECK(obj->Set(prop_name, v8::Integer::New(isolate, 2008))); 3161 CHECK(obj->Set(prop_name, v8::Integer::New(2008)));
3171 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); 3162 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value());
3172 CHECK_EQ(2008, obj->Get(prop_name)->Int32Value()); 3163 CHECK_EQ(2008, obj->Get(prop_name)->Int32Value());
3173 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); 3164 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value());
3174 CHECK(obj->Delete(prop_name)); 3165 CHECK(obj->Delete(prop_name));
3175 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); 3166 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value());
3176 3167
3177 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 3168 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
3178 3169
3179 CHECK(obj->SetHiddenValue(key, Handle<Value>())); 3170 CHECK(obj->SetHiddenValue(key, Handle<Value>()));
3180 CHECK(obj->GetHiddenValue(key).IsEmpty()); 3171 CHECK(obj->GetHiddenValue(key).IsEmpty());
3181 3172
3182 CHECK(obj->SetHiddenValue(key, v8::Integer::New(isolate, 2002))); 3173 CHECK(obj->SetHiddenValue(key, v8::Integer::New(2002)));
3183 CHECK(obj->DeleteHiddenValue(key)); 3174 CHECK(obj->DeleteHiddenValue(key));
3184 CHECK(obj->GetHiddenValue(key).IsEmpty()); 3175 CHECK(obj->GetHiddenValue(key).IsEmpty());
3185 } 3176 }
3186 3177
3187 3178
3188 THREADED_TEST(Regress97784) { 3179 THREADED_TEST(Regress97784) {
3189 // Regression test for crbug.com/97784 3180 // Regression test for crbug.com/97784
3190 // Messing with the Object.prototype should not have effect on 3181 // Messing with the Object.prototype should not have effect on
3191 // hidden properties. 3182 // hidden properties.
3192 LocalContext env; 3183 LocalContext env;
3193 v8::HandleScope scope(env->GetIsolate()); 3184 v8::HandleScope scope(env->GetIsolate());
3194 3185
3195 v8::Local<v8::Object> obj = v8::Object::New(env->GetIsolate()); 3186 v8::Local<v8::Object> obj = v8::Object::New();
3196 v8::Local<v8::String> key = v8_str("hidden"); 3187 v8::Local<v8::String> key = v8_str("hidden");
3197 3188
3198 CompileRun( 3189 CompileRun(
3199 "set_called = false;" 3190 "set_called = false;"
3200 "Object.defineProperty(" 3191 "Object.defineProperty("
3201 " Object.prototype," 3192 " Object.prototype,"
3202 " 'hidden'," 3193 " 'hidden',"
3203 " {get: function() { return 45; }," 3194 " {get: function() { return 45; },"
3204 " set: function() { set_called = true; }})"); 3195 " set: function() { set_called = true; }})");
3205 3196
3206 CHECK(obj->GetHiddenValue(key).IsEmpty()); 3197 CHECK(obj->GetHiddenValue(key).IsEmpty());
3207 // Make sure that the getter and setter from Object.prototype is not invoked. 3198 // Make sure that the getter and setter from Object.prototype is not invoked.
3208 // If it did we would have full access to the hidden properties in 3199 // If it did we would have full access to the hidden properties in
3209 // the accessor. 3200 // the accessor.
3210 CHECK(obj->SetHiddenValue(key, v8::Integer::New(env->GetIsolate(), 42))); 3201 CHECK(obj->SetHiddenValue(key, v8::Integer::New(42)));
3211 ExpectFalse("set_called"); 3202 ExpectFalse("set_called");
3212 CHECK_EQ(42, obj->GetHiddenValue(key)->Int32Value()); 3203 CHECK_EQ(42, obj->GetHiddenValue(key)->Int32Value());
3213 } 3204 }
3214 3205
3215 3206
3216 static bool interceptor_for_hidden_properties_called; 3207 static bool interceptor_for_hidden_properties_called;
3217 static void InterceptorForHiddenProperties( 3208 static void InterceptorForHiddenProperties(
3218 Local<String> name, const v8::PropertyCallbackInfo<v8::Value>& info) { 3209 Local<String> name, const v8::PropertyCallbackInfo<v8::Value>& info) {
3219 interceptor_for_hidden_properties_called = true; 3210 interceptor_for_hidden_properties_called = true;
3220 } 3211 }
3221 3212
3222 3213
3223 THREADED_TEST(HiddenPropertiesWithInterceptors) { 3214 THREADED_TEST(HiddenPropertiesWithInterceptors) {
3224 LocalContext context; 3215 LocalContext context;
3225 v8::Isolate* isolate = context->GetIsolate(); 3216 v8::Isolate* isolate = context->GetIsolate();
3226 v8::HandleScope scope(isolate); 3217 v8::HandleScope scope(isolate);
3227 3218
3228 interceptor_for_hidden_properties_called = false; 3219 interceptor_for_hidden_properties_called = false;
3229 3220
3230 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); 3221 v8::Local<v8::String> key = v8_str("api-test::hidden-key");
3231 3222
3232 // Associate an interceptor with an object and start setting hidden values. 3223 // Associate an interceptor with an object and start setting hidden values.
3233 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate); 3224 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate);
3234 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); 3225 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate();
3235 instance_templ->SetNamedPropertyHandler(InterceptorForHiddenProperties); 3226 instance_templ->SetNamedPropertyHandler(InterceptorForHiddenProperties);
3236 Local<v8::Function> function = fun_templ->GetFunction(); 3227 Local<v8::Function> function = fun_templ->GetFunction();
3237 Local<v8::Object> obj = function->NewInstance(); 3228 Local<v8::Object> obj = function->NewInstance();
3238 CHECK(obj->SetHiddenValue(key, v8::Integer::New(isolate, 2302))); 3229 CHECK(obj->SetHiddenValue(key, v8::Integer::New(2302)));
3239 CHECK_EQ(2302, obj->GetHiddenValue(key)->Int32Value()); 3230 CHECK_EQ(2302, obj->GetHiddenValue(key)->Int32Value());
3240 CHECK(!interceptor_for_hidden_properties_called); 3231 CHECK(!interceptor_for_hidden_properties_called);
3241 } 3232 }
3242 3233
3243 3234
3244 THREADED_TEST(External) { 3235 THREADED_TEST(External) {
3245 v8::HandleScope scope(CcTest::isolate()); 3236 v8::HandleScope scope(CcTest::isolate());
3246 int x = 3; 3237 int x = 3;
3247 Local<v8::External> ext = v8::External::New(CcTest::isolate(), &x); 3238 Local<v8::External> ext = v8::External::New(CcTest::isolate(), &x);
3248 LocalContext env; 3239 LocalContext env;
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
3520 3511
3521 WeakCallCounterAndPersistent<Value> g1s1(&counter); 3512 WeakCallCounterAndPersistent<Value> g1s1(&counter);
3522 WeakCallCounterAndPersistent<Value> g1s2(&counter); 3513 WeakCallCounterAndPersistent<Value> g1s2(&counter);
3523 WeakCallCounterAndPersistent<Value> g1c1(&counter); 3514 WeakCallCounterAndPersistent<Value> g1c1(&counter);
3524 WeakCallCounterAndPersistent<Value> g2s1(&counter); 3515 WeakCallCounterAndPersistent<Value> g2s1(&counter);
3525 WeakCallCounterAndPersistent<Value> g2s2(&counter); 3516 WeakCallCounterAndPersistent<Value> g2s2(&counter);
3526 WeakCallCounterAndPersistent<Value> g2c1(&counter); 3517 WeakCallCounterAndPersistent<Value> g2c1(&counter);
3527 3518
3528 { 3519 {
3529 HandleScope scope(iso); 3520 HandleScope scope(iso);
3530 g1s1.handle.Reset(iso, Object::New(iso)); 3521 g1s1.handle.Reset(iso, Object::New());
3531 g1s2.handle.Reset(iso, Object::New(iso)); 3522 g1s2.handle.Reset(iso, Object::New());
3532 g1c1.handle.Reset(iso, Object::New(iso)); 3523 g1c1.handle.Reset(iso, Object::New());
3533 g1s1.handle.SetWeak(&g1s1, &WeakPointerCallback); 3524 g1s1.handle.SetWeak(&g1s1, &WeakPointerCallback);
3534 g1s2.handle.SetWeak(&g1s2, &WeakPointerCallback); 3525 g1s2.handle.SetWeak(&g1s2, &WeakPointerCallback);
3535 g1c1.handle.SetWeak(&g1c1, &WeakPointerCallback); 3526 g1c1.handle.SetWeak(&g1c1, &WeakPointerCallback);
3536 3527
3537 g2s1.handle.Reset(iso, Object::New(iso)); 3528 g2s1.handle.Reset(iso, Object::New());
3538 g2s2.handle.Reset(iso, Object::New(iso)); 3529 g2s2.handle.Reset(iso, Object::New());
3539 g2c1.handle.Reset(iso, Object::New(iso)); 3530 g2c1.handle.Reset(iso, Object::New());
3540 g2s1.handle.SetWeak(&g2s1, &WeakPointerCallback); 3531 g2s1.handle.SetWeak(&g2s1, &WeakPointerCallback);
3541 g2s2.handle.SetWeak(&g2s2, &WeakPointerCallback); 3532 g2s2.handle.SetWeak(&g2s2, &WeakPointerCallback);
3542 g2c1.handle.SetWeak(&g2c1, &WeakPointerCallback); 3533 g2c1.handle.SetWeak(&g2c1, &WeakPointerCallback);
3543 } 3534 }
3544 3535
3545 WeakCallCounterAndPersistent<Value> root(&counter); 3536 WeakCallCounterAndPersistent<Value> root(&counter);
3546 root.handle.Reset(iso, g1s1.handle); // make a root. 3537 root.handle.Reset(iso, g1s1.handle); // make a root.
3547 3538
3548 // Connect group 1 and 2, make a cycle. 3539 // Connect group 1 and 2, make a cycle.
3549 { 3540 {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
3614 3605
3615 WeakCallCounterAndPersistent<Object> g1s1(&counter); 3606 WeakCallCounterAndPersistent<Object> g1s1(&counter);
3616 WeakCallCounterAndPersistent<String> g1s2(&counter); 3607 WeakCallCounterAndPersistent<String> g1s2(&counter);
3617 WeakCallCounterAndPersistent<String> g1c1(&counter); 3608 WeakCallCounterAndPersistent<String> g1c1(&counter);
3618 WeakCallCounterAndPersistent<Object> g2s1(&counter); 3609 WeakCallCounterAndPersistent<Object> g2s1(&counter);
3619 WeakCallCounterAndPersistent<String> g2s2(&counter); 3610 WeakCallCounterAndPersistent<String> g2s2(&counter);
3620 WeakCallCounterAndPersistent<String> g2c1(&counter); 3611 WeakCallCounterAndPersistent<String> g2c1(&counter);
3621 3612
3622 { 3613 {
3623 HandleScope scope(iso); 3614 HandleScope scope(iso);
3624 g1s1.handle.Reset(iso, Object::New(iso)); 3615 g1s1.handle.Reset(iso, Object::New());
3625 g1s2.handle.Reset(iso, String::NewFromUtf8(iso, "foo1")); 3616 g1s2.handle.Reset(iso, String::NewFromUtf8(iso, "foo1"));
3626 g1c1.handle.Reset(iso, String::NewFromUtf8(iso, "foo2")); 3617 g1c1.handle.Reset(iso, String::NewFromUtf8(iso, "foo2"));
3627 g1s1.handle.SetWeak(&g1s1, &WeakPointerCallback); 3618 g1s1.handle.SetWeak(&g1s1, &WeakPointerCallback);
3628 g1s2.handle.SetWeak(&g1s2, &WeakPointerCallback); 3619 g1s2.handle.SetWeak(&g1s2, &WeakPointerCallback);
3629 g1c1.handle.SetWeak(&g1c1, &WeakPointerCallback); 3620 g1c1.handle.SetWeak(&g1c1, &WeakPointerCallback);
3630 3621
3631 g2s1.handle.Reset(iso, Object::New(iso)); 3622 g2s1.handle.Reset(iso, Object::New());
3632 g2s2.handle.Reset(iso, String::NewFromUtf8(iso, "foo3")); 3623 g2s2.handle.Reset(iso, String::NewFromUtf8(iso, "foo3"));
3633 g2c1.handle.Reset(iso, String::NewFromUtf8(iso, "foo4")); 3624 g2c1.handle.Reset(iso, String::NewFromUtf8(iso, "foo4"));
3634 g2s1.handle.SetWeak(&g2s1, &WeakPointerCallback); 3625 g2s1.handle.SetWeak(&g2s1, &WeakPointerCallback);
3635 g2s2.handle.SetWeak(&g2s2, &WeakPointerCallback); 3626 g2s2.handle.SetWeak(&g2s2, &WeakPointerCallback);
3636 g2c1.handle.SetWeak(&g2c1, &WeakPointerCallback); 3627 g2c1.handle.SetWeak(&g2c1, &WeakPointerCallback);
3637 } 3628 }
3638 3629
3639 WeakCallCounterAndPersistent<Value> root(&counter); 3630 WeakCallCounterAndPersistent<Value> root(&counter);
3640 root.handle.Reset(iso, g1s1.handle); // make a root. 3631 root.handle.Reset(iso, g1s1.handle); // make a root.
3641 3632
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
3710 WeakCallCounterAndPersistent<Value> g1s2(&counter); 3701 WeakCallCounterAndPersistent<Value> g1s2(&counter);
3711 WeakCallCounterAndPersistent<Value> g2s1(&counter); 3702 WeakCallCounterAndPersistent<Value> g2s1(&counter);
3712 WeakCallCounterAndPersistent<Value> g2s2(&counter); 3703 WeakCallCounterAndPersistent<Value> g2s2(&counter);
3713 WeakCallCounterAndPersistent<Value> g3s1(&counter); 3704 WeakCallCounterAndPersistent<Value> g3s1(&counter);
3714 WeakCallCounterAndPersistent<Value> g3s2(&counter); 3705 WeakCallCounterAndPersistent<Value> g3s2(&counter);
3715 WeakCallCounterAndPersistent<Value> g4s1(&counter); 3706 WeakCallCounterAndPersistent<Value> g4s1(&counter);
3716 WeakCallCounterAndPersistent<Value> g4s2(&counter); 3707 WeakCallCounterAndPersistent<Value> g4s2(&counter);
3717 3708
3718 { 3709 {
3719 HandleScope scope(iso); 3710 HandleScope scope(iso);
3720 g1s1.handle.Reset(iso, Object::New(iso)); 3711 g1s1.handle.Reset(iso, Object::New());
3721 g1s2.handle.Reset(iso, Object::New(iso)); 3712 g1s2.handle.Reset(iso, Object::New());
3722 g1s1.handle.SetWeak(&g1s1, &WeakPointerCallback); 3713 g1s1.handle.SetWeak(&g1s1, &WeakPointerCallback);
3723 g1s2.handle.SetWeak(&g1s2, &WeakPointerCallback); 3714 g1s2.handle.SetWeak(&g1s2, &WeakPointerCallback);
3724 CHECK(g1s1.handle.IsWeak()); 3715 CHECK(g1s1.handle.IsWeak());
3725 CHECK(g1s2.handle.IsWeak()); 3716 CHECK(g1s2.handle.IsWeak());
3726 3717
3727 g2s1.handle.Reset(iso, Object::New(iso)); 3718 g2s1.handle.Reset(iso, Object::New());
3728 g2s2.handle.Reset(iso, Object::New(iso)); 3719 g2s2.handle.Reset(iso, Object::New());
3729 g2s1.handle.SetWeak(&g2s1, &WeakPointerCallback); 3720 g2s1.handle.SetWeak(&g2s1, &WeakPointerCallback);
3730 g2s2.handle.SetWeak(&g2s2, &WeakPointerCallback); 3721 g2s2.handle.SetWeak(&g2s2, &WeakPointerCallback);
3731 CHECK(g2s1.handle.IsWeak()); 3722 CHECK(g2s1.handle.IsWeak());
3732 CHECK(g2s2.handle.IsWeak()); 3723 CHECK(g2s2.handle.IsWeak());
3733 3724
3734 g3s1.handle.Reset(iso, Object::New(iso)); 3725 g3s1.handle.Reset(iso, Object::New());
3735 g3s2.handle.Reset(iso, Object::New(iso)); 3726 g3s2.handle.Reset(iso, Object::New());
3736 g3s1.handle.SetWeak(&g3s1, &WeakPointerCallback); 3727 g3s1.handle.SetWeak(&g3s1, &WeakPointerCallback);
3737 g3s2.handle.SetWeak(&g3s2, &WeakPointerCallback); 3728 g3s2.handle.SetWeak(&g3s2, &WeakPointerCallback);
3738 CHECK(g3s1.handle.IsWeak()); 3729 CHECK(g3s1.handle.IsWeak());
3739 CHECK(g3s2.handle.IsWeak()); 3730 CHECK(g3s2.handle.IsWeak());
3740 3731
3741 g4s1.handle.Reset(iso, Object::New(iso)); 3732 g4s1.handle.Reset(iso, Object::New());
3742 g4s2.handle.Reset(iso, Object::New(iso)); 3733 g4s2.handle.Reset(iso, Object::New());
3743 g4s1.handle.SetWeak(&g4s1, &WeakPointerCallback); 3734 g4s1.handle.SetWeak(&g4s1, &WeakPointerCallback);
3744 g4s2.handle.SetWeak(&g4s2, &WeakPointerCallback); 3735 g4s2.handle.SetWeak(&g4s2, &WeakPointerCallback);
3745 CHECK(g4s1.handle.IsWeak()); 3736 CHECK(g4s1.handle.IsWeak());
3746 CHECK(g4s2.handle.IsWeak()); 3737 CHECK(g4s2.handle.IsWeak());
3747 } 3738 }
3748 3739
3749 WeakCallCounterAndPersistent<Value> root(&counter); 3740 WeakCallCounterAndPersistent<Value> root(&counter);
3750 root.handle.Reset(iso, g1s1.handle); // make a root. 3741 root.handle.Reset(iso, g1s1.handle); // make a root.
3751 3742
3752 // Connect groups. We're building the following cycle: 3743 // Connect groups. We're building the following cycle:
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
3821 3812
3822 WeakCallCounterAndPersistent<Value> g1s1(&counter); 3813 WeakCallCounterAndPersistent<Value> g1s1(&counter);
3823 WeakCallCounterAndPersistent<Value> g1s2(&counter); 3814 WeakCallCounterAndPersistent<Value> g1s2(&counter);
3824 WeakCallCounterAndPersistent<Value> g2s1(&counter); 3815 WeakCallCounterAndPersistent<Value> g2s1(&counter);
3825 WeakCallCounterAndPersistent<Value> g2s2(&counter); 3816 WeakCallCounterAndPersistent<Value> g2s2(&counter);
3826 WeakCallCounterAndPersistent<Value> g3s1(&counter); 3817 WeakCallCounterAndPersistent<Value> g3s1(&counter);
3827 WeakCallCounterAndPersistent<Value> g3s2(&counter); 3818 WeakCallCounterAndPersistent<Value> g3s2(&counter);
3828 3819
3829 { 3820 {
3830 HandleScope scope(iso); 3821 HandleScope scope(iso);
3831 g1s1.handle.Reset(iso, Object::New(iso)); 3822 g1s1.handle.Reset(iso, Object::New());
3832 g1s2.handle.Reset(iso, Object::New(iso)); 3823 g1s2.handle.Reset(iso, Object::New());
3833 g1s1.handle.SetWeak(&g1s1, &WeakPointerCallback); 3824 g1s1.handle.SetWeak(&g1s1, &WeakPointerCallback);
3834 g1s2.handle.SetWeak(&g1s2, &WeakPointerCallback); 3825 g1s2.handle.SetWeak(&g1s2, &WeakPointerCallback);
3835 3826
3836 g2s1.handle.Reset(iso, Object::New(iso)); 3827 g2s1.handle.Reset(iso, Object::New());
3837 g2s2.handle.Reset(iso, Object::New(iso)); 3828 g2s2.handle.Reset(iso, Object::New());
3838 g2s1.handle.SetWeak(&g2s1, &WeakPointerCallback); 3829 g2s1.handle.SetWeak(&g2s1, &WeakPointerCallback);
3839 g2s2.handle.SetWeak(&g2s2, &WeakPointerCallback); 3830 g2s2.handle.SetWeak(&g2s2, &WeakPointerCallback);
3840 3831
3841 g3s1.handle.Reset(iso, Object::New(iso)); 3832 g3s1.handle.Reset(iso, Object::New());
3842 g3s2.handle.Reset(iso, Object::New(iso)); 3833 g3s2.handle.Reset(iso, Object::New());
3843 g3s1.handle.SetWeak(&g3s1, &WeakPointerCallback); 3834 g3s1.handle.SetWeak(&g3s1, &WeakPointerCallback);
3844 g3s2.handle.SetWeak(&g3s2, &WeakPointerCallback); 3835 g3s2.handle.SetWeak(&g3s2, &WeakPointerCallback);
3845 } 3836 }
3846 3837
3847 // Make a root. 3838 // Make a root.
3848 WeakCallCounterAndPersistent<Value> root(&counter); 3839 WeakCallCounterAndPersistent<Value> root(&counter);
3849 root.handle.Reset(iso, g1s1.handle); 3840 root.handle.Reset(iso, g1s1.handle);
3850 root.handle.MarkPartiallyDependent(); 3841 root.handle.MarkPartiallyDependent();
3851 3842
3852 // Connect groups. We're building the following cycle: 3843 // Connect groups. We're building the following cycle:
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
3950 CHECK_EQ(7.56, message->GetScriptData()->NumberValue()); 3941 CHECK_EQ(7.56, message->GetScriptData()->NumberValue());
3951 CHECK(!message->IsSharedCrossOrigin()); 3942 CHECK(!message->IsSharedCrossOrigin());
3952 message_received = true; 3943 message_received = true;
3953 } 3944 }
3954 3945
3955 3946
3956 THREADED_TEST(MessageHandler0) { 3947 THREADED_TEST(MessageHandler0) {
3957 message_received = false; 3948 message_received = false;
3958 v8::HandleScope scope(CcTest::isolate()); 3949 v8::HandleScope scope(CcTest::isolate());
3959 CHECK(!message_received); 3950 CHECK(!message_received);
3951 v8::V8::AddMessageListener(check_message_0, v8_num(5.76));
3960 LocalContext context; 3952 LocalContext context;
3961 v8::V8::AddMessageListener(check_message_0, v8_num(5.76));
3962 v8::ScriptOrigin origin = 3953 v8::ScriptOrigin origin =
3963 v8::ScriptOrigin(v8_str("6.75")); 3954 v8::ScriptOrigin(v8_str("6.75"));
3964 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"), 3955 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"),
3965 &origin); 3956 &origin);
3966 script->SetData(v8_str("7.56")); 3957 script->SetData(v8_str("7.56"));
3967 script->Run(); 3958 script->Run();
3968 CHECK(message_received); 3959 CHECK(message_received);
3969 // clear out the message listener 3960 // clear out the message listener
3970 v8::V8::RemoveMessageListeners(check_message_0); 3961 v8::V8::RemoveMessageListeners(check_message_0);
3971 } 3962 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
4032 4023
4033 TEST(MessageHandler3) { 4024 TEST(MessageHandler3) {
4034 message_received = false; 4025 message_received = false;
4035 v8::Isolate* isolate = CcTest::isolate(); 4026 v8::Isolate* isolate = CcTest::isolate();
4036 v8::HandleScope scope(isolate); 4027 v8::HandleScope scope(isolate);
4037 CHECK(!message_received); 4028 CHECK(!message_received);
4038 v8::V8::AddMessageListener(check_message_3); 4029 v8::V8::AddMessageListener(check_message_3);
4039 LocalContext context; 4030 LocalContext context;
4040 v8::ScriptOrigin origin = 4031 v8::ScriptOrigin origin =
4041 v8::ScriptOrigin(v8_str("6.75"), 4032 v8::ScriptOrigin(v8_str("6.75"),
4042 v8::Integer::New(isolate, 1), 4033 v8::Integer::New(1, isolate),
4043 v8::Integer::New(isolate, 2), 4034 v8::Integer::New(2, isolate),
4044 v8::True(isolate)); 4035 v8::True(isolate));
4045 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"), 4036 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"),
4046 &origin); 4037 &origin);
4047 script->Run(); 4038 script->Run();
4048 CHECK(message_received); 4039 CHECK(message_received);
4049 // clear out the message listener 4040 // clear out the message listener
4050 v8::V8::RemoveMessageListeners(check_message_3); 4041 v8::V8::RemoveMessageListeners(check_message_3);
4051 } 4042 }
4052 4043
4053 4044
4054 static void check_message_4(v8::Handle<v8::Message> message, 4045 static void check_message_4(v8::Handle<v8::Message> message,
4055 v8::Handle<Value> data) { 4046 v8::Handle<Value> data) {
4056 CHECK(!message->IsSharedCrossOrigin()); 4047 CHECK(!message->IsSharedCrossOrigin());
4057 CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue()); 4048 CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue());
4058 message_received = true; 4049 message_received = true;
4059 } 4050 }
4060 4051
4061 4052
4062 TEST(MessageHandler4) { 4053 TEST(MessageHandler4) {
4063 message_received = false; 4054 message_received = false;
4064 v8::Isolate* isolate = CcTest::isolate(); 4055 v8::Isolate* isolate = CcTest::isolate();
4065 v8::HandleScope scope(isolate); 4056 v8::HandleScope scope(isolate);
4066 CHECK(!message_received); 4057 CHECK(!message_received);
4067 v8::V8::AddMessageListener(check_message_4); 4058 v8::V8::AddMessageListener(check_message_4);
4068 LocalContext context; 4059 LocalContext context;
4069 v8::ScriptOrigin origin = 4060 v8::ScriptOrigin origin =
4070 v8::ScriptOrigin(v8_str("6.75"), 4061 v8::ScriptOrigin(v8_str("6.75"),
4071 v8::Integer::New(isolate, 1), 4062 v8::Integer::New(1, isolate),
4072 v8::Integer::New(isolate, 2), 4063 v8::Integer::New(2, isolate),
4073 v8::False(isolate)); 4064 v8::False(isolate));
4074 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"), 4065 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"),
4075 &origin); 4066 &origin);
4076 script->Run(); 4067 script->Run();
4077 CHECK(message_received); 4068 CHECK(message_received);
4078 // clear out the message listener 4069 // clear out the message listener
4079 v8::V8::RemoveMessageListeners(check_message_4); 4070 v8::V8::RemoveMessageListeners(check_message_4);
4080 } 4071 }
4081 4072
4082 4073
(...skipping 15 matching lines...) Expand all
4098 4089
4099 TEST(MessageHandler5) { 4090 TEST(MessageHandler5) {
4100 message_received = false; 4091 message_received = false;
4101 v8::Isolate* isolate = CcTest::isolate(); 4092 v8::Isolate* isolate = CcTest::isolate();
4102 v8::HandleScope scope(isolate); 4093 v8::HandleScope scope(isolate);
4103 CHECK(!message_received); 4094 CHECK(!message_received);
4104 v8::V8::AddMessageListener(check_message_5a); 4095 v8::V8::AddMessageListener(check_message_5a);
4105 LocalContext context; 4096 LocalContext context;
4106 v8::ScriptOrigin origin = 4097 v8::ScriptOrigin origin =
4107 v8::ScriptOrigin(v8_str("6.75"), 4098 v8::ScriptOrigin(v8_str("6.75"),
4108 v8::Integer::New(isolate, 1), 4099 v8::Integer::New(1, isolate),
4109 v8::Integer::New(isolate, 2), 4100 v8::Integer::New(2, isolate),
4110 v8::True(isolate)); 4101 v8::True(isolate));
4111 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"), 4102 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"),
4112 &origin); 4103 &origin);
4113 script->Run(); 4104 script->Run();
4114 CHECK(message_received); 4105 CHECK(message_received);
4115 // clear out the message listener 4106 // clear out the message listener
4116 v8::V8::RemoveMessageListeners(check_message_5a); 4107 v8::V8::RemoveMessageListeners(check_message_5a);
4117 4108
4118 message_received = false; 4109 message_received = false;
4119 v8::V8::AddMessageListener(check_message_5b); 4110 v8::V8::AddMessageListener(check_message_5b);
4120 origin = 4111 origin =
4121 v8::ScriptOrigin(v8_str("6.75"), 4112 v8::ScriptOrigin(v8_str("6.75"),
4122 v8::Integer::New(isolate, 1), 4113 v8::Integer::New(1, isolate),
4123 v8::Integer::New(isolate, 2), 4114 v8::Integer::New(2, isolate),
4124 v8::False(isolate)); 4115 v8::False(isolate));
4125 script = Script::Compile(v8_str("throw 'error'"), 4116 script = Script::Compile(v8_str("throw 'error'"),
4126 &origin); 4117 &origin);
4127 script->Run(); 4118 script->Run();
4128 CHECK(message_received); 4119 CHECK(message_received);
4129 // clear out the message listener 4120 // clear out the message listener
4130 v8::V8::RemoveMessageListeners(check_message_5b); 4121 v8::V8::RemoveMessageListeners(check_message_5b);
4131 } 4122 }
4132 4123
4133 4124
4134 THREADED_TEST(GetSetProperty) { 4125 THREADED_TEST(GetSetProperty) {
4135 LocalContext context; 4126 LocalContext context;
4136 v8::Isolate* isolate = context->GetIsolate(); 4127 v8::HandleScope scope(context->GetIsolate());
4137 v8::HandleScope scope(isolate);
4138 context->Global()->Set(v8_str("foo"), v8_num(14)); 4128 context->Global()->Set(v8_str("foo"), v8_num(14));
4139 context->Global()->Set(v8_str("12"), v8_num(92)); 4129 context->Global()->Set(v8_str("12"), v8_num(92));
4140 context->Global()->Set(v8::Integer::New(isolate, 16), v8_num(32)); 4130 context->Global()->Set(v8::Integer::New(16), v8_num(32));
4141 context->Global()->Set(v8_num(13), v8_num(56)); 4131 context->Global()->Set(v8_num(13), v8_num(56));
4142 Local<Value> foo = Script::Compile(v8_str("this.foo"))->Run(); 4132 Local<Value> foo = Script::Compile(v8_str("this.foo"))->Run();
4143 CHECK_EQ(14, foo->Int32Value()); 4133 CHECK_EQ(14, foo->Int32Value());
4144 Local<Value> twelve = Script::Compile(v8_str("this[12]"))->Run(); 4134 Local<Value> twelve = Script::Compile(v8_str("this[12]"))->Run();
4145 CHECK_EQ(92, twelve->Int32Value()); 4135 CHECK_EQ(92, twelve->Int32Value());
4146 Local<Value> sixteen = Script::Compile(v8_str("this[16]"))->Run(); 4136 Local<Value> sixteen = Script::Compile(v8_str("this[16]"))->Run();
4147 CHECK_EQ(32, sixteen->Int32Value()); 4137 CHECK_EQ(32, sixteen->Int32Value());
4148 Local<Value> thirteen = Script::Compile(v8_str("this[13]"))->Run(); 4138 Local<Value> thirteen = Script::Compile(v8_str("this[13]"))->Run();
4149 CHECK_EQ(56, thirteen->Int32Value()); 4139 CHECK_EQ(56, thirteen->Int32Value());
4150 CHECK_EQ(92, 4140 CHECK_EQ(92, context->Global()->Get(v8::Integer::New(12))->Int32Value());
4151 context->Global()->Get(v8::Integer::New(isolate, 12))->Int32Value());
4152 CHECK_EQ(92, context->Global()->Get(v8_str("12"))->Int32Value()); 4141 CHECK_EQ(92, context->Global()->Get(v8_str("12"))->Int32Value());
4153 CHECK_EQ(92, context->Global()->Get(v8_num(12))->Int32Value()); 4142 CHECK_EQ(92, context->Global()->Get(v8_num(12))->Int32Value());
4154 CHECK_EQ(32, 4143 CHECK_EQ(32, context->Global()->Get(v8::Integer::New(16))->Int32Value());
4155 context->Global()->Get(v8::Integer::New(isolate, 16))->Int32Value());
4156 CHECK_EQ(32, context->Global()->Get(v8_str("16"))->Int32Value()); 4144 CHECK_EQ(32, context->Global()->Get(v8_str("16"))->Int32Value());
4157 CHECK_EQ(32, context->Global()->Get(v8_num(16))->Int32Value()); 4145 CHECK_EQ(32, context->Global()->Get(v8_num(16))->Int32Value());
4158 CHECK_EQ(56, 4146 CHECK_EQ(56, context->Global()->Get(v8::Integer::New(13))->Int32Value());
4159 context->Global()->Get(v8::Integer::New(isolate, 13))->Int32Value());
4160 CHECK_EQ(56, context->Global()->Get(v8_str("13"))->Int32Value()); 4147 CHECK_EQ(56, context->Global()->Get(v8_str("13"))->Int32Value());
4161 CHECK_EQ(56, context->Global()->Get(v8_num(13))->Int32Value()); 4148 CHECK_EQ(56, context->Global()->Get(v8_num(13))->Int32Value());
4162 } 4149 }
4163 4150
4164 4151
4165 THREADED_TEST(PropertyAttributes) { 4152 THREADED_TEST(PropertyAttributes) {
4166 LocalContext context; 4153 LocalContext context;
4167 v8::HandleScope scope(context->GetIsolate()); 4154 v8::HandleScope scope(context->GetIsolate());
4168 // none 4155 // none
4169 Local<String> prop = v8_str("none"); 4156 Local<String> prop = v8_str("none");
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
4309 Local<Function> ReturnThisStrict = 4296 Local<Function> ReturnThisStrict =
4310 Local<Function>::Cast(context->Global()->Get(v8_str("ReturnThisStrict"))); 4297 Local<Function>::Cast(context->Global()->Get(v8_str("ReturnThisStrict")));
4311 4298
4312 v8::Handle<Value>* args0 = NULL; 4299 v8::Handle<Value>* args0 = NULL;
4313 Local<v8::Array> a0 = Local<v8::Array>::Cast(Foo->Call(Foo, 0, args0)); 4300 Local<v8::Array> a0 = Local<v8::Array>::Cast(Foo->Call(Foo, 0, args0));
4314 CHECK_EQ(0, a0->Length()); 4301 CHECK_EQ(0, a0->Length());
4315 4302
4316 v8::Handle<Value> args1[] = { v8_num(1.1) }; 4303 v8::Handle<Value> args1[] = { v8_num(1.1) };
4317 Local<v8::Array> a1 = Local<v8::Array>::Cast(Foo->Call(Foo, 1, args1)); 4304 Local<v8::Array> a1 = Local<v8::Array>::Cast(Foo->Call(Foo, 1, args1));
4318 CHECK_EQ(1, a1->Length()); 4305 CHECK_EQ(1, a1->Length());
4319 CHECK_EQ(1.1, a1->Get(v8::Integer::New(isolate, 0))->NumberValue()); 4306 CHECK_EQ(1.1, a1->Get(v8::Integer::New(0))->NumberValue());
4320 4307
4321 v8::Handle<Value> args2[] = { v8_num(2.2), 4308 v8::Handle<Value> args2[] = { v8_num(2.2),
4322 v8_num(3.3) }; 4309 v8_num(3.3) };
4323 Local<v8::Array> a2 = Local<v8::Array>::Cast(Foo->Call(Foo, 2, args2)); 4310 Local<v8::Array> a2 = Local<v8::Array>::Cast(Foo->Call(Foo, 2, args2));
4324 CHECK_EQ(2, a2->Length()); 4311 CHECK_EQ(2, a2->Length());
4325 CHECK_EQ(2.2, a2->Get(v8::Integer::New(isolate, 0))->NumberValue()); 4312 CHECK_EQ(2.2, a2->Get(v8::Integer::New(0))->NumberValue());
4326 CHECK_EQ(3.3, a2->Get(v8::Integer::New(isolate, 1))->NumberValue()); 4313 CHECK_EQ(3.3, a2->Get(v8::Integer::New(1))->NumberValue());
4327 4314
4328 v8::Handle<Value> args3[] = { v8_num(4.4), 4315 v8::Handle<Value> args3[] = { v8_num(4.4),
4329 v8_num(5.5), 4316 v8_num(5.5),
4330 v8_num(6.6) }; 4317 v8_num(6.6) };
4331 Local<v8::Array> a3 = Local<v8::Array>::Cast(Foo->Call(Foo, 3, args3)); 4318 Local<v8::Array> a3 = Local<v8::Array>::Cast(Foo->Call(Foo, 3, args3));
4332 CHECK_EQ(3, a3->Length()); 4319 CHECK_EQ(3, a3->Length());
4333 CHECK_EQ(4.4, a3->Get(v8::Integer::New(isolate, 0))->NumberValue()); 4320 CHECK_EQ(4.4, a3->Get(v8::Integer::New(0))->NumberValue());
4334 CHECK_EQ(5.5, a3->Get(v8::Integer::New(isolate, 1))->NumberValue()); 4321 CHECK_EQ(5.5, a3->Get(v8::Integer::New(1))->NumberValue());
4335 CHECK_EQ(6.6, a3->Get(v8::Integer::New(isolate, 2))->NumberValue()); 4322 CHECK_EQ(6.6, a3->Get(v8::Integer::New(2))->NumberValue());
4336 4323
4337 v8::Handle<Value> args4[] = { v8_num(7.7), 4324 v8::Handle<Value> args4[] = { v8_num(7.7),
4338 v8_num(8.8), 4325 v8_num(8.8),
4339 v8_num(9.9), 4326 v8_num(9.9),
4340 v8_num(10.11) }; 4327 v8_num(10.11) };
4341 Local<v8::Array> a4 = Local<v8::Array>::Cast(Foo->Call(Foo, 4, args4)); 4328 Local<v8::Array> a4 = Local<v8::Array>::Cast(Foo->Call(Foo, 4, args4));
4342 CHECK_EQ(4, a4->Length()); 4329 CHECK_EQ(4, a4->Length());
4343 CHECK_EQ(7.7, a4->Get(v8::Integer::New(isolate, 0))->NumberValue()); 4330 CHECK_EQ(7.7, a4->Get(v8::Integer::New(0))->NumberValue());
4344 CHECK_EQ(8.8, a4->Get(v8::Integer::New(isolate, 1))->NumberValue()); 4331 CHECK_EQ(8.8, a4->Get(v8::Integer::New(1))->NumberValue());
4345 CHECK_EQ(9.9, a4->Get(v8::Integer::New(isolate, 2))->NumberValue()); 4332 CHECK_EQ(9.9, a4->Get(v8::Integer::New(2))->NumberValue());
4346 CHECK_EQ(10.11, a4->Get(v8::Integer::New(isolate, 3))->NumberValue()); 4333 CHECK_EQ(10.11, a4->Get(v8::Integer::New(3))->NumberValue());
4347 4334
4348 Local<v8::Value> r1 = ReturnThisSloppy->Call(v8::Undefined(isolate), 0, NULL); 4335 Local<v8::Value> r1 = ReturnThisSloppy->Call(v8::Undefined(isolate), 0, NULL);
4349 CHECK(r1->StrictEquals(context->Global())); 4336 CHECK(r1->StrictEquals(context->Global()));
4350 Local<v8::Value> r2 = ReturnThisSloppy->Call(v8::Null(isolate), 0, NULL); 4337 Local<v8::Value> r2 = ReturnThisSloppy->Call(v8::Null(isolate), 0, NULL);
4351 CHECK(r2->StrictEquals(context->Global())); 4338 CHECK(r2->StrictEquals(context->Global()));
4352 Local<v8::Value> r3 = ReturnThisSloppy->Call(v8_num(42), 0, NULL); 4339 Local<v8::Value> r3 = ReturnThisSloppy->Call(v8_num(42), 0, NULL);
4353 CHECK(r3->IsNumberObject()); 4340 CHECK(r3->IsNumberObject());
4354 CHECK_EQ(42.0, r3.As<v8::NumberObject>()->ValueOf()); 4341 CHECK_EQ(42.0, r3.As<v8::NumberObject>()->ValueOf());
4355 Local<v8::Value> r4 = ReturnThisSloppy->Call(v8_str("hello"), 0, NULL); 4342 Local<v8::Value> r4 = ReturnThisSloppy->Call(v8_str("hello"), 0, NULL);
4356 CHECK(r4->IsStringObject()); 4343 CHECK(r4->IsStringObject());
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
4473 CompileRun( 4460 CompileRun(
4474 "var str = Array.prototype.join.call({length: 513}, \"A\").toUpperCase();" 4461 "var str = Array.prototype.join.call({length: 513}, \"A\").toUpperCase();"
4475 "for (var i = 0; i < 22; i++) { str = str + str; }"); 4462 "for (var i = 0; i < 22; i++) { str = str + str; }");
4476 4463
4477 CHECK(false); // Should not return. 4464 CHECK(false); // Should not return.
4478 } 4465 }
4479 4466
4480 4467
4481 THREADED_TEST(ConstructCall) { 4468 THREADED_TEST(ConstructCall) {
4482 LocalContext context; 4469 LocalContext context;
4483 v8::Isolate* isolate = context->GetIsolate(); 4470 v8::HandleScope scope(context->GetIsolate());
4484 v8::HandleScope scope(isolate);
4485 CompileRun( 4471 CompileRun(
4486 "function Foo() {" 4472 "function Foo() {"
4487 " var result = [];" 4473 " var result = [];"
4488 " for (var i = 0; i < arguments.length; i++) {" 4474 " for (var i = 0; i < arguments.length; i++) {"
4489 " result.push(arguments[i]);" 4475 " result.push(arguments[i]);"
4490 " }" 4476 " }"
4491 " return result;" 4477 " return result;"
4492 "}"); 4478 "}");
4493 Local<Function> Foo = 4479 Local<Function> Foo =
4494 Local<Function>::Cast(context->Global()->Get(v8_str("Foo"))); 4480 Local<Function>::Cast(context->Global()->Get(v8_str("Foo")));
4495 4481
4496 v8::Handle<Value>* args0 = NULL; 4482 v8::Handle<Value>* args0 = NULL;
4497 Local<v8::Array> a0 = Local<v8::Array>::Cast(Foo->NewInstance(0, args0)); 4483 Local<v8::Array> a0 = Local<v8::Array>::Cast(Foo->NewInstance(0, args0));
4498 CHECK_EQ(0, a0->Length()); 4484 CHECK_EQ(0, a0->Length());
4499 4485
4500 v8::Handle<Value> args1[] = { v8_num(1.1) }; 4486 v8::Handle<Value> args1[] = { v8_num(1.1) };
4501 Local<v8::Array> a1 = Local<v8::Array>::Cast(Foo->NewInstance(1, args1)); 4487 Local<v8::Array> a1 = Local<v8::Array>::Cast(Foo->NewInstance(1, args1));
4502 CHECK_EQ(1, a1->Length()); 4488 CHECK_EQ(1, a1->Length());
4503 CHECK_EQ(1.1, a1->Get(v8::Integer::New(isolate, 0))->NumberValue()); 4489 CHECK_EQ(1.1, a1->Get(v8::Integer::New(0))->NumberValue());
4504 4490
4505 v8::Handle<Value> args2[] = { v8_num(2.2), 4491 v8::Handle<Value> args2[] = { v8_num(2.2),
4506 v8_num(3.3) }; 4492 v8_num(3.3) };
4507 Local<v8::Array> a2 = Local<v8::Array>::Cast(Foo->NewInstance(2, args2)); 4493 Local<v8::Array> a2 = Local<v8::Array>::Cast(Foo->NewInstance(2, args2));
4508 CHECK_EQ(2, a2->Length()); 4494 CHECK_EQ(2, a2->Length());
4509 CHECK_EQ(2.2, a2->Get(v8::Integer::New(isolate, 0))->NumberValue()); 4495 CHECK_EQ(2.2, a2->Get(v8::Integer::New(0))->NumberValue());
4510 CHECK_EQ(3.3, a2->Get(v8::Integer::New(isolate, 1))->NumberValue()); 4496 CHECK_EQ(3.3, a2->Get(v8::Integer::New(1))->NumberValue());
4511 4497
4512 v8::Handle<Value> args3[] = { v8_num(4.4), 4498 v8::Handle<Value> args3[] = { v8_num(4.4),
4513 v8_num(5.5), 4499 v8_num(5.5),
4514 v8_num(6.6) }; 4500 v8_num(6.6) };
4515 Local<v8::Array> a3 = Local<v8::Array>::Cast(Foo->NewInstance(3, args3)); 4501 Local<v8::Array> a3 = Local<v8::Array>::Cast(Foo->NewInstance(3, args3));
4516 CHECK_EQ(3, a3->Length()); 4502 CHECK_EQ(3, a3->Length());
4517 CHECK_EQ(4.4, a3->Get(v8::Integer::New(isolate, 0))->NumberValue()); 4503 CHECK_EQ(4.4, a3->Get(v8::Integer::New(0))->NumberValue());
4518 CHECK_EQ(5.5, a3->Get(v8::Integer::New(isolate, 1))->NumberValue()); 4504 CHECK_EQ(5.5, a3->Get(v8::Integer::New(1))->NumberValue());
4519 CHECK_EQ(6.6, a3->Get(v8::Integer::New(isolate, 2))->NumberValue()); 4505 CHECK_EQ(6.6, a3->Get(v8::Integer::New(2))->NumberValue());
4520 4506
4521 v8::Handle<Value> args4[] = { v8_num(7.7), 4507 v8::Handle<Value> args4[] = { v8_num(7.7),
4522 v8_num(8.8), 4508 v8_num(8.8),
4523 v8_num(9.9), 4509 v8_num(9.9),
4524 v8_num(10.11) }; 4510 v8_num(10.11) };
4525 Local<v8::Array> a4 = Local<v8::Array>::Cast(Foo->NewInstance(4, args4)); 4511 Local<v8::Array> a4 = Local<v8::Array>::Cast(Foo->NewInstance(4, args4));
4526 CHECK_EQ(4, a4->Length()); 4512 CHECK_EQ(4, a4->Length());
4527 CHECK_EQ(7.7, a4->Get(v8::Integer::New(isolate, 0))->NumberValue()); 4513 CHECK_EQ(7.7, a4->Get(v8::Integer::New(0))->NumberValue());
4528 CHECK_EQ(8.8, a4->Get(v8::Integer::New(isolate, 1))->NumberValue()); 4514 CHECK_EQ(8.8, a4->Get(v8::Integer::New(1))->NumberValue());
4529 CHECK_EQ(9.9, a4->Get(v8::Integer::New(isolate, 2))->NumberValue()); 4515 CHECK_EQ(9.9, a4->Get(v8::Integer::New(2))->NumberValue());
4530 CHECK_EQ(10.11, a4->Get(v8::Integer::New(isolate, 3))->NumberValue()); 4516 CHECK_EQ(10.11, a4->Get(v8::Integer::New(3))->NumberValue());
4531 } 4517 }
4532 4518
4533 4519
4534 static void CheckUncle(v8::TryCatch* try_catch) { 4520 static void CheckUncle(v8::TryCatch* try_catch) {
4535 CHECK(try_catch->HasCaught()); 4521 CHECK(try_catch->HasCaught());
4536 String::Utf8Value str_value(try_catch->Exception()); 4522 String::Utf8Value str_value(try_catch->Exception());
4537 CHECK_EQ(*str_value, "uncle?"); 4523 CHECK_EQ(*str_value, "uncle?");
4538 try_catch->Reset(); 4524 try_catch->Reset();
4539 } 4525 }
4540 4526
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
5134 "function Run(obj) {" 5120 "function Run(obj) {"
5135 " try {" 5121 " try {"
5136 " Throw(obj);" 5122 " Throw(obj);"
5137 " } catch (e) {" 5123 " } catch (e) {"
5138 " return e;" 5124 " return e;"
5139 " }" 5125 " }"
5140 " return 'no exception';" 5126 " return 'no exception';"
5141 "}" 5127 "}"
5142 "[Run('str'), Run(1), Run(0), Run(null), Run(void 0)];")); 5128 "[Run('str'), Run(1), Run(0), Run(null), Run(void 0)];"));
5143 CHECK_EQ(5, result->Length()); 5129 CHECK_EQ(5, result->Length());
5144 CHECK(result->Get(v8::Integer::New(isolate, 0))->IsString()); 5130 CHECK(result->Get(v8::Integer::New(0))->IsString());
5145 CHECK(result->Get(v8::Integer::New(isolate, 1))->IsNumber()); 5131 CHECK(result->Get(v8::Integer::New(1))->IsNumber());
5146 CHECK_EQ(1, result->Get(v8::Integer::New(isolate, 1))->Int32Value()); 5132 CHECK_EQ(1, result->Get(v8::Integer::New(1))->Int32Value());
5147 CHECK(result->Get(v8::Integer::New(isolate, 2))->IsNumber()); 5133 CHECK(result->Get(v8::Integer::New(2))->IsNumber());
5148 CHECK_EQ(0, result->Get(v8::Integer::New(isolate, 2))->Int32Value()); 5134 CHECK_EQ(0, result->Get(v8::Integer::New(2))->Int32Value());
5149 CHECK(result->Get(v8::Integer::New(isolate, 3))->IsNull()); 5135 CHECK(result->Get(v8::Integer::New(3))->IsNull());
5150 CHECK(result->Get(v8::Integer::New(isolate, 4))->IsUndefined()); 5136 CHECK(result->Get(v8::Integer::New(4))->IsUndefined());
5151 } 5137 }
5152 5138
5153 5139
5154 THREADED_TEST(CatchZero) { 5140 THREADED_TEST(CatchZero) {
5155 LocalContext context; 5141 LocalContext context;
5156 v8::HandleScope scope(context->GetIsolate()); 5142 v8::HandleScope scope(context->GetIsolate());
5157 v8::TryCatch try_catch; 5143 v8::TryCatch try_catch;
5158 CHECK(!try_catch.HasCaught()); 5144 CHECK(!try_catch.HasCaught());
5159 Script::Compile(v8_str("throw 10"))->Run(); 5145 Script::Compile(v8_str("throw 10"))->Run();
5160 CHECK(try_catch.HasCaught()); 5146 CHECK(try_catch.HasCaught());
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
5297 CHECK(!v8_str("a")->StrictEquals(v8_str("b"))); 5283 CHECK(!v8_str("a")->StrictEquals(v8_str("b")));
5298 CHECK(!v8_str("5")->StrictEquals(v8_num(5))); 5284 CHECK(!v8_str("5")->StrictEquals(v8_num(5)));
5299 CHECK(v8_num(1)->StrictEquals(v8_num(1))); 5285 CHECK(v8_num(1)->StrictEquals(v8_num(1)));
5300 CHECK(!v8_num(1)->StrictEquals(v8_num(2))); 5286 CHECK(!v8_num(1)->StrictEquals(v8_num(2)));
5301 CHECK(v8_num(0.0)->StrictEquals(v8_num(-0.0))); 5287 CHECK(v8_num(0.0)->StrictEquals(v8_num(-0.0)));
5302 Local<Value> not_a_number = v8_num(i::OS::nan_value()); 5288 Local<Value> not_a_number = v8_num(i::OS::nan_value());
5303 CHECK(!not_a_number->StrictEquals(not_a_number)); 5289 CHECK(!not_a_number->StrictEquals(not_a_number));
5304 CHECK(v8::False(isolate)->StrictEquals(v8::False(isolate))); 5290 CHECK(v8::False(isolate)->StrictEquals(v8::False(isolate)));
5305 CHECK(!v8::False(isolate)->StrictEquals(v8::Undefined(isolate))); 5291 CHECK(!v8::False(isolate)->StrictEquals(v8::Undefined(isolate)));
5306 5292
5307 v8::Handle<v8::Object> obj = v8::Object::New(isolate); 5293 v8::Handle<v8::Object> obj = v8::Object::New();
5308 v8::Persistent<v8::Object> alias(isolate, obj); 5294 v8::Persistent<v8::Object> alias(isolate, obj);
5309 CHECK(v8::Local<v8::Object>::New(isolate, alias)->StrictEquals(obj)); 5295 CHECK(v8::Local<v8::Object>::New(isolate, alias)->StrictEquals(obj));
5310 alias.Reset(); 5296 alias.Reset();
5311 5297
5312 CHECK(v8_str("a")->SameValue(v8_str("a"))); 5298 CHECK(v8_str("a")->SameValue(v8_str("a")));
5313 CHECK(!v8_str("a")->SameValue(v8_str("b"))); 5299 CHECK(!v8_str("a")->SameValue(v8_str("b")));
5314 CHECK(!v8_str("5")->SameValue(v8_num(5))); 5300 CHECK(!v8_str("5")->SameValue(v8_num(5)));
5315 CHECK(v8_num(1)->SameValue(v8_num(1))); 5301 CHECK(v8_num(1)->SameValue(v8_num(1)));
5316 CHECK(!v8_num(1)->SameValue(v8_num(2))); 5302 CHECK(!v8_num(1)->SameValue(v8_num(2)));
5317 CHECK(!v8_num(0.0)->SameValue(v8_num(-0.0))); 5303 CHECK(!v8_num(0.0)->SameValue(v8_num(-0.0)));
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
5760 CompileRun("var obj = { x : 0 }; delete obj.x;"); 5746 CompileRun("var obj = { x : 0 }; delete obj.x;");
5761 context1->Exit(); 5747 context1->Exit();
5762 } 5748 }
5763 5749
5764 5750
5765 static void SetXOnPrototypeGetter( 5751 static void SetXOnPrototypeGetter(
5766 Local<String> property, 5752 Local<String> property,
5767 const v8::PropertyCallbackInfo<v8::Value>& info) { 5753 const v8::PropertyCallbackInfo<v8::Value>& info) {
5768 // Set x on the prototype object and do not handle the get request. 5754 // Set x on the prototype object and do not handle the get request.
5769 v8::Handle<v8::Value> proto = info.Holder()->GetPrototype(); 5755 v8::Handle<v8::Value> proto = info.Holder()->GetPrototype();
5770 proto.As<v8::Object>()->Set(v8_str("x"), 5756 proto.As<v8::Object>()->Set(v8_str("x"), v8::Integer::New(23));
5771 v8::Integer::New(info.GetIsolate(), 23));
5772 } 5757 }
5773 5758
5774 5759
5775 // This is a regression test for http://crbug.com/20104. Map 5760 // This is a regression test for http://crbug.com/20104. Map
5776 // transitions should not interfere with post interceptor lookup. 5761 // transitions should not interfere with post interceptor lookup.
5777 THREADED_TEST(NamedInterceptorMapTransitionRead) { 5762 THREADED_TEST(NamedInterceptorMapTransitionRead) {
5778 v8::Isolate* isolate = CcTest::isolate(); 5763 v8::Isolate* isolate = CcTest::isolate();
5779 v8::HandleScope scope(isolate); 5764 v8::HandleScope scope(isolate);
5780 Local<v8::FunctionTemplate> function_template = 5765 Local<v8::FunctionTemplate> function_template =
5781 v8::FunctionTemplate::New(isolate); 5766 v8::FunctionTemplate::New(isolate);
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after
6418 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable 6403 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable
6419 6404
6420 Local<v8::Object> obj = desc->GetFunction()->NewInstance(); 6405 Local<v8::Object> obj = desc->GetFunction()->NewInstance();
6421 env->Global()->Set(v8_str("undetectable"), obj); 6406 env->Global()->Set(v8_str("undetectable"), obj);
6422 6407
6423 Local<String> source = v8_str("undetectable.x = 42;" 6408 Local<String> source = v8_str("undetectable.x = 42;"
6424 "undetectable.x"); 6409 "undetectable.x");
6425 6410
6426 Local<Script> script = Script::Compile(source); 6411 Local<Script> script = Script::Compile(source);
6427 6412
6428 CHECK_EQ(v8::Integer::New(isolate, 42), script->Run()); 6413 CHECK_EQ(v8::Integer::New(42), script->Run());
6429 6414
6430 ExpectBoolean("Object.isExtensible(undetectable)", true); 6415 ExpectBoolean("Object.isExtensible(undetectable)", true);
6431 6416
6432 source = v8_str("Object.preventExtensions(undetectable);"); 6417 source = v8_str("Object.preventExtensions(undetectable);");
6433 script = Script::Compile(source); 6418 script = Script::Compile(source);
6434 script->Run(); 6419 script->Run();
6435 ExpectBoolean("Object.isExtensible(undetectable)", false); 6420 ExpectBoolean("Object.isExtensible(undetectable)", false);
6436 6421
6437 source = v8_str("undetectable.y = 2000;"); 6422 source = v8_str("undetectable.y = 2000;");
6438 script = Script::Compile(source); 6423 script = Script::Compile(source);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
6563 6548
6564 THREADED_TEST(SimpleExtensions) { 6549 THREADED_TEST(SimpleExtensions) {
6565 v8::HandleScope handle_scope(CcTest::isolate()); 6550 v8::HandleScope handle_scope(CcTest::isolate());
6566 v8::RegisterExtension(new Extension("simpletest", kSimpleExtensionSource)); 6551 v8::RegisterExtension(new Extension("simpletest", kSimpleExtensionSource));
6567 const char* extension_names[] = { "simpletest" }; 6552 const char* extension_names[] = { "simpletest" };
6568 v8::ExtensionConfiguration extensions(1, extension_names); 6553 v8::ExtensionConfiguration extensions(1, extension_names);
6569 v8::Handle<Context> context = 6554 v8::Handle<Context> context =
6570 Context::New(CcTest::isolate(), &extensions); 6555 Context::New(CcTest::isolate(), &extensions);
6571 Context::Scope lock(context); 6556 Context::Scope lock(context);
6572 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run(); 6557 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run();
6573 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 4)); 6558 CHECK_EQ(result, v8::Integer::New(4));
6574 } 6559 }
6575 6560
6576 6561
6577 THREADED_TEST(NullExtensions) { 6562 THREADED_TEST(NullExtensions) {
6578 v8::HandleScope handle_scope(CcTest::isolate()); 6563 v8::HandleScope handle_scope(CcTest::isolate());
6579 v8::RegisterExtension(new Extension("nulltest", NULL)); 6564 v8::RegisterExtension(new Extension("nulltest", NULL));
6580 const char* extension_names[] = { "nulltest" }; 6565 const char* extension_names[] = { "nulltest" };
6581 v8::ExtensionConfiguration extensions(1, extension_names); 6566 v8::ExtensionConfiguration extensions(1, extension_names);
6582 v8::Handle<Context> context = 6567 v8::Handle<Context> context =
6583 Context::New(CcTest::isolate(), &extensions); 6568 Context::New(CcTest::isolate(), &extensions);
6584 Context::Scope lock(context); 6569 Context::Scope lock(context);
6585 v8::Handle<Value> result = Script::Compile(v8_str("1+3"))->Run(); 6570 v8::Handle<Value> result = Script::Compile(v8_str("1+3"))->Run();
6586 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 4)); 6571 CHECK_EQ(result, v8::Integer::New(4));
6587 } 6572 }
6588 6573
6589 6574
6590 static const char* kEmbeddedExtensionSource = 6575 static const char* kEmbeddedExtensionSource =
6591 "function Ret54321(){return 54321;}~~@@$" 6576 "function Ret54321(){return 54321;}~~@@$"
6592 "$%% THIS IS A SERIES OF NON-NULL-TERMINATED STRINGS."; 6577 "$%% THIS IS A SERIES OF NON-NULL-TERMINATED STRINGS.";
6593 static const int kEmbeddedExtensionSourceValidLen = 34; 6578 static const int kEmbeddedExtensionSourceValidLen = 34;
6594 6579
6595 6580
6596 THREADED_TEST(ExtensionMissingSourceLength) { 6581 THREADED_TEST(ExtensionMissingSourceLength) {
(...skipping 17 matching lines...) Expand all
6614 v8::RegisterExtension(new Extension(extension_name.start(), 6599 v8::RegisterExtension(new Extension(extension_name.start(),
6615 kEmbeddedExtensionSource, 0, 0, 6600 kEmbeddedExtensionSource, 0, 0,
6616 source_len)); 6601 source_len));
6617 const char* extension_names[1] = { extension_name.start() }; 6602 const char* extension_names[1] = { extension_name.start() };
6618 v8::ExtensionConfiguration extensions(1, extension_names); 6603 v8::ExtensionConfiguration extensions(1, extension_names);
6619 v8::Handle<Context> context = 6604 v8::Handle<Context> context =
6620 Context::New(CcTest::isolate(), &extensions); 6605 Context::New(CcTest::isolate(), &extensions);
6621 if (source_len == kEmbeddedExtensionSourceValidLen) { 6606 if (source_len == kEmbeddedExtensionSourceValidLen) {
6622 Context::Scope lock(context); 6607 Context::Scope lock(context);
6623 v8::Handle<Value> result = Script::Compile(v8_str("Ret54321()"))->Run(); 6608 v8::Handle<Value> result = Script::Compile(v8_str("Ret54321()"))->Run();
6624 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 54321), result); 6609 CHECK_EQ(v8::Integer::New(54321), result);
6625 } else { 6610 } else {
6626 // Anything but exactly the right length should fail to compile. 6611 // Anything but exactly the right length should fail to compile.
6627 CHECK_EQ(0, *context); 6612 CHECK_EQ(0, *context);
6628 } 6613 }
6629 } 6614 }
6630 } 6615 }
6631 6616
6632 6617
6633 static const char* kEvalExtensionSource1 = 6618 static const char* kEvalExtensionSource1 =
6634 "function UseEval1() {" 6619 "function UseEval1() {"
(...skipping 15 matching lines...) Expand all
6650 THREADED_TEST(UseEvalFromExtension) { 6635 THREADED_TEST(UseEvalFromExtension) {
6651 v8::HandleScope handle_scope(CcTest::isolate()); 6636 v8::HandleScope handle_scope(CcTest::isolate());
6652 v8::RegisterExtension(new Extension("evaltest1", kEvalExtensionSource1)); 6637 v8::RegisterExtension(new Extension("evaltest1", kEvalExtensionSource1));
6653 v8::RegisterExtension(new Extension("evaltest2", kEvalExtensionSource2)); 6638 v8::RegisterExtension(new Extension("evaltest2", kEvalExtensionSource2));
6654 const char* extension_names[] = { "evaltest1", "evaltest2" }; 6639 const char* extension_names[] = { "evaltest1", "evaltest2" };
6655 v8::ExtensionConfiguration extensions(2, extension_names); 6640 v8::ExtensionConfiguration extensions(2, extension_names);
6656 v8::Handle<Context> context = 6641 v8::Handle<Context> context =
6657 Context::New(CcTest::isolate(), &extensions); 6642 Context::New(CcTest::isolate(), &extensions);
6658 Context::Scope lock(context); 6643 Context::Scope lock(context);
6659 v8::Handle<Value> result = Script::Compile(v8_str("UseEval1()"))->Run(); 6644 v8::Handle<Value> result = Script::Compile(v8_str("UseEval1()"))->Run();
6660 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 42)); 6645 CHECK_EQ(result, v8::Integer::New(42));
6661 result = Script::Compile(v8_str("UseEval2()"))->Run(); 6646 result = Script::Compile(v8_str("UseEval2()"))->Run();
6662 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 42)); 6647 CHECK_EQ(result, v8::Integer::New(42));
6663 } 6648 }
6664 6649
6665 6650
6666 static const char* kWithExtensionSource1 = 6651 static const char* kWithExtensionSource1 =
6667 "function UseWith1() {" 6652 "function UseWith1() {"
6668 " var x = 42;" 6653 " var x = 42;"
6669 " with({x:87}) { return x; }" 6654 " with({x:87}) { return x; }"
6670 "}"; 6655 "}";
6671 6656
6672 6657
(...skipping 11 matching lines...) Expand all
6684 THREADED_TEST(UseWithFromExtension) { 6669 THREADED_TEST(UseWithFromExtension) {
6685 v8::HandleScope handle_scope(CcTest::isolate()); 6670 v8::HandleScope handle_scope(CcTest::isolate());
6686 v8::RegisterExtension(new Extension("withtest1", kWithExtensionSource1)); 6671 v8::RegisterExtension(new Extension("withtest1", kWithExtensionSource1));
6687 v8::RegisterExtension(new Extension("withtest2", kWithExtensionSource2)); 6672 v8::RegisterExtension(new Extension("withtest2", kWithExtensionSource2));
6688 const char* extension_names[] = { "withtest1", "withtest2" }; 6673 const char* extension_names[] = { "withtest1", "withtest2" };
6689 v8::ExtensionConfiguration extensions(2, extension_names); 6674 v8::ExtensionConfiguration extensions(2, extension_names);
6690 v8::Handle<Context> context = 6675 v8::Handle<Context> context =
6691 Context::New(CcTest::isolate(), &extensions); 6676 Context::New(CcTest::isolate(), &extensions);
6692 Context::Scope lock(context); 6677 Context::Scope lock(context);
6693 v8::Handle<Value> result = Script::Compile(v8_str("UseWith1()"))->Run(); 6678 v8::Handle<Value> result = Script::Compile(v8_str("UseWith1()"))->Run();
6694 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 87)); 6679 CHECK_EQ(result, v8::Integer::New(87));
6695 result = Script::Compile(v8_str("UseWith2()"))->Run(); 6680 result = Script::Compile(v8_str("UseWith2()"))->Run();
6696 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 87)); 6681 CHECK_EQ(result, v8::Integer::New(87));
6697 } 6682 }
6698 6683
6699 6684
6700 THREADED_TEST(AutoExtensions) { 6685 THREADED_TEST(AutoExtensions) {
6701 v8::HandleScope handle_scope(CcTest::isolate()); 6686 v8::HandleScope handle_scope(CcTest::isolate());
6702 Extension* extension = new Extension("autotest", kSimpleExtensionSource); 6687 Extension* extension = new Extension("autotest", kSimpleExtensionSource);
6703 extension->set_auto_enable(true); 6688 extension->set_auto_enable(true);
6704 v8::RegisterExtension(extension); 6689 v8::RegisterExtension(extension);
6705 v8::Handle<Context> context = 6690 v8::Handle<Context> context =
6706 Context::New(CcTest::isolate()); 6691 Context::New(CcTest::isolate());
6707 Context::Scope lock(context); 6692 Context::Scope lock(context);
6708 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run(); 6693 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run();
6709 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 4)); 6694 CHECK_EQ(result, v8::Integer::New(4));
6710 } 6695 }
6711 6696
6712 6697
6713 static const char* kSyntaxErrorInExtensionSource = 6698 static const char* kSyntaxErrorInExtensionSource =
6714 "["; 6699 "[";
6715 6700
6716 6701
6717 // Test that a syntax error in an extension does not cause a fatal 6702 // Test that a syntax error in an extension does not cause a fatal
6718 // error but results in an empty context. 6703 // error but results in an empty context.
6719 THREADED_TEST(SyntaxErrorExtensions) { 6704 THREADED_TEST(SyntaxErrorExtensions) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
6759 THREADED_TEST(NativeCallInExtensions) { 6744 THREADED_TEST(NativeCallInExtensions) {
6760 v8::HandleScope handle_scope(CcTest::isolate()); 6745 v8::HandleScope handle_scope(CcTest::isolate());
6761 v8::RegisterExtension(new Extension("nativecall", 6746 v8::RegisterExtension(new Extension("nativecall",
6762 kNativeCallInExtensionSource)); 6747 kNativeCallInExtensionSource));
6763 const char* extension_names[] = { "nativecall" }; 6748 const char* extension_names[] = { "nativecall" };
6764 v8::ExtensionConfiguration extensions(1, extension_names); 6749 v8::ExtensionConfiguration extensions(1, extension_names);
6765 v8::Handle<Context> context = 6750 v8::Handle<Context> context =
6766 Context::New(CcTest::isolate(), &extensions); 6751 Context::New(CcTest::isolate(), &extensions);
6767 Context::Scope lock(context); 6752 Context::Scope lock(context);
6768 v8::Handle<Value> result = Script::Compile(v8_str(kNativeCallTest))->Run(); 6753 v8::Handle<Value> result = Script::Compile(v8_str(kNativeCallTest))->Run();
6769 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 3)); 6754 CHECK_EQ(result, v8::Integer::New(3));
6770 } 6755 }
6771 6756
6772 6757
6773 class NativeFunctionExtension : public Extension { 6758 class NativeFunctionExtension : public Extension {
6774 public: 6759 public:
6775 NativeFunctionExtension(const char* name, 6760 NativeFunctionExtension(const char* name,
6776 const char* source, 6761 const char* source,
6777 v8::FunctionCallback fun = &Echo) 6762 v8::FunctionCallback fun = &Echo)
6778 : Extension(name, source), 6763 : Extension(name, source),
6779 function_(fun) { } 6764 function_(fun) { }
(...skipping 16 matching lines...) Expand all
6796 v8::HandleScope handle_scope(CcTest::isolate()); 6781 v8::HandleScope handle_scope(CcTest::isolate());
6797 const char* name = "nativedecl"; 6782 const char* name = "nativedecl";
6798 v8::RegisterExtension(new NativeFunctionExtension(name, 6783 v8::RegisterExtension(new NativeFunctionExtension(name,
6799 "native function foo();")); 6784 "native function foo();"));
6800 const char* extension_names[] = { name }; 6785 const char* extension_names[] = { name };
6801 v8::ExtensionConfiguration extensions(1, extension_names); 6786 v8::ExtensionConfiguration extensions(1, extension_names);
6802 v8::Handle<Context> context = 6787 v8::Handle<Context> context =
6803 Context::New(CcTest::isolate(), &extensions); 6788 Context::New(CcTest::isolate(), &extensions);
6804 Context::Scope lock(context); 6789 Context::Scope lock(context);
6805 v8::Handle<Value> result = Script::Compile(v8_str("foo(42);"))->Run(); 6790 v8::Handle<Value> result = Script::Compile(v8_str("foo(42);"))->Run();
6806 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 42)); 6791 CHECK_EQ(result, v8::Integer::New(42));
6807 } 6792 }
6808 6793
6809 6794
6810 THREADED_TEST(NativeFunctionDeclarationError) { 6795 THREADED_TEST(NativeFunctionDeclarationError) {
6811 v8::HandleScope handle_scope(CcTest::isolate()); 6796 v8::HandleScope handle_scope(CcTest::isolate());
6812 const char* name = "nativedeclerr"; 6797 const char* name = "nativedeclerr";
6813 // Syntax error in extension code. 6798 // Syntax error in extension code.
6814 v8::RegisterExtension(new NativeFunctionExtension(name, 6799 v8::RegisterExtension(new NativeFunctionExtension(name,
6815 "native\nfunction foo();")); 6800 "native\nfunction foo();"));
6816 const char* extension_names[] = { name }; 6801 const char* extension_names[] = { name };
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
6904 v8::Isolate* isolate, 6889 v8::Isolate* isolate,
6905 v8::Handle<String> name); 6890 v8::Handle<String> name);
6906 }; 6891 };
6907 6892
6908 6893
6909 static int lookup_count = 0; 6894 static int lookup_count = 0;
6910 v8::Handle<v8::FunctionTemplate> FunctionExtension::GetNativeFunctionTemplate( 6895 v8::Handle<v8::FunctionTemplate> FunctionExtension::GetNativeFunctionTemplate(
6911 v8::Isolate* isolate, v8::Handle<String> name) { 6896 v8::Isolate* isolate, v8::Handle<String> name) {
6912 lookup_count++; 6897 lookup_count++;
6913 if (name->Equals(v8_str("A"))) { 6898 if (name->Equals(v8_str("A"))) {
6914 return v8::FunctionTemplate::New( 6899 return v8::FunctionTemplate::New(isolate, CallFun, v8::Integer::New(8));
6915 isolate, CallFun, v8::Integer::New(isolate, 8));
6916 } else if (name->Equals(v8_str("B"))) { 6900 } else if (name->Equals(v8_str("B"))) {
6917 return v8::FunctionTemplate::New( 6901 return v8::FunctionTemplate::New(isolate, CallFun, v8::Integer::New(7));
6918 isolate, CallFun, v8::Integer::New(isolate, 7));
6919 } else if (name->Equals(v8_str("C"))) { 6902 } else if (name->Equals(v8_str("C"))) {
6920 return v8::FunctionTemplate::New( 6903 return v8::FunctionTemplate::New(isolate, CallFun, v8::Integer::New(6));
6921 isolate, CallFun, v8::Integer::New(isolate, 6));
6922 } else { 6904 } else {
6923 return v8::Handle<v8::FunctionTemplate>(); 6905 return v8::Handle<v8::FunctionTemplate>();
6924 } 6906 }
6925 } 6907 }
6926 6908
6927 6909
6928 THREADED_TEST(FunctionLookup) { 6910 THREADED_TEST(FunctionLookup) {
6929 v8::RegisterExtension(new FunctionExtension()); 6911 v8::RegisterExtension(new FunctionExtension());
6930 v8::HandleScope handle_scope(CcTest::isolate()); 6912 v8::HandleScope handle_scope(CcTest::isolate());
6931 static const char* exts[1] = { "functiontest" }; 6913 static const char* exts[1] = { "functiontest" };
6932 v8::ExtensionConfiguration config(1, exts); 6914 v8::ExtensionConfiguration config(1, exts);
6933 LocalContext context(&config); 6915 LocalContext context(&config);
6934 CHECK_EQ(3, lookup_count); 6916 CHECK_EQ(3, lookup_count);
6935 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 8), 6917 CHECK_EQ(v8::Integer::New(8), Script::Compile(v8_str("Foo(0)"))->Run());
6936 Script::Compile(v8_str("Foo(0)"))->Run()); 6918 CHECK_EQ(v8::Integer::New(7), Script::Compile(v8_str("Foo(1)"))->Run());
6937 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 7), 6919 CHECK_EQ(v8::Integer::New(6), Script::Compile(v8_str("Foo(2)"))->Run());
6938 Script::Compile(v8_str("Foo(1)"))->Run());
6939 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 6),
6940 Script::Compile(v8_str("Foo(2)"))->Run());
6941 } 6920 }
6942 6921
6943 6922
6944 THREADED_TEST(NativeFunctionConstructCall) { 6923 THREADED_TEST(NativeFunctionConstructCall) {
6945 v8::RegisterExtension(new FunctionExtension()); 6924 v8::RegisterExtension(new FunctionExtension());
6946 v8::HandleScope handle_scope(CcTest::isolate()); 6925 v8::HandleScope handle_scope(CcTest::isolate());
6947 static const char* exts[1] = { "functiontest" }; 6926 static const char* exts[1] = { "functiontest" };
6948 v8::ExtensionConfiguration config(1, exts); 6927 v8::ExtensionConfiguration config(1, exts);
6949 LocalContext context(&config); 6928 LocalContext context(&config);
6950 for (int i = 0; i < 10; i++) { 6929 for (int i = 0; i < 10; i++) {
6951 // Run a few times to ensure that allocation of objects doesn't 6930 // Run a few times to ensure that allocation of objects doesn't
6952 // change behavior of a constructor function. 6931 // change behavior of a constructor function.
6953 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 8), 6932 CHECK_EQ(v8::Integer::New(8),
6954 Script::Compile(v8_str("(new A()).data"))->Run()); 6933 Script::Compile(v8_str("(new A()).data"))->Run());
6955 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 7), 6934 CHECK_EQ(v8::Integer::New(7),
6956 Script::Compile(v8_str("(new B()).data"))->Run()); 6935 Script::Compile(v8_str("(new B()).data"))->Run());
6957 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 6), 6936 CHECK_EQ(v8::Integer::New(6),
6958 Script::Compile(v8_str("(new C()).data"))->Run()); 6937 Script::Compile(v8_str("(new C()).data"))->Run());
6959 } 6938 }
6960 } 6939 }
6961 6940
6962 6941
6963 static const char* last_location; 6942 static const char* last_location;
6964 static const char* last_message; 6943 static const char* last_message;
6965 void StoringErrorCallback(const char* location, const char* message) { 6944 void StoringErrorCallback(const char* location, const char* message) {
6966 if (last_location == NULL) { 6945 if (last_location == NULL) {
6967 last_location = location; 6946 last_location = location;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
7063 delete data.GetParameter(); 7042 delete data.GetParameter();
7064 } 7043 }
7065 7044
7066 void WhammyPropertyGetter(Local<String> name, 7045 void WhammyPropertyGetter(Local<String> name,
7067 const v8::PropertyCallbackInfo<v8::Value>& info) { 7046 const v8::PropertyCallbackInfo<v8::Value>& info) {
7068 Whammy* whammy = 7047 Whammy* whammy =
7069 static_cast<Whammy*>(v8::Handle<v8::External>::Cast(info.Data())->Value()); 7048 static_cast<Whammy*>(v8::Handle<v8::External>::Cast(info.Data())->Value());
7070 7049
7071 v8::Persistent<v8::Object>& prev = whammy->objects_[whammy->cursor_]; 7050 v8::Persistent<v8::Object>& prev = whammy->objects_[whammy->cursor_];
7072 7051
7073 v8::Handle<v8::Object> obj = v8::Object::New(info.GetIsolate()); 7052 v8::Handle<v8::Object> obj = v8::Object::New();
7074 if (!prev.IsEmpty()) { 7053 if (!prev.IsEmpty()) {
7075 v8::Local<v8::Object>::New(info.GetIsolate(), prev) 7054 v8::Local<v8::Object>::New(info.GetIsolate(), prev)
7076 ->Set(v8_str("next"), obj); 7055 ->Set(v8_str("next"), obj);
7077 prev.SetWeak<Value, Snorkel<Value> >(new Snorkel<Value>(&prev.As<Value>()), 7056 prev.SetWeak<Value, Snorkel<Value> >(new Snorkel<Value>(&prev.As<Value>()),
7078 &HandleWeakReference); 7057 &HandleWeakReference);
7079 } 7058 }
7080 whammy->objects_[whammy->cursor_].Reset(info.GetIsolate(), obj); 7059 whammy->objects_[whammy->cursor_].Reset(info.GetIsolate(), obj);
7081 whammy->cursor_ = (whammy->cursor_ + 1) % Whammy::kObjectCount; 7060 whammy->cursor_ = (whammy->cursor_ + 1) % Whammy::kObjectCount;
7082 info.GetReturnValue().Set(whammy->getScript()->Run()); 7061 info.GetReturnValue().Set(whammy->getScript()->Run());
7083 } 7062 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
7129 THREADED_TEST(IndependentWeakHandle) { 7108 THREADED_TEST(IndependentWeakHandle) {
7130 v8::Isolate* iso = CcTest::isolate(); 7109 v8::Isolate* iso = CcTest::isolate();
7131 v8::HandleScope scope(iso); 7110 v8::HandleScope scope(iso);
7132 v8::Handle<Context> context = Context::New(iso); 7111 v8::Handle<Context> context = Context::New(iso);
7133 Context::Scope context_scope(context); 7112 Context::Scope context_scope(context);
7134 7113
7135 FlagAndPersistent object_a, object_b; 7114 FlagAndPersistent object_a, object_b;
7136 7115
7137 { 7116 {
7138 v8::HandleScope handle_scope(iso); 7117 v8::HandleScope handle_scope(iso);
7139 object_a.handle.Reset(iso, v8::Object::New(iso)); 7118 object_a.handle.Reset(iso, v8::Object::New());
7140 object_b.handle.Reset(iso, v8::Object::New(iso)); 7119 object_b.handle.Reset(iso, v8::Object::New());
7141 } 7120 }
7142 7121
7143 object_a.flag = false; 7122 object_a.flag = false;
7144 object_b.flag = false; 7123 object_b.flag = false;
7145 object_a.handle.SetWeak(&object_a, &DisposeAndSetFlag); 7124 object_a.handle.SetWeak(&object_a, &DisposeAndSetFlag);
7146 object_b.handle.SetWeak(&object_b, &DisposeAndSetFlag); 7125 object_b.handle.SetWeak(&object_b, &DisposeAndSetFlag);
7147 CHECK(!object_b.handle.IsIndependent()); 7126 CHECK(!object_b.handle.IsIndependent());
7148 object_a.handle.MarkIndependent(); 7127 object_a.handle.MarkIndependent();
7149 object_b.handle.MarkIndependent(); 7128 object_b.handle.MarkIndependent();
7150 CHECK(object_b.handle.IsIndependent()); 7129 CHECK(object_b.handle.IsIndependent());
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
7193 {&ForceScavenge, &ForceMarkSweep}; 7172 {&ForceScavenge, &ForceMarkSweep};
7194 7173
7195 typedef void (*GCInvoker)(); 7174 typedef void (*GCInvoker)();
7196 GCInvoker invoke_gc[kNumberOfGCTypes] = {&InvokeScavenge, &InvokeMarkSweep}; 7175 GCInvoker invoke_gc[kNumberOfGCTypes] = {&InvokeScavenge, &InvokeMarkSweep};
7197 7176
7198 for (int outer_gc = 0; outer_gc < kNumberOfGCTypes; outer_gc++) { 7177 for (int outer_gc = 0; outer_gc < kNumberOfGCTypes; outer_gc++) {
7199 for (int inner_gc = 0; inner_gc < kNumberOfGCTypes; inner_gc++) { 7178 for (int inner_gc = 0; inner_gc < kNumberOfGCTypes; inner_gc++) {
7200 FlagAndPersistent object; 7179 FlagAndPersistent object;
7201 { 7180 {
7202 v8::HandleScope handle_scope(isolate); 7181 v8::HandleScope handle_scope(isolate);
7203 object.handle.Reset(isolate, v8::Object::New(isolate)); 7182 object.handle.Reset(isolate, v8::Object::New());
7204 } 7183 }
7205 object.flag = false; 7184 object.flag = false;
7206 object.handle.SetWeak(&object, gc_forcing_callback[inner_gc]); 7185 object.handle.SetWeak(&object, gc_forcing_callback[inner_gc]);
7207 object.handle.MarkIndependent(); 7186 object.handle.MarkIndependent();
7208 invoke_gc[outer_gc](); 7187 invoke_gc[outer_gc]();
7209 CHECK(object.flag); 7188 CHECK(object.flag);
7210 } 7189 }
7211 } 7190 }
7212 } 7191 }
7213 7192
7214 7193
7215 static void RevivingCallback( 7194 static void RevivingCallback(
7216 const v8::WeakCallbackData<v8::Object, FlagAndPersistent>& data) { 7195 const v8::WeakCallbackData<v8::Object, FlagAndPersistent>& data) {
7217 data.GetParameter()->handle.ClearWeak(); 7196 data.GetParameter()->handle.ClearWeak();
7218 data.GetParameter()->flag = true; 7197 data.GetParameter()->flag = true;
7219 } 7198 }
7220 7199
7221 7200
7222 THREADED_TEST(IndependentHandleRevival) { 7201 THREADED_TEST(IndependentHandleRevival) {
7223 v8::Isolate* isolate = CcTest::isolate(); 7202 v8::Isolate* isolate = CcTest::isolate();
7224 v8::HandleScope scope(isolate); 7203 v8::HandleScope scope(isolate);
7225 v8::Handle<Context> context = Context::New(isolate); 7204 v8::Handle<Context> context = Context::New(isolate);
7226 Context::Scope context_scope(context); 7205 Context::Scope context_scope(context);
7227 7206
7228 FlagAndPersistent object; 7207 FlagAndPersistent object;
7229 { 7208 {
7230 v8::HandleScope handle_scope(isolate); 7209 v8::HandleScope handle_scope(isolate);
7231 v8::Local<v8::Object> o = v8::Object::New(isolate); 7210 v8::Local<v8::Object> o = v8::Object::New();
7232 object.handle.Reset(isolate, o); 7211 object.handle.Reset(isolate, o);
7233 o->Set(v8_str("x"), v8::Integer::New(isolate, 1)); 7212 o->Set(v8_str("x"), v8::Integer::New(1));
7234 v8::Local<String> y_str = v8_str("y"); 7213 v8::Local<String> y_str = v8_str("y");
7235 o->Set(y_str, y_str); 7214 o->Set(y_str, y_str);
7236 } 7215 }
7237 object.flag = false; 7216 object.flag = false;
7238 object.handle.SetWeak(&object, &RevivingCallback); 7217 object.handle.SetWeak(&object, &RevivingCallback);
7239 object.handle.MarkIndependent(); 7218 object.handle.MarkIndependent();
7240 CcTest::heap()->PerformScavenge(); 7219 CcTest::heap()->PerformScavenge();
7241 CHECK(object.flag); 7220 CHECK(object.flag);
7242 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 7221 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
7243 { 7222 {
7244 v8::HandleScope handle_scope(isolate); 7223 v8::HandleScope handle_scope(isolate);
7245 v8::Local<v8::Object> o = 7224 v8::Local<v8::Object> o =
7246 v8::Local<v8::Object>::New(isolate, object.handle); 7225 v8::Local<v8::Object>::New(isolate, object.handle);
7247 v8::Local<String> y_str = v8_str("y"); 7226 v8::Local<String> y_str = v8_str("y");
7248 CHECK_EQ(v8::Integer::New(isolate, 1), o->Get(v8_str("x"))); 7227 CHECK_EQ(v8::Integer::New(1), o->Get(v8_str("x")));
7249 CHECK(o->Get(y_str)->Equals(y_str)); 7228 CHECK(o->Get(y_str)->Equals(y_str));
7250 } 7229 }
7251 } 7230 }
7252 7231
7253 7232
7254 v8::Handle<Function> args_fun; 7233 v8::Handle<Function> args_fun;
7255 7234
7256 7235
7257 static void ArgumentsTestCallback( 7236 static void ArgumentsTestCallback(
7258 const v8::FunctionCallbackInfo<v8::Value>& args) { 7237 const v8::FunctionCallbackInfo<v8::Value>& args) {
7259 ApiTestFuzzer::Fuzz(); 7238 ApiTestFuzzer::Fuzz();
7260 v8::Isolate* isolate = args.GetIsolate(); 7239 v8::Isolate* isolate = args.GetIsolate();
7261 CHECK_EQ(args_fun, args.Callee()); 7240 CHECK_EQ(args_fun, args.Callee());
7262 CHECK_EQ(3, args.Length()); 7241 CHECK_EQ(3, args.Length());
7263 CHECK_EQ(v8::Integer::New(isolate, 1), args[0]); 7242 CHECK_EQ(v8::Integer::New(1, isolate), args[0]);
7264 CHECK_EQ(v8::Integer::New(isolate, 2), args[1]); 7243 CHECK_EQ(v8::Integer::New(2, isolate), args[1]);
7265 CHECK_EQ(v8::Integer::New(isolate, 3), args[2]); 7244 CHECK_EQ(v8::Integer::New(3, isolate), args[2]);
7266 CHECK_EQ(v8::Undefined(isolate), args[3]); 7245 CHECK_EQ(v8::Undefined(isolate), args[3]);
7267 v8::HandleScope scope(args.GetIsolate()); 7246 v8::HandleScope scope(args.GetIsolate());
7268 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 7247 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
7269 } 7248 }
7270 7249
7271 7250
7272 THREADED_TEST(Arguments) { 7251 THREADED_TEST(Arguments) {
7273 v8::Isolate* isolate = CcTest::isolate(); 7252 v8::Isolate* isolate = CcTest::isolate();
7274 v8::HandleScope scope(isolate); 7253 v8::HandleScope scope(isolate);
7275 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(); 7254 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New();
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
7351 static void IndexedGetK(uint32_t index, 7330 static void IndexedGetK(uint32_t index,
7352 const v8::PropertyCallbackInfo<v8::Value>& info) { 7331 const v8::PropertyCallbackInfo<v8::Value>& info) {
7353 ApiTestFuzzer::Fuzz(); 7332 ApiTestFuzzer::Fuzz();
7354 if (index == 0 || index == 1) info.GetReturnValue().SetUndefined(); 7333 if (index == 0 || index == 1) info.GetReturnValue().SetUndefined();
7355 } 7334 }
7356 7335
7357 7336
7358 static void NamedEnum(const v8::PropertyCallbackInfo<v8::Array>& info) { 7337 static void NamedEnum(const v8::PropertyCallbackInfo<v8::Array>& info) {
7359 ApiTestFuzzer::Fuzz(); 7338 ApiTestFuzzer::Fuzz();
7360 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 3); 7339 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 3);
7361 result->Set(v8::Integer::New(info.GetIsolate(), 0), v8_str("foo")); 7340 result->Set(v8::Integer::New(0), v8_str("foo"));
7362 result->Set(v8::Integer::New(info.GetIsolate(), 1), v8_str("bar")); 7341 result->Set(v8::Integer::New(1), v8_str("bar"));
7363 result->Set(v8::Integer::New(info.GetIsolate(), 2), v8_str("baz")); 7342 result->Set(v8::Integer::New(2), v8_str("baz"));
7364 info.GetReturnValue().Set(result); 7343 info.GetReturnValue().Set(result);
7365 } 7344 }
7366 7345
7367 7346
7368 static void IndexedEnum(const v8::PropertyCallbackInfo<v8::Array>& info) { 7347 static void IndexedEnum(const v8::PropertyCallbackInfo<v8::Array>& info) {
7369 ApiTestFuzzer::Fuzz(); 7348 ApiTestFuzzer::Fuzz();
7370 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 2); 7349 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 2);
7371 result->Set(v8::Integer::New(info.GetIsolate(), 0), v8_str("0")); 7350 result->Set(v8::Integer::New(0), v8_str("0"));
7372 result->Set(v8::Integer::New(info.GetIsolate(), 1), v8_str("1")); 7351 result->Set(v8::Integer::New(1), v8_str("1"));
7373 info.GetReturnValue().Set(result); 7352 info.GetReturnValue().Set(result);
7374 } 7353 }
7375 7354
7376 7355
7377 THREADED_TEST(Enumerators) { 7356 THREADED_TEST(Enumerators) {
7378 v8::Isolate* isolate = CcTest::isolate(); 7357 v8::HandleScope scope(CcTest::isolate());
7379 v8::HandleScope scope(isolate);
7380 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 7358 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
7381 obj->SetNamedPropertyHandler(GetK, NULL, NULL, NULL, NamedEnum); 7359 obj->SetNamedPropertyHandler(GetK, NULL, NULL, NULL, NamedEnum);
7382 obj->SetIndexedPropertyHandler(IndexedGetK, NULL, NULL, NULL, IndexedEnum); 7360 obj->SetIndexedPropertyHandler(IndexedGetK, NULL, NULL, NULL, IndexedEnum);
7383 LocalContext context; 7361 LocalContext context;
7384 context->Global()->Set(v8_str("k"), obj->NewInstance()); 7362 context->Global()->Set(v8_str("k"), obj->NewInstance());
7385 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( 7363 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun(
7386 "k[10] = 0;" 7364 "k[10] = 0;"
7387 "k.a = 0;" 7365 "k.a = 0;"
7388 "k[5] = 0;" 7366 "k[5] = 0;"
7389 "k.b = 0;" 7367 "k.b = 0;"
(...skipping 11 matching lines...) Expand all
7401 "}" 7379 "}"
7402 "result")); 7380 "result"));
7403 // Check that we get all the property names returned including the 7381 // Check that we get all the property names returned including the
7404 // ones from the enumerators in the right order: indexed properties 7382 // ones from the enumerators in the right order: indexed properties
7405 // in numerical order, indexed interceptor properties, named 7383 // in numerical order, indexed interceptor properties, named
7406 // properties in insertion order, named interceptor properties. 7384 // properties in insertion order, named interceptor properties.
7407 // This order is not mandated by the spec, so this test is just 7385 // This order is not mandated by the spec, so this test is just
7408 // documenting our behavior. 7386 // documenting our behavior.
7409 CHECK_EQ(17, result->Length()); 7387 CHECK_EQ(17, result->Length());
7410 // Indexed properties in numerical order. 7388 // Indexed properties in numerical order.
7411 CHECK_EQ(v8_str("5"), result->Get(v8::Integer::New(isolate, 0))); 7389 CHECK_EQ(v8_str("5"), result->Get(v8::Integer::New(0)));
7412 CHECK_EQ(v8_str("10"), result->Get(v8::Integer::New(isolate, 1))); 7390 CHECK_EQ(v8_str("10"), result->Get(v8::Integer::New(1)));
7413 CHECK_EQ(v8_str("140000"), result->Get(v8::Integer::New(isolate, 2))); 7391 CHECK_EQ(v8_str("140000"), result->Get(v8::Integer::New(2)));
7414 CHECK_EQ(v8_str("4294967295"), result->Get(v8::Integer::New(isolate, 3))); 7392 CHECK_EQ(v8_str("4294967295"), result->Get(v8::Integer::New(3)));
7415 // Indexed interceptor properties in the order they are returned 7393 // Indexed interceptor properties in the order they are returned
7416 // from the enumerator interceptor. 7394 // from the enumerator interceptor.
7417 CHECK_EQ(v8_str("0"), result->Get(v8::Integer::New(isolate, 4))); 7395 CHECK_EQ(v8_str("0"), result->Get(v8::Integer::New(4)));
7418 CHECK_EQ(v8_str("1"), result->Get(v8::Integer::New(isolate, 5))); 7396 CHECK_EQ(v8_str("1"), result->Get(v8::Integer::New(5)));
7419 // Named properties in insertion order. 7397 // Named properties in insertion order.
7420 CHECK_EQ(v8_str("a"), result->Get(v8::Integer::New(isolate, 6))); 7398 CHECK_EQ(v8_str("a"), result->Get(v8::Integer::New(6)));
7421 CHECK_EQ(v8_str("b"), result->Get(v8::Integer::New(isolate, 7))); 7399 CHECK_EQ(v8_str("b"), result->Get(v8::Integer::New(7)));
7422 CHECK_EQ(v8_str("c"), result->Get(v8::Integer::New(isolate, 8))); 7400 CHECK_EQ(v8_str("c"), result->Get(v8::Integer::New(8)));
7423 CHECK_EQ(v8_str("4294967296"), result->Get(v8::Integer::New(isolate, 9))); 7401 CHECK_EQ(v8_str("4294967296"), result->Get(v8::Integer::New(9)));
7424 CHECK_EQ(v8_str("d"), result->Get(v8::Integer::New(isolate, 10))); 7402 CHECK_EQ(v8_str("d"), result->Get(v8::Integer::New(10)));
7425 CHECK_EQ(v8_str("e"), result->Get(v8::Integer::New(isolate, 11))); 7403 CHECK_EQ(v8_str("e"), result->Get(v8::Integer::New(11)));
7426 CHECK_EQ(v8_str("30000000000"), result->Get(v8::Integer::New(isolate, 12))); 7404 CHECK_EQ(v8_str("30000000000"), result->Get(v8::Integer::New(12)));
7427 CHECK_EQ(v8_str("f"), result->Get(v8::Integer::New(isolate, 13))); 7405 CHECK_EQ(v8_str("f"), result->Get(v8::Integer::New(13)));
7428 // Named interceptor properties. 7406 // Named interceptor properties.
7429 CHECK_EQ(v8_str("foo"), result->Get(v8::Integer::New(isolate, 14))); 7407 CHECK_EQ(v8_str("foo"), result->Get(v8::Integer::New(14)));
7430 CHECK_EQ(v8_str("bar"), result->Get(v8::Integer::New(isolate, 15))); 7408 CHECK_EQ(v8_str("bar"), result->Get(v8::Integer::New(15)));
7431 CHECK_EQ(v8_str("baz"), result->Get(v8::Integer::New(isolate, 16))); 7409 CHECK_EQ(v8_str("baz"), result->Get(v8::Integer::New(16)));
7432 } 7410 }
7433 7411
7434 7412
7435 int p_getter_count; 7413 int p_getter_count;
7436 int p_getter_count2; 7414 int p_getter_count2;
7437 7415
7438 7416
7439 static void PGetter(Local<String> name, 7417 static void PGetter(Local<String> name,
7440 const v8::PropertyCallbackInfo<v8::Value>& info) { 7418 const v8::PropertyCallbackInfo<v8::Value>& info) {
7441 ApiTestFuzzer::Fuzz(); 7419 ApiTestFuzzer::Fuzz();
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after
8040 CHECK(SameSymbol(sym0b, Handle<String>::Cast(s0b))); 8018 CHECK(SameSymbol(sym0b, Handle<String>::Cast(s0b)));
8041 CHECK(SameSymbol(sym1, Handle<String>::Cast(s1))); 8019 CHECK(SameSymbol(sym1, Handle<String>::Cast(s1)));
8042 CHECK(SameSymbol(sym2, Handle<String>::Cast(s2))); 8020 CHECK(SameSymbol(sym2, Handle<String>::Cast(s2)));
8043 CHECK(SameSymbol(sym3, Handle<String>::Cast(s3))); 8021 CHECK(SameSymbol(sym3, Handle<String>::Cast(s3)));
8044 CHECK(SameSymbol(sym4, Handle<String>::Cast(s4))); 8022 CHECK(SameSymbol(sym4, Handle<String>::Cast(s4)));
8045 } 8023 }
8046 8024
8047 8025
8048 THREADED_TEST(ToArrayIndex) { 8026 THREADED_TEST(ToArrayIndex) {
8049 LocalContext context; 8027 LocalContext context;
8050 v8::Isolate* isolate = context->GetIsolate(); 8028 v8::HandleScope scope(context->GetIsolate());
8051 v8::HandleScope scope(isolate);
8052 8029
8053 v8::Handle<String> str = v8_str("42"); 8030 v8::Handle<String> str = v8_str("42");
8054 v8::Handle<v8::Uint32> index = str->ToArrayIndex(); 8031 v8::Handle<v8::Uint32> index = str->ToArrayIndex();
8055 CHECK(!index.IsEmpty()); 8032 CHECK(!index.IsEmpty());
8056 CHECK_EQ(42.0, index->Uint32Value()); 8033 CHECK_EQ(42.0, index->Uint32Value());
8057 str = v8_str("42asdf"); 8034 str = v8_str("42asdf");
8058 index = str->ToArrayIndex(); 8035 index = str->ToArrayIndex();
8059 CHECK(index.IsEmpty()); 8036 CHECK(index.IsEmpty());
8060 str = v8_str("-42"); 8037 str = v8_str("-42");
8061 index = str->ToArrayIndex(); 8038 index = str->ToArrayIndex();
8062 CHECK(index.IsEmpty()); 8039 CHECK(index.IsEmpty());
8063 str = v8_str("4294967295"); 8040 str = v8_str("4294967295");
8064 index = str->ToArrayIndex(); 8041 index = str->ToArrayIndex();
8065 CHECK(!index.IsEmpty()); 8042 CHECK(!index.IsEmpty());
8066 CHECK_EQ(4294967295.0, index->Uint32Value()); 8043 CHECK_EQ(4294967295.0, index->Uint32Value());
8067 v8::Handle<v8::Number> num = v8::Number::New(isolate, 1); 8044 v8::Handle<v8::Number> num = v8::Number::New(1);
8068 index = num->ToArrayIndex(); 8045 index = num->ToArrayIndex();
8069 CHECK(!index.IsEmpty()); 8046 CHECK(!index.IsEmpty());
8070 CHECK_EQ(1.0, index->Uint32Value()); 8047 CHECK_EQ(1.0, index->Uint32Value());
8071 num = v8::Number::New(isolate, -1); 8048 num = v8::Number::New(-1);
8072 index = num->ToArrayIndex(); 8049 index = num->ToArrayIndex();
8073 CHECK(index.IsEmpty()); 8050 CHECK(index.IsEmpty());
8074 v8::Handle<v8::Object> obj = v8::Object::New(isolate); 8051 v8::Handle<v8::Object> obj = v8::Object::New();
8075 index = obj->ToArrayIndex(); 8052 index = obj->ToArrayIndex();
8076 CHECK(index.IsEmpty()); 8053 CHECK(index.IsEmpty());
8077 } 8054 }
8078 8055
8079 8056
8080 THREADED_TEST(ErrorConstruction) { 8057 THREADED_TEST(ErrorConstruction) {
8081 LocalContext context; 8058 LocalContext context;
8082 v8::HandleScope scope(context->GetIsolate()); 8059 v8::HandleScope scope(context->GetIsolate());
8083 8060
8084 v8::Handle<String> foo = v8_str("foo"); 8061 v8::Handle<String> foo = v8_str("foo");
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
8133 8110
8134 THREADED_TEST(TypeSwitch) { 8111 THREADED_TEST(TypeSwitch) {
8135 v8::Isolate* isolate = CcTest::isolate(); 8112 v8::Isolate* isolate = CcTest::isolate();
8136 v8::HandleScope scope(isolate); 8113 v8::HandleScope scope(isolate);
8137 v8::Handle<v8::FunctionTemplate> templ1 = v8::FunctionTemplate::New(isolate); 8114 v8::Handle<v8::FunctionTemplate> templ1 = v8::FunctionTemplate::New(isolate);
8138 v8::Handle<v8::FunctionTemplate> templ2 = v8::FunctionTemplate::New(isolate); 8115 v8::Handle<v8::FunctionTemplate> templ2 = v8::FunctionTemplate::New(isolate);
8139 v8::Handle<v8::FunctionTemplate> templ3 = v8::FunctionTemplate::New(isolate); 8116 v8::Handle<v8::FunctionTemplate> templ3 = v8::FunctionTemplate::New(isolate);
8140 v8::Handle<v8::FunctionTemplate> templs[3] = { templ1, templ2, templ3 }; 8117 v8::Handle<v8::FunctionTemplate> templs[3] = { templ1, templ2, templ3 };
8141 v8::Handle<v8::TypeSwitch> type_switch = v8::TypeSwitch::New(3, templs); 8118 v8::Handle<v8::TypeSwitch> type_switch = v8::TypeSwitch::New(3, templs);
8142 LocalContext context; 8119 LocalContext context;
8143 v8::Handle<v8::Object> obj0 = v8::Object::New(isolate); 8120 v8::Handle<v8::Object> obj0 = v8::Object::New();
8144 v8::Handle<v8::Object> obj1 = templ1->GetFunction()->NewInstance(); 8121 v8::Handle<v8::Object> obj1 = templ1->GetFunction()->NewInstance();
8145 v8::Handle<v8::Object> obj2 = templ2->GetFunction()->NewInstance(); 8122 v8::Handle<v8::Object> obj2 = templ2->GetFunction()->NewInstance();
8146 v8::Handle<v8::Object> obj3 = templ3->GetFunction()->NewInstance(); 8123 v8::Handle<v8::Object> obj3 = templ3->GetFunction()->NewInstance();
8147 for (int i = 0; i < 10; i++) { 8124 for (int i = 0; i < 10; i++) {
8148 CHECK_EQ(0, type_switch->match(obj0)); 8125 CHECK_EQ(0, type_switch->match(obj0));
8149 CHECK_EQ(1, type_switch->match(obj1)); 8126 CHECK_EQ(1, type_switch->match(obj1));
8150 CHECK_EQ(2, type_switch->match(obj2)); 8127 CHECK_EQ(2, type_switch->match(obj2));
8151 CHECK_EQ(3, type_switch->match(obj3)); 8128 CHECK_EQ(3, type_switch->match(obj3));
8152 CHECK_EQ(3, type_switch->match(obj3)); 8129 CHECK_EQ(3, type_switch->match(obj3));
8153 CHECK_EQ(2, type_switch->match(obj2)); 8130 CHECK_EQ(2, type_switch->match(obj2));
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
8586 8563
8587 // Set to the same domain. 8564 // Set to the same domain.
8588 env1->SetSecurityToken(foo); 8565 env1->SetSecurityToken(foo);
8589 env2->SetSecurityToken(foo); 8566 env2->SetSecurityToken(foo);
8590 8567
8591 // Enter env2 8568 // Enter env2
8592 env2->Enter(); 8569 env2->Enter();
8593 8570
8594 // Create a function in env2 and add a reference to it in env1. 8571 // Create a function in env2 and add a reference to it in env1.
8595 Local<v8::Object> global2 = env2->Global(); 8572 Local<v8::Object> global2 = env2->Global();
8596 global2->Set(v8_str("prop"), v8::Integer::New(env2->GetIsolate(), 1)); 8573 global2->Set(v8_str("prop"), v8::Integer::New(1));
8597 CompileRun("function getProp() {return prop;}"); 8574 CompileRun("function getProp() {return prop;}");
8598 8575
8599 env1->Global()->Set(v8_str("getProp"), 8576 env1->Global()->Set(v8_str("getProp"),
8600 global2->Get(v8_str("getProp"))); 8577 global2->Get(v8_str("getProp")));
8601 8578
8602 // Detach env2's global, and reuse the global object of env2 8579 // Detach env2's global, and reuse the global object of env2
8603 env2->Exit(); 8580 env2->Exit();
8604 env2->DetachGlobal(); 8581 env2->DetachGlobal();
8605 8582
8606 v8::Handle<Context> env3 = Context::New(env1->GetIsolate(), 8583 v8::Handle<Context> env3 = Context::New(env1->GetIsolate(),
8607 0, 8584 0,
8608 v8::Handle<v8::ObjectTemplate>(), 8585 v8::Handle<v8::ObjectTemplate>(),
8609 global2); 8586 global2);
8610 env3->SetSecurityToken(v8_str("bar")); 8587 env3->SetSecurityToken(v8_str("bar"));
8611 env3->Enter(); 8588 env3->Enter();
8612 8589
8613 Local<v8::Object> global3 = env3->Global(); 8590 Local<v8::Object> global3 = env3->Global();
8614 CHECK_EQ(global2, global3); 8591 CHECK_EQ(global2, global3);
8615 CHECK(global3->Get(v8_str("prop"))->IsUndefined()); 8592 CHECK(global3->Get(v8_str("prop"))->IsUndefined());
8616 CHECK(global3->Get(v8_str("getProp"))->IsUndefined()); 8593 CHECK(global3->Get(v8_str("getProp"))->IsUndefined());
8617 global3->Set(v8_str("prop"), v8::Integer::New(env3->GetIsolate(), -1)); 8594 global3->Set(v8_str("prop"), v8::Integer::New(-1));
8618 global3->Set(v8_str("prop2"), v8::Integer::New(env3->GetIsolate(), 2)); 8595 global3->Set(v8_str("prop2"), v8::Integer::New(2));
8619 env3->Exit(); 8596 env3->Exit();
8620 8597
8621 // Call getProp in env1, and it should return the value 1 8598 // Call getProp in env1, and it should return the value 1
8622 { 8599 {
8623 Local<Value> get_prop = global1->Get(v8_str("getProp")); 8600 Local<Value> get_prop = global1->Get(v8_str("getProp"));
8624 CHECK(get_prop->IsFunction()); 8601 CHECK(get_prop->IsFunction());
8625 v8::TryCatch try_catch; 8602 v8::TryCatch try_catch;
8626 Local<Value> r = Function::Cast(*get_prop)->Call(global1, 0, NULL); 8603 Local<Value> r = Function::Cast(*get_prop)->Call(global1, 0, NULL);
8627 CHECK(!try_catch.HasCaught()); 8604 CHECK(!try_catch.HasCaught());
8628 CHECK_EQ(1, r->Int32Value()); 8605 CHECK_EQ(1, r->Int32Value());
(...skipping 16 matching lines...) Expand all
8645 8622
8646 Local<Value> foo = v8_str("foo"); 8623 Local<Value> foo = v8_str("foo");
8647 8624
8648 // Set same security token for env1 and env2. 8625 // Set same security token for env1 and env2.
8649 env1->SetSecurityToken(foo); 8626 env1->SetSecurityToken(foo);
8650 env2->SetSecurityToken(foo); 8627 env2->SetSecurityToken(foo);
8651 8628
8652 // Create a property on the global object in env2. 8629 // Create a property on the global object in env2.
8653 { 8630 {
8654 v8::Context::Scope scope(env2); 8631 v8::Context::Scope scope(env2);
8655 env2->Global()->Set(v8_str("p"), v8::Integer::New(env2->GetIsolate(), 42)); 8632 env2->Global()->Set(v8_str("p"), v8::Integer::New(42));
8656 } 8633 }
8657 8634
8658 // Create a reference to env2 global from env1 global. 8635 // Create a reference to env2 global from env1 global.
8659 env1->Global()->Set(v8_str("other"), env2->Global()); 8636 env1->Global()->Set(v8_str("other"), env2->Global());
8660 8637
8661 // Check that we have access to other.p in env2 from env1. 8638 // Check that we have access to other.p in env2 from env1.
8662 Local<Value> result = CompileRun("other.p"); 8639 Local<Value> result = CompileRun("other.p");
8663 CHECK(result->IsInt32()); 8640 CHECK(result->IsInt32());
8664 CHECK_EQ(42, result->Int32Value()); 8641 CHECK_EQ(42, result->Int32Value());
8665 8642
(...skipping 12 matching lines...) Expand all
8678 v8::Handle<v8::ObjectTemplate>(), 8655 v8::Handle<v8::ObjectTemplate>(),
8679 global2); 8656 global2);
8680 CHECK_EQ(global2, env3->Global()); 8657 CHECK_EQ(global2, env3->Global());
8681 8658
8682 // Start by using the same security token for env3 as for env1 and env2. 8659 // Start by using the same security token for env3 as for env1 and env2.
8683 env3->SetSecurityToken(foo); 8660 env3->SetSecurityToken(foo);
8684 8661
8685 // Create a property on the global object in env3. 8662 // Create a property on the global object in env3.
8686 { 8663 {
8687 v8::Context::Scope scope(env3); 8664 v8::Context::Scope scope(env3);
8688 env3->Global()->Set(v8_str("p"), v8::Integer::New(env3->GetIsolate(), 24)); 8665 env3->Global()->Set(v8_str("p"), v8::Integer::New(24));
8689 } 8666 }
8690 8667
8691 // Check that other.p is now the property in env3 and that we have access. 8668 // Check that other.p is now the property in env3 and that we have access.
8692 result = CompileRun("other.p"); 8669 result = CompileRun("other.p");
8693 CHECK(result->IsInt32()); 8670 CHECK(result->IsInt32());
8694 CHECK_EQ(24, result->Int32Value()); 8671 CHECK_EQ(24, result->Int32Value());
8695 8672
8696 // Change security token for env3 to something different from env1 and env2. 8673 // Change security token for env3 to something different from env1 and env2.
8697 env3->SetSecurityToken(v8_str("bar")); 8674 env3->SetSecurityToken(v8_str("bar"));
8698 8675
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
9190 Local<Value> data) { 9167 Local<Value> data) {
9191 return false; 9168 return false;
9192 } 9169 }
9193 9170
9194 9171
9195 THREADED_TEST(AccessControlGetOwnPropertyNames) { 9172 THREADED_TEST(AccessControlGetOwnPropertyNames) {
9196 v8::Isolate* isolate = CcTest::isolate(); 9173 v8::Isolate* isolate = CcTest::isolate();
9197 v8::HandleScope handle_scope(isolate); 9174 v8::HandleScope handle_scope(isolate);
9198 v8::Handle<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(); 9175 v8::Handle<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New();
9199 9176
9200 obj_template->Set(v8_str("x"), v8::Integer::New(isolate, 42)); 9177 obj_template->Set(v8_str("x"), v8::Integer::New(42));
9201 obj_template->SetAccessCheckCallbacks(GetOwnPropertyNamesNamedBlocker, 9178 obj_template->SetAccessCheckCallbacks(GetOwnPropertyNamesNamedBlocker,
9202 GetOwnPropertyNamesIndexedBlocker); 9179 GetOwnPropertyNamesIndexedBlocker);
9203 9180
9204 // Create an environment 9181 // Create an environment
9205 v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template); 9182 v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template);
9206 context0->Enter(); 9183 context0->Enter();
9207 9184
9208 v8::Handle<v8::Object> global0 = context0->Global(); 9185 v8::Handle<v8::Object> global0 = context0->Global();
9209 9186
9210 v8::HandleScope scope1(CcTest::isolate()); 9187 v8::HandleScope scope1(CcTest::isolate());
(...skipping 19 matching lines...) Expand all
9230 CHECK(value->IsTrue()); 9207 CHECK(value->IsTrue());
9231 9208
9232 context1->Exit(); 9209 context1->Exit();
9233 context0->Exit(); 9210 context0->Exit();
9234 } 9211 }
9235 9212
9236 9213
9237 static void IndexedPropertyEnumerator( 9214 static void IndexedPropertyEnumerator(
9238 const v8::PropertyCallbackInfo<v8::Array>& info) { 9215 const v8::PropertyCallbackInfo<v8::Array>& info) {
9239 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 2); 9216 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 2);
9240 result->Set(0, v8::Integer::New(info.GetIsolate(), 7)); 9217 result->Set(0, v8::Integer::New(7));
9241 result->Set(1, v8::Object::New(info.GetIsolate())); 9218 result->Set(1, v8::Object::New());
9242 info.GetReturnValue().Set(result); 9219 info.GetReturnValue().Set(result);
9243 } 9220 }
9244 9221
9245 9222
9246 static void NamedPropertyEnumerator( 9223 static void NamedPropertyEnumerator(
9247 const v8::PropertyCallbackInfo<v8::Array>& info) { 9224 const v8::PropertyCallbackInfo<v8::Array>& info) {
9248 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 2); 9225 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 2);
9249 result->Set(0, v8_str("x")); 9226 result->Set(0, v8_str("x"));
9250 result->Set(1, v8::Object::New(info.GetIsolate())); 9227 result->Set(1, v8::Object::New());
9251 info.GetReturnValue().Set(result); 9228 info.GetReturnValue().Set(result);
9252 } 9229 }
9253 9230
9254 9231
9255 THREADED_TEST(GetOwnPropertyNamesWithInterceptor) { 9232 THREADED_TEST(GetOwnPropertyNamesWithInterceptor) {
9256 v8::HandleScope handle_scope(CcTest::isolate()); 9233 v8::HandleScope handle_scope(CcTest::isolate());
9257 v8::Handle<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(); 9234 v8::Handle<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New();
9258 9235
9259 obj_template->Set(v8_str("7"), v8::Integer::New(CcTest::isolate(), 7)); 9236 obj_template->Set(v8_str("7"), v8::Integer::New(7));
9260 obj_template->Set(v8_str("x"), v8::Integer::New(CcTest::isolate(), 42)); 9237 obj_template->Set(v8_str("x"), v8::Integer::New(42));
9261 obj_template->SetIndexedPropertyHandler(NULL, NULL, NULL, NULL, 9238 obj_template->SetIndexedPropertyHandler(NULL, NULL, NULL, NULL,
9262 IndexedPropertyEnumerator); 9239 IndexedPropertyEnumerator);
9263 obj_template->SetNamedPropertyHandler(NULL, NULL, NULL, NULL, 9240 obj_template->SetNamedPropertyHandler(NULL, NULL, NULL, NULL,
9264 NamedPropertyEnumerator); 9241 NamedPropertyEnumerator);
9265 9242
9266 LocalContext context; 9243 LocalContext context;
9267 v8::Handle<v8::Object> global = context->Global(); 9244 v8::Handle<v8::Object> global = context->Global();
9268 global->Set(v8_str("object"), obj_template->NewInstance()); 9245 global->Set(v8_str("object"), obj_template->NewInstance());
9269 9246
9270 v8::Handle<v8::Value> result = 9247 v8::Handle<v8::Value> result =
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after
9956 9933
9957 // Regression test for issue 2457. 9934 // Regression test for issue 2457.
9958 THREADED_TEST(HiddenPrototypeIdentityHash) { 9935 THREADED_TEST(HiddenPrototypeIdentityHash) {
9959 LocalContext context; 9936 LocalContext context;
9960 v8::HandleScope handle_scope(context->GetIsolate()); 9937 v8::HandleScope handle_scope(context->GetIsolate());
9961 9938
9962 Handle<FunctionTemplate> t = FunctionTemplate::New(context->GetIsolate()); 9939 Handle<FunctionTemplate> t = FunctionTemplate::New(context->GetIsolate());
9963 t->SetHiddenPrototype(true); 9940 t->SetHiddenPrototype(true);
9964 t->InstanceTemplate()->Set(v8_str("foo"), v8_num(75)); 9941 t->InstanceTemplate()->Set(v8_str("foo"), v8_num(75));
9965 Handle<Object> p = t->GetFunction()->NewInstance(); 9942 Handle<Object> p = t->GetFunction()->NewInstance();
9966 Handle<Object> o = Object::New(context->GetIsolate()); 9943 Handle<Object> o = Object::New();
9967 o->SetPrototype(p); 9944 o->SetPrototype(p);
9968 9945
9969 int hash = o->GetIdentityHash(); 9946 int hash = o->GetIdentityHash();
9970 USE(hash); 9947 USE(hash);
9971 o->Set(v8_str("foo"), v8_num(42)); 9948 o->Set(v8_str("foo"), v8_num(42));
9972 ASSERT_EQ(hash, o->GetIdentityHash()); 9949 ASSERT_EQ(hash, o->GetIdentityHash());
9973 } 9950 }
9974 9951
9975 9952
9976 THREADED_TEST(SetPrototype) { 9953 THREADED_TEST(SetPrototype) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
10039 LocalContext context; 10016 LocalContext context;
10040 v8::Isolate* isolate = context->GetIsolate(); 10017 v8::Isolate* isolate = context->GetIsolate();
10041 v8::HandleScope handle_scope(isolate); 10018 v8::HandleScope handle_scope(isolate);
10042 10019
10043 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate); 10020 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate);
10044 t1->SetHiddenPrototype(true); 10021 t1->SetHiddenPrototype(true);
10045 t1->InstanceTemplate()->Set(v8_str("foo"), v8_num(1)); 10022 t1->InstanceTemplate()->Set(v8_str("foo"), v8_num(1));
10046 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate); 10023 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate);
10047 t2->SetHiddenPrototype(true); 10024 t2->SetHiddenPrototype(true);
10048 t2->InstanceTemplate()->Set(v8_str("fuz1"), v8_num(2)); 10025 t2->InstanceTemplate()->Set(v8_str("fuz1"), v8_num(2));
10049 t2->InstanceTemplate()->Set(v8_str("objects"), v8::Object::New(isolate)); 10026 t2->InstanceTemplate()->Set(v8_str("objects"), v8::Object::New());
10050 t2->InstanceTemplate()->Set(v8_str("fuz2"), v8_num(2)); 10027 t2->InstanceTemplate()->Set(v8_str("fuz2"), v8_num(2));
10051 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(isolate); 10028 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(isolate);
10052 t3->SetHiddenPrototype(true); 10029 t3->SetHiddenPrototype(true);
10053 t3->InstanceTemplate()->Set(v8_str("boo"), v8_num(3)); 10030 t3->InstanceTemplate()->Set(v8_str("boo"), v8_num(3));
10054 Local<v8::FunctionTemplate> t4 = v8::FunctionTemplate::New(isolate); 10031 Local<v8::FunctionTemplate> t4 = v8::FunctionTemplate::New(isolate);
10055 t4->InstanceTemplate()->Set(v8_str("baz"), v8_num(4)); 10032 t4->InstanceTemplate()->Set(v8_str("baz"), v8_num(4));
10056 10033
10057 // Force dictionary-based properties. 10034 // Force dictionary-based properties.
10058 i::ScopedVector<char> name_buf(1024); 10035 i::ScopedVector<char> name_buf(1024);
10059 for (int i = 1; i <= 1000; i++) { 10036 for (int i = 1; i <= 1000; i++) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
10114 10091
10115 // Inherit from t1 and mark prototype as hidden. 10092 // Inherit from t1 and mark prototype as hidden.
10116 t2->Inherit(t1); 10093 t2->Inherit(t1);
10117 t2->InstanceTemplate()->Set(v8_str("mine"), v8_num(4)); 10094 t2->InstanceTemplate()->Set(v8_str("mine"), v8_num(4));
10118 10095
10119 Local<v8::Object> o2 = t2->GetFunction()->NewInstance(); 10096 Local<v8::Object> o2 = t2->GetFunction()->NewInstance();
10120 CHECK(o2->SetPrototype(o1)); 10097 CHECK(o2->SetPrototype(o1));
10121 10098
10122 v8::Local<v8::Symbol> sym = v8::Symbol::New(context->GetIsolate(), "s1"); 10099 v8::Local<v8::Symbol> sym = v8::Symbol::New(context->GetIsolate(), "s1");
10123 o1->Set(sym, v8_num(3)); 10100 o1->Set(sym, v8_num(3));
10124 o1->SetHiddenValue(v8_str("h1"), 10101 o1->SetHiddenValue(v8_str("h1"), v8::Integer::New(2013));
10125 v8::Integer::New(context->GetIsolate(), 2013));
10126 10102
10127 // Call the runtime version of GetLocalPropertyNames() on 10103 // Call the runtime version of GetLocalPropertyNames() on
10128 // the natively created object through JavaScript. 10104 // the natively created object through JavaScript.
10129 context->Global()->Set(v8_str("obj"), o2); 10105 context->Global()->Set(v8_str("obj"), o2);
10130 context->Global()->Set(v8_str("sym"), sym); 10106 context->Global()->Set(v8_str("sym"), sym);
10131 CompileRun("var names = %GetLocalPropertyNames(obj, true);"); 10107 CompileRun("var names = %GetLocalPropertyNames(obj, true);");
10132 10108
10133 ExpectInt32("names.length", 7); 10109 ExpectInt32("names.length", 7);
10134 ExpectTrue("names.indexOf(\"foo\") >= 0"); 10110 ExpectTrue("names.indexOf(\"foo\") >= 0");
10135 ExpectTrue("names.indexOf(\"bar\") >= 0"); 10111 ExpectTrue("names.indexOf(\"bar\") >= 0");
10136 ExpectTrue("names.indexOf(\"baz\") >= 0"); 10112 ExpectTrue("names.indexOf(\"baz\") >= 0");
10137 ExpectTrue("names.indexOf(\"n1\") >= 0"); 10113 ExpectTrue("names.indexOf(\"n1\") >= 0");
10138 ExpectTrue("names.indexOf(\"n2\") >= 0"); 10114 ExpectTrue("names.indexOf(\"n2\") >= 0");
10139 ExpectTrue("names.indexOf(sym) >= 0"); 10115 ExpectTrue("names.indexOf(sym) >= 0");
10140 ExpectTrue("names.indexOf(\"mine\") >= 0"); 10116 ExpectTrue("names.indexOf(\"mine\") >= 0");
10141 } 10117 }
10142 10118
10143 10119
10144 THREADED_TEST(FunctionReadOnlyPrototype) { 10120 THREADED_TEST(FunctionReadOnlyPrototype) {
10145 LocalContext context; 10121 LocalContext context;
10146 v8::Isolate* isolate = context->GetIsolate(); 10122 v8::Isolate* isolate = context->GetIsolate();
10147 v8::HandleScope handle_scope(isolate); 10123 v8::HandleScope handle_scope(isolate);
10148 10124
10149 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate); 10125 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate);
10150 t1->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(isolate, 42)); 10126 t1->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(42));
10151 t1->ReadOnlyPrototype(); 10127 t1->ReadOnlyPrototype();
10152 context->Global()->Set(v8_str("func1"), t1->GetFunction()); 10128 context->Global()->Set(v8_str("func1"), t1->GetFunction());
10153 // Configured value of ReadOnly flag. 10129 // Configured value of ReadOnly flag.
10154 CHECK(CompileRun( 10130 CHECK(CompileRun(
10155 "(function() {" 10131 "(function() {"
10156 " descriptor = Object.getOwnPropertyDescriptor(func1, 'prototype');" 10132 " descriptor = Object.getOwnPropertyDescriptor(func1, 'prototype');"
10157 " return (descriptor['writable'] == false);" 10133 " return (descriptor['writable'] == false);"
10158 "})()")->BooleanValue()); 10134 "})()")->BooleanValue());
10159 CHECK_EQ(42, CompileRun("func1.prototype.x")->Int32Value()); 10135 CHECK_EQ(42, CompileRun("func1.prototype.x")->Int32Value());
10160 CHECK_EQ(42, 10136 CHECK_EQ(42,
10161 CompileRun("func1.prototype = {}; func1.prototype.x")->Int32Value()); 10137 CompileRun("func1.prototype = {}; func1.prototype.x")->Int32Value());
10162 10138
10163 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate); 10139 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate);
10164 t2->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(isolate, 42)); 10140 t2->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(42));
10165 context->Global()->Set(v8_str("func2"), t2->GetFunction()); 10141 context->Global()->Set(v8_str("func2"), t2->GetFunction());
10166 // Default value of ReadOnly flag. 10142 // Default value of ReadOnly flag.
10167 CHECK(CompileRun( 10143 CHECK(CompileRun(
10168 "(function() {" 10144 "(function() {"
10169 " descriptor = Object.getOwnPropertyDescriptor(func2, 'prototype');" 10145 " descriptor = Object.getOwnPropertyDescriptor(func2, 'prototype');"
10170 " return (descriptor['writable'] == true);" 10146 " return (descriptor['writable'] == true);"
10171 "})()")->BooleanValue()); 10147 "})()")->BooleanValue());
10172 CHECK_EQ(42, CompileRun("func2.prototype.x")->Int32Value()); 10148 CHECK_EQ(42, CompileRun("func2.prototype.x")->Int32Value());
10173 } 10149 }
10174 10150
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
10211 CHECK(try_catch.HasCaught()); 10187 CHECK(try_catch.HasCaught());
10212 10188
10213 try_catch.Reset(); 10189 try_catch.Reset();
10214 fun->NewInstance(); 10190 fun->NewInstance();
10215 CHECK(try_catch.HasCaught()); 10191 CHECK(try_catch.HasCaught());
10216 } 10192 }
10217 10193
10218 10194
10219 THREADED_TEST(GetterSetterExceptions) { 10195 THREADED_TEST(GetterSetterExceptions) {
10220 LocalContext context; 10196 LocalContext context;
10221 v8::Isolate* isolate = context->GetIsolate(); 10197 v8::HandleScope handle_scope(context->GetIsolate());
10222 v8::HandleScope handle_scope(isolate);
10223 CompileRun( 10198 CompileRun(
10224 "function Foo() { };" 10199 "function Foo() { };"
10225 "function Throw() { throw 5; };" 10200 "function Throw() { throw 5; };"
10226 "var x = { };" 10201 "var x = { };"
10227 "x.__defineSetter__('set', Throw);" 10202 "x.__defineSetter__('set', Throw);"
10228 "x.__defineGetter__('get', Throw);"); 10203 "x.__defineGetter__('get', Throw);");
10229 Local<v8::Object> x = 10204 Local<v8::Object> x =
10230 Local<v8::Object>::Cast(context->Global()->Get(v8_str("x"))); 10205 Local<v8::Object>::Cast(context->Global()->Get(v8_str("x")));
10231 v8::TryCatch try_catch; 10206 v8::TryCatch try_catch;
10232 x->Set(v8_str("set"), v8::Integer::New(isolate, 8)); 10207 x->Set(v8_str("set"), v8::Integer::New(8));
10233 x->Get(v8_str("get")); 10208 x->Get(v8_str("get"));
10234 x->Set(v8_str("set"), v8::Integer::New(isolate, 8)); 10209 x->Set(v8_str("set"), v8::Integer::New(8));
10235 x->Get(v8_str("get")); 10210 x->Get(v8_str("get"));
10236 x->Set(v8_str("set"), v8::Integer::New(isolate, 8)); 10211 x->Set(v8_str("set"), v8::Integer::New(8));
10237 x->Get(v8_str("get")); 10212 x->Get(v8_str("get"));
10238 x->Set(v8_str("set"), v8::Integer::New(isolate, 8)); 10213 x->Set(v8_str("set"), v8::Integer::New(8));
10239 x->Get(v8_str("get")); 10214 x->Get(v8_str("get"));
10240 } 10215 }
10241 10216
10242 10217
10243 THREADED_TEST(Constructor) { 10218 THREADED_TEST(Constructor) {
10244 LocalContext context; 10219 LocalContext context;
10245 v8::Isolate* isolate = context->GetIsolate(); 10220 v8::Isolate* isolate = context->GetIsolate();
10246 v8::HandleScope handle_scope(isolate); 10221 v8::HandleScope handle_scope(isolate);
10247 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); 10222 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate);
10248 templ->SetClassName(v8_str("Fun")); 10223 templ->SetClassName(v8_str("Fun"));
10249 Local<Function> cons = templ->GetFunction(); 10224 Local<Function> cons = templ->GetFunction();
10250 context->Global()->Set(v8_str("Fun"), cons); 10225 context->Global()->Set(v8_str("Fun"), cons);
10251 Local<v8::Object> inst = cons->NewInstance(); 10226 Local<v8::Object> inst = cons->NewInstance();
10252 i::Handle<i::JSObject> obj(v8::Utils::OpenHandle(*inst)); 10227 i::Handle<i::JSObject> obj(v8::Utils::OpenHandle(*inst));
10253 CHECK(obj->IsJSObject()); 10228 CHECK(obj->IsJSObject());
10254 Local<Value> value = CompileRun("(new Fun()).constructor === Fun"); 10229 Local<Value> value = CompileRun("(new Fun()).constructor === Fun");
10255 CHECK(value->BooleanValue()); 10230 CHECK(value->BooleanValue());
10256 } 10231 }
10257 10232
10258 10233
10259 static void ConstructorCallback( 10234 static void ConstructorCallback(
10260 const v8::FunctionCallbackInfo<v8::Value>& args) { 10235 const v8::FunctionCallbackInfo<v8::Value>& args) {
10261 ApiTestFuzzer::Fuzz(); 10236 ApiTestFuzzer::Fuzz();
10262 Local<Object> This; 10237 Local<Object> This;
10263 10238
10264 if (args.IsConstructCall()) { 10239 if (args.IsConstructCall()) {
10265 Local<Object> Holder = args.Holder(); 10240 Local<Object> Holder = args.Holder();
10266 This = Object::New(args.GetIsolate()); 10241 This = Object::New();
10267 Local<Value> proto = Holder->GetPrototype(); 10242 Local<Value> proto = Holder->GetPrototype();
10268 if (proto->IsObject()) { 10243 if (proto->IsObject()) {
10269 This->SetPrototype(proto); 10244 This->SetPrototype(proto);
10270 } 10245 }
10271 } else { 10246 } else {
10272 This = args.This(); 10247 This = args.This();
10273 } 10248 }
10274 10249
10275 This->Set(v8_str("a"), args[0]); 10250 This->Set(v8_str("a"), args[0]);
10276 args.GetReturnValue().Set(This); 10251 args.GetReturnValue().Set(This);
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
10903 10878
10904 static int CountHandles() { 10879 static int CountHandles() {
10905 return v8::HandleScope::NumberOfHandles(); 10880 return v8::HandleScope::NumberOfHandles();
10906 } 10881 }
10907 10882
10908 10883
10909 static int Recurse(int depth, int iterations) { 10884 static int Recurse(int depth, int iterations) {
10910 v8::HandleScope scope(CcTest::isolate()); 10885 v8::HandleScope scope(CcTest::isolate());
10911 if (depth == 0) return CountHandles(); 10886 if (depth == 0) return CountHandles();
10912 for (int i = 0; i < iterations; i++) { 10887 for (int i = 0; i < iterations; i++) {
10913 Local<v8::Number> n(v8::Integer::New(CcTest::isolate(), 42)); 10888 Local<v8::Number> n(v8::Integer::New(42));
10914 } 10889 }
10915 return Recurse(depth - 1, iterations); 10890 return Recurse(depth - 1, iterations);
10916 } 10891 }
10917 10892
10918 10893
10919 THREADED_TEST(HandleIteration) { 10894 THREADED_TEST(HandleIteration) {
10920 static const int kIterations = 500; 10895 static const int kIterations = 500;
10921 static const int kNesting = 200; 10896 static const int kNesting = 200;
10922 CHECK_EQ(0, CountHandles()); 10897 CHECK_EQ(0, CountHandles());
10923 { 10898 {
10924 v8::HandleScope scope1(CcTest::isolate()); 10899 v8::HandleScope scope1(CcTest::isolate());
10925 CHECK_EQ(0, CountHandles()); 10900 CHECK_EQ(0, CountHandles());
10926 for (int i = 0; i < kIterations; i++) { 10901 for (int i = 0; i < kIterations; i++) {
10927 Local<v8::Number> n(v8::Integer::New(CcTest::isolate(), 42)); 10902 Local<v8::Number> n(v8::Integer::New(42));
10928 CHECK_EQ(i + 1, CountHandles()); 10903 CHECK_EQ(i + 1, CountHandles());
10929 } 10904 }
10930 10905
10931 CHECK_EQ(kIterations, CountHandles()); 10906 CHECK_EQ(kIterations, CountHandles());
10932 { 10907 {
10933 v8::HandleScope scope2(CcTest::isolate()); 10908 v8::HandleScope scope2(CcTest::isolate());
10934 for (int j = 0; j < kIterations; j++) { 10909 for (int j = 0; j < kIterations; j++) {
10935 Local<v8::Number> n(v8::Integer::New(CcTest::isolate(), 42)); 10910 Local<v8::Number> n(v8::Integer::New(42));
10936 CHECK_EQ(j + 1 + kIterations, CountHandles()); 10911 CHECK_EQ(j + 1 + kIterations, CountHandles());
10937 } 10912 }
10938 } 10913 }
10939 CHECK_EQ(kIterations, CountHandles()); 10914 CHECK_EQ(kIterations, CountHandles());
10940 } 10915 }
10941 CHECK_EQ(0, CountHandles()); 10916 CHECK_EQ(0, CountHandles());
10942 CHECK_EQ(kNesting * kIterations, Recurse(kNesting, kIterations)); 10917 CHECK_EQ(kNesting * kIterations, Recurse(kNesting, kIterations));
10943 } 10918 }
10944 10919
10945 10920
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
11031 11006
11032 11007
11033 static void InterceptorLoadICGetter( 11008 static void InterceptorLoadICGetter(
11034 Local<String> name, 11009 Local<String> name,
11035 const v8::PropertyCallbackInfo<v8::Value>& info) { 11010 const v8::PropertyCallbackInfo<v8::Value>& info) {
11036 ApiTestFuzzer::Fuzz(); 11011 ApiTestFuzzer::Fuzz();
11037 v8::Isolate* isolate = CcTest::isolate(); 11012 v8::Isolate* isolate = CcTest::isolate();
11038 CHECK_EQ(isolate, info.GetIsolate()); 11013 CHECK_EQ(isolate, info.GetIsolate());
11039 CHECK_EQ(v8_str("data"), info.Data()); 11014 CHECK_EQ(v8_str("data"), info.Data());
11040 CHECK_EQ(v8_str("x"), name); 11015 CHECK_EQ(v8_str("x"), name);
11041 info.GetReturnValue().Set(v8::Integer::New(isolate, 42)); 11016 info.GetReturnValue().Set(v8::Integer::New(42));
11042 } 11017 }
11043 11018
11044 11019
11045 // This test should hit the load IC for the interceptor case. 11020 // This test should hit the load IC for the interceptor case.
11046 THREADED_TEST(InterceptorLoadIC) { 11021 THREADED_TEST(InterceptorLoadIC) {
11047 CheckInterceptorLoadIC(InterceptorLoadICGetter, 11022 CheckInterceptorLoadIC(InterceptorLoadICGetter,
11048 "var result = 0;" 11023 "var result = 0;"
11049 "for (var i = 0; i < 1000; i++) {" 11024 "for (var i = 0; i < 1000; i++) {"
11050 " result = o.x;" 11025 " result = o.x;"
11051 "}", 11026 "}",
11052 42); 11027 42);
11053 } 11028 }
11054 11029
11055 11030
11056 // Below go several tests which verify that JITing for various 11031 // Below go several tests which verify that JITing for various
11057 // configurations of interceptor and explicit fields works fine 11032 // configurations of interceptor and explicit fields works fine
11058 // (those cases are special cased to get better performance). 11033 // (those cases are special cased to get better performance).
11059 11034
11060 static void InterceptorLoadXICGetter( 11035 static void InterceptorLoadXICGetter(
11061 Local<String> name, 11036 Local<String> name,
11062 const v8::PropertyCallbackInfo<v8::Value>& info) { 11037 const v8::PropertyCallbackInfo<v8::Value>& info) {
11063 ApiTestFuzzer::Fuzz(); 11038 ApiTestFuzzer::Fuzz();
11064 info.GetReturnValue().Set( 11039 info.GetReturnValue().Set(
11065 v8_str("x")->Equals(name) ? 11040 v8_str("x")->Equals(name) ?
11066 v8::Handle<v8::Value>(v8::Integer::New(info.GetIsolate(), 42)) : 11041 v8::Handle<v8::Value>(v8::Integer::New(42)) :
11067 v8::Handle<v8::Value>()); 11042 v8::Handle<v8::Value>());
11068 } 11043 }
11069 11044
11070 11045
11071 THREADED_TEST(InterceptorLoadICWithFieldOnHolder) { 11046 THREADED_TEST(InterceptorLoadICWithFieldOnHolder) {
11072 CheckInterceptorLoadIC(InterceptorLoadXICGetter, 11047 CheckInterceptorLoadIC(InterceptorLoadXICGetter,
11073 "var result = 0;" 11048 "var result = 0;"
11074 "o.y = 239;" 11049 "o.y = 239;"
11075 "for (var i = 0; i < 1000; i++) {" 11050 "for (var i = 0; i < 1000; i++) {"
11076 " result = o.y;" 11051 " result = o.y;"
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
11408 "result"); 11383 "result");
11409 CHECK_EQ(42 * 10, value->Int32Value()); 11384 CHECK_EQ(42 * 10, value->Int32Value());
11410 } 11385 }
11411 11386
11412 11387
11413 static void InterceptorLoadICGetter0( 11388 static void InterceptorLoadICGetter0(
11414 Local<String> name, 11389 Local<String> name,
11415 const v8::PropertyCallbackInfo<v8::Value>& info) { 11390 const v8::PropertyCallbackInfo<v8::Value>& info) {
11416 ApiTestFuzzer::Fuzz(); 11391 ApiTestFuzzer::Fuzz();
11417 CHECK(v8_str("x")->Equals(name)); 11392 CHECK(v8_str("x")->Equals(name));
11418 info.GetReturnValue().Set(v8::Integer::New(info.GetIsolate(), 0)); 11393 info.GetReturnValue().Set(v8::Integer::New(0));
11419 } 11394 }
11420 11395
11421 11396
11422 THREADED_TEST(InterceptorReturningZero) { 11397 THREADED_TEST(InterceptorReturningZero) {
11423 CheckInterceptorLoadIC(InterceptorLoadICGetter0, 11398 CheckInterceptorLoadIC(InterceptorLoadICGetter0,
11424 "o.x == undefined ? 1 : 0", 11399 "o.x == undefined ? 1 : 0",
11425 0); 11400 0);
11426 } 11401 }
11427 11402
11428 11403
(...skipping 1225 matching lines...) Expand 10 before | Expand all | Expand 10 after
12654 ApiTestFuzzer::Fuzz(); 12629 ApiTestFuzzer::Fuzz();
12655 info.GetIsolate()->ThrowException(Handle<Value>()); 12630 info.GetIsolate()->ThrowException(Handle<Value>());
12656 info.GetReturnValue().SetUndefined(); 12631 info.GetReturnValue().SetUndefined();
12657 } 12632 }
12658 12633
12659 12634
12660 THREADED_TEST(VariousGetPropertiesAndThrowingCallbacks) { 12635 THREADED_TEST(VariousGetPropertiesAndThrowingCallbacks) {
12661 LocalContext context; 12636 LocalContext context;
12662 HandleScope scope(context->GetIsolate()); 12637 HandleScope scope(context->GetIsolate());
12663 12638
12664 Local<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate()); 12639 Local<FunctionTemplate> templ = FunctionTemplate::New(CcTest::isolate());
12665 Local<ObjectTemplate> instance_templ = templ->InstanceTemplate(); 12640 Local<ObjectTemplate> instance_templ = templ->InstanceTemplate();
12666 instance_templ->SetAccessor(v8_str("f"), ThrowingGetter); 12641 instance_templ->SetAccessor(v8_str("f"), ThrowingGetter);
12667 12642
12668 Local<Object> instance = templ->GetFunction()->NewInstance(); 12643 Local<Object> instance = templ->GetFunction()->NewInstance();
12669 12644
12670 Local<Object> another = Object::New(context->GetIsolate()); 12645 Local<Object> another = Object::New();
12671 another->SetPrototype(instance); 12646 another->SetPrototype(instance);
12672 12647
12673 Local<Object> with_js_getter = CompileRun( 12648 Local<Object> with_js_getter = CompileRun(
12674 "o = {};\n" 12649 "o = {};\n"
12675 "o.__defineGetter__('f', function() { throw undefined; });\n" 12650 "o.__defineGetter__('f', function() { throw undefined; });\n"
12676 "o\n").As<Object>(); 12651 "o\n").As<Object>();
12677 CHECK(!with_js_getter.IsEmpty()); 12652 CHECK(!with_js_getter.IsEmpty());
12678 12653
12679 TryCatch try_catch; 12654 TryCatch try_catch;
12680 12655
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
13301 v8::Isolate* isolate = context->GetIsolate(); 13276 v8::Isolate* isolate = context->GetIsolate();
13302 i::GlobalHandles* globals = 13277 i::GlobalHandles* globals =
13303 reinterpret_cast<i::Isolate*>(isolate)->global_handles(); 13278 reinterpret_cast<i::Isolate*>(isolate)->global_handles();
13304 int initial_handles = globals->global_handles_count(); 13279 int initial_handles = globals->global_handles_count();
13305 typedef v8::Persistent<v8::Object, v8::CopyablePersistentTraits<v8::Object> > 13280 typedef v8::Persistent<v8::Object, v8::CopyablePersistentTraits<v8::Object> >
13306 CopyableObject; 13281 CopyableObject;
13307 { 13282 {
13308 CopyableObject handle1; 13283 CopyableObject handle1;
13309 { 13284 {
13310 v8::HandleScope scope(isolate); 13285 v8::HandleScope scope(isolate);
13311 handle1.Reset(isolate, v8::Object::New(isolate)); 13286 handle1.Reset(isolate, v8::Object::New());
13312 } 13287 }
13313 CHECK_EQ(initial_handles + 1, globals->global_handles_count()); 13288 CHECK_EQ(initial_handles + 1, globals->global_handles_count());
13314 CopyableObject handle2; 13289 CopyableObject handle2;
13315 handle2 = handle1; 13290 handle2 = handle1;
13316 CHECK(handle1 == handle2); 13291 CHECK(handle1 == handle2);
13317 CHECK_EQ(initial_handles + 2, globals->global_handles_count()); 13292 CHECK_EQ(initial_handles + 2, globals->global_handles_count());
13318 CopyableObject handle3(handle2); 13293 CopyableObject handle3(handle2);
13319 CHECK(handle1 == handle3); 13294 CHECK(handle1 == handle3);
13320 CHECK_EQ(initial_handles + 3, globals->global_handles_count()); 13295 CHECK_EQ(initial_handles + 3, globals->global_handles_count());
13321 } 13296 }
(...skipping 12 matching lines...) Expand all
13334 13309
13335 13310
13336 TEST(WeakCallbackApi) { 13311 TEST(WeakCallbackApi) {
13337 LocalContext context; 13312 LocalContext context;
13338 v8::Isolate* isolate = context->GetIsolate(); 13313 v8::Isolate* isolate = context->GetIsolate();
13339 i::GlobalHandles* globals = 13314 i::GlobalHandles* globals =
13340 reinterpret_cast<i::Isolate*>(isolate)->global_handles(); 13315 reinterpret_cast<i::Isolate*>(isolate)->global_handles();
13341 int initial_handles = globals->global_handles_count(); 13316 int initial_handles = globals->global_handles_count();
13342 { 13317 {
13343 v8::HandleScope scope(isolate); 13318 v8::HandleScope scope(isolate);
13344 v8::Local<v8::Object> obj = v8::Object::New(isolate); 13319 v8::Local<v8::Object> obj = v8::Object::New();
13345 obj->Set(v8_str("key"), v8::Integer::New(isolate, 231)); 13320 obj->Set(v8_str("key"), v8::Integer::New(231, isolate));
13346 v8::Persistent<v8::Object>* handle = 13321 v8::Persistent<v8::Object>* handle =
13347 new v8::Persistent<v8::Object>(isolate, obj); 13322 new v8::Persistent<v8::Object>(isolate, obj);
13348 handle->SetWeak<v8::Object, v8::Persistent<v8::Object> >(handle, 13323 handle->SetWeak<v8::Object, v8::Persistent<v8::Object> >(handle,
13349 WeakApiCallback); 13324 WeakApiCallback);
13350 } 13325 }
13351 reinterpret_cast<i::Isolate*>(isolate)->heap()-> 13326 reinterpret_cast<i::Isolate*>(isolate)->heap()->
13352 CollectAllGarbage(i::Heap::kNoGCFlags); 13327 CollectAllGarbage(i::Heap::kNoGCFlags);
13353 // Verify disposed. 13328 // Verify disposed.
13354 CHECK_EQ(initial_handles, globals->global_handles_count()); 13329 CHECK_EQ(initial_handles, globals->global_handles_count());
13355 } 13330 }
(...skipping 10 matching lines...) Expand all
13366 } 13341 }
13367 13342
13368 13343
13369 THREADED_TEST(NewPersistentHandleFromWeakCallback) { 13344 THREADED_TEST(NewPersistentHandleFromWeakCallback) {
13370 LocalContext context; 13345 LocalContext context;
13371 v8::Isolate* isolate = context->GetIsolate(); 13346 v8::Isolate* isolate = context->GetIsolate();
13372 13347
13373 v8::Persistent<v8::Object> handle1, handle2; 13348 v8::Persistent<v8::Object> handle1, handle2;
13374 { 13349 {
13375 v8::HandleScope scope(isolate); 13350 v8::HandleScope scope(isolate);
13376 some_object.Reset(isolate, v8::Object::New(isolate)); 13351 some_object.Reset(isolate, v8::Object::New());
13377 handle1.Reset(isolate, v8::Object::New(isolate)); 13352 handle1.Reset(isolate, v8::Object::New());
13378 handle2.Reset(isolate, v8::Object::New(isolate)); 13353 handle2.Reset(isolate, v8::Object::New());
13379 } 13354 }
13380 // Note: order is implementation dependent alas: currently 13355 // Note: order is implementation dependent alas: currently
13381 // global handle nodes are processed by PostGarbageCollectionProcessing 13356 // global handle nodes are processed by PostGarbageCollectionProcessing
13382 // in reverse allocation order, so if second allocated handle is deleted, 13357 // in reverse allocation order, so if second allocated handle is deleted,
13383 // weak callback of the first handle would be able to 'reallocate' it. 13358 // weak callback of the first handle would be able to 'reallocate' it.
13384 handle1.SetWeak(&handle1, NewPersistentHandleCallback); 13359 handle1.SetWeak(&handle1, NewPersistentHandleCallback);
13385 handle2.Reset(); 13360 handle2.Reset();
13386 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 13361 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
13387 } 13362 }
13388 13363
13389 13364
13390 v8::Persistent<v8::Object> to_be_disposed; 13365 v8::Persistent<v8::Object> to_be_disposed;
13391 13366
13392 void DisposeAndForceGcCallback( 13367 void DisposeAndForceGcCallback(
13393 const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) { 13368 const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) {
13394 to_be_disposed.Reset(); 13369 to_be_disposed.Reset();
13395 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 13370 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
13396 data.GetParameter()->Reset(); 13371 data.GetParameter()->Reset();
13397 } 13372 }
13398 13373
13399 13374
13400 THREADED_TEST(DoNotUseDeletedNodesInSecondLevelGc) { 13375 THREADED_TEST(DoNotUseDeletedNodesInSecondLevelGc) {
13401 LocalContext context; 13376 LocalContext context;
13402 v8::Isolate* isolate = context->GetIsolate(); 13377 v8::Isolate* isolate = context->GetIsolate();
13403 13378
13404 v8::Persistent<v8::Object> handle1, handle2; 13379 v8::Persistent<v8::Object> handle1, handle2;
13405 { 13380 {
13406 v8::HandleScope scope(isolate); 13381 v8::HandleScope scope(isolate);
13407 handle1.Reset(isolate, v8::Object::New(isolate)); 13382 handle1.Reset(isolate, v8::Object::New());
13408 handle2.Reset(isolate, v8::Object::New(isolate)); 13383 handle2.Reset(isolate, v8::Object::New());
13409 } 13384 }
13410 handle1.SetWeak(&handle1, DisposeAndForceGcCallback); 13385 handle1.SetWeak(&handle1, DisposeAndForceGcCallback);
13411 to_be_disposed.Reset(isolate, handle2); 13386 to_be_disposed.Reset(isolate, handle2);
13412 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 13387 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
13413 } 13388 }
13414 13389
13415 void DisposingCallback( 13390 void DisposingCallback(
13416 const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) { 13391 const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) {
13417 data.GetParameter()->Reset(); 13392 data.GetParameter()->Reset();
13418 } 13393 }
13419 13394
13420 void HandleCreatingCallback( 13395 void HandleCreatingCallback(
13421 const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) { 13396 const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) {
13422 v8::HandleScope scope(data.GetIsolate()); 13397 v8::HandleScope scope(data.GetIsolate());
13423 v8::Persistent<v8::Object>(data.GetIsolate(), 13398 v8::Persistent<v8::Object>(data.GetIsolate(), v8::Object::New());
13424 v8::Object::New(data.GetIsolate()));
13425 data.GetParameter()->Reset(); 13399 data.GetParameter()->Reset();
13426 } 13400 }
13427 13401
13428 13402
13429 THREADED_TEST(NoGlobalHandlesOrphaningDueToWeakCallback) { 13403 THREADED_TEST(NoGlobalHandlesOrphaningDueToWeakCallback) {
13430 LocalContext context; 13404 LocalContext context;
13431 v8::Isolate* isolate = context->GetIsolate(); 13405 v8::Isolate* isolate = context->GetIsolate();
13432 13406
13433 v8::Persistent<v8::Object> handle1, handle2, handle3; 13407 v8::Persistent<v8::Object> handle1, handle2, handle3;
13434 { 13408 {
13435 v8::HandleScope scope(isolate); 13409 v8::HandleScope scope(isolate);
13436 handle3.Reset(isolate, v8::Object::New(isolate)); 13410 handle3.Reset(isolate, v8::Object::New());
13437 handle2.Reset(isolate, v8::Object::New(isolate)); 13411 handle2.Reset(isolate, v8::Object::New());
13438 handle1.Reset(isolate, v8::Object::New(isolate)); 13412 handle1.Reset(isolate, v8::Object::New());
13439 } 13413 }
13440 handle2.SetWeak(&handle2, DisposingCallback); 13414 handle2.SetWeak(&handle2, DisposingCallback);
13441 handle3.SetWeak(&handle3, HandleCreatingCallback); 13415 handle3.SetWeak(&handle3, HandleCreatingCallback);
13442 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 13416 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
13443 } 13417 }
13444 13418
13445 13419
13446 THREADED_TEST(CheckForCrossContextObjectLiterals) { 13420 THREADED_TEST(CheckForCrossContextObjectLiterals) {
13447 v8::V8::Initialize(); 13421 v8::V8::Initialize();
13448 13422
(...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after
14175 14149
14176 resource_name = "test1.js"; 14150 resource_name = "test1.js";
14177 v8::ScriptOrigin origin1( 14151 v8::ScriptOrigin origin1(
14178 v8::String::NewFromUtf8(context->GetIsolate(), resource_name)); 14152 v8::String::NewFromUtf8(context->GetIsolate(), resource_name));
14179 script = v8::Script::Compile(source, &origin1); 14153 script = v8::Script::Compile(source, &origin1);
14180 CheckTryCatchSourceInfo(script, resource_name, 0); 14154 CheckTryCatchSourceInfo(script, resource_name, 0);
14181 14155
14182 resource_name = "test2.js"; 14156 resource_name = "test2.js";
14183 v8::ScriptOrigin origin2( 14157 v8::ScriptOrigin origin2(
14184 v8::String::NewFromUtf8(context->GetIsolate(), resource_name), 14158 v8::String::NewFromUtf8(context->GetIsolate(), resource_name),
14185 v8::Integer::New(context->GetIsolate(), 7)); 14159 v8::Integer::New(7));
14186 script = v8::Script::Compile(source, &origin2); 14160 script = v8::Script::Compile(source, &origin2);
14187 CheckTryCatchSourceInfo(script, resource_name, 7); 14161 CheckTryCatchSourceInfo(script, resource_name, 7);
14188 } 14162 }
14189 14163
14190 14164
14191 THREADED_TEST(CompilationCache) { 14165 THREADED_TEST(CompilationCache) {
14192 LocalContext context; 14166 LocalContext context;
14193 v8::HandleScope scope(context->GetIsolate()); 14167 v8::HandleScope scope(context->GetIsolate());
14194 v8::Handle<v8::String> source0 = 14168 v8::Handle<v8::String> source0 =
14195 v8::String::NewFromUtf8(context->GetIsolate(), "1234"); 14169 v8::String::NewFromUtf8(context->GetIsolate(), "1234");
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
14232 THREADED_TEST(DateAccess) { 14206 THREADED_TEST(DateAccess) {
14233 LocalContext context; 14207 LocalContext context;
14234 v8::HandleScope scope(context->GetIsolate()); 14208 v8::HandleScope scope(context->GetIsolate());
14235 v8::Handle<v8::Value> date = 14209 v8::Handle<v8::Value> date =
14236 v8::Date::New(context->GetIsolate(), 1224744689038.0); 14210 v8::Date::New(context->GetIsolate(), 1224744689038.0);
14237 CHECK(date->IsDate()); 14211 CHECK(date->IsDate());
14238 CHECK_EQ(1224744689038.0, date.As<v8::Date>()->ValueOf()); 14212 CHECK_EQ(1224744689038.0, date.As<v8::Date>()->ValueOf());
14239 } 14213 }
14240 14214
14241 14215
14242 void CheckProperties(v8::Isolate* isolate, 14216 void CheckProperties(v8::Handle<v8::Value> val, int elmc, const char* elmv[]) {
14243 v8::Handle<v8::Value> val,
14244 int elmc,
14245 const char* elmv[]) {
14246 v8::Handle<v8::Object> obj = val.As<v8::Object>(); 14217 v8::Handle<v8::Object> obj = val.As<v8::Object>();
14247 v8::Handle<v8::Array> props = obj->GetPropertyNames(); 14218 v8::Handle<v8::Array> props = obj->GetPropertyNames();
14248 CHECK_EQ(elmc, props->Length()); 14219 CHECK_EQ(elmc, props->Length());
14249 for (int i = 0; i < elmc; i++) { 14220 for (int i = 0; i < elmc; i++) {
14250 v8::String::Utf8Value elm(props->Get(v8::Integer::New(isolate, i))); 14221 v8::String::Utf8Value elm(props->Get(v8::Integer::New(i)));
14251 CHECK_EQ(elmv[i], *elm); 14222 CHECK_EQ(elmv[i], *elm);
14252 } 14223 }
14253 } 14224 }
14254 14225
14255 14226
14256 void CheckOwnProperties(v8::Isolate* isolate, 14227 void CheckOwnProperties(v8::Handle<v8::Value> val,
14257 v8::Handle<v8::Value> val,
14258 int elmc, 14228 int elmc,
14259 const char* elmv[]) { 14229 const char* elmv[]) {
14260 v8::Handle<v8::Object> obj = val.As<v8::Object>(); 14230 v8::Handle<v8::Object> obj = val.As<v8::Object>();
14261 v8::Handle<v8::Array> props = obj->GetOwnPropertyNames(); 14231 v8::Handle<v8::Array> props = obj->GetOwnPropertyNames();
14262 CHECK_EQ(elmc, props->Length()); 14232 CHECK_EQ(elmc, props->Length());
14263 for (int i = 0; i < elmc; i++) { 14233 for (int i = 0; i < elmc; i++) {
14264 v8::String::Utf8Value elm(props->Get(v8::Integer::New(isolate, i))); 14234 v8::String::Utf8Value elm(props->Get(v8::Integer::New(i)));
14265 CHECK_EQ(elmv[i], *elm); 14235 CHECK_EQ(elmv[i], *elm);
14266 } 14236 }
14267 } 14237 }
14268 14238
14269 14239
14270 THREADED_TEST(PropertyEnumeration) { 14240 THREADED_TEST(PropertyEnumeration) {
14271 LocalContext context; 14241 LocalContext context;
14272 v8::Isolate* isolate = context->GetIsolate(); 14242 v8::HandleScope scope(context->GetIsolate());
14273 v8::HandleScope scope(isolate);
14274 v8::Handle<v8::Value> obj = v8::Script::Compile(v8::String::NewFromUtf8( 14243 v8::Handle<v8::Value> obj = v8::Script::Compile(v8::String::NewFromUtf8(
14275 context->GetIsolate(), 14244 context->GetIsolate(),
14276 "var result = [];" 14245 "var result = [];"
14277 "result[0] = {};" 14246 "result[0] = {};"
14278 "result[1] = {a: 1, b: 2};" 14247 "result[1] = {a: 1, b: 2};"
14279 "result[2] = [1, 2, 3];" 14248 "result[2] = [1, 2, 3];"
14280 "var proto = {x: 1, y: 2, z: 3};" 14249 "var proto = {x: 1, y: 2, z: 3};"
14281 "var x = { __proto__: proto, w: 0, z: 1 };" 14250 "var x = { __proto__: proto, w: 0, z: 1 };"
14282 "result[3] = x;" 14251 "result[3] = x;"
14283 "result;"))->Run(); 14252 "result;"))->Run();
14284 v8::Handle<v8::Array> elms = obj.As<v8::Array>(); 14253 v8::Handle<v8::Array> elms = obj.As<v8::Array>();
14285 CHECK_EQ(4, elms->Length()); 14254 CHECK_EQ(4, elms->Length());
14286 int elmc0 = 0; 14255 int elmc0 = 0;
14287 const char** elmv0 = NULL; 14256 const char** elmv0 = NULL;
14288 CheckProperties( 14257 CheckProperties(elms->Get(v8::Integer::New(0)), elmc0, elmv0);
14289 isolate, elms->Get(v8::Integer::New(isolate, 0)), elmc0, elmv0); 14258 CheckOwnProperties(elms->Get(v8::Integer::New(0)), elmc0, elmv0);
14290 CheckOwnProperties(
14291 isolate, elms->Get(v8::Integer::New(isolate, 0)), elmc0, elmv0);
14292 int elmc1 = 2; 14259 int elmc1 = 2;
14293 const char* elmv1[] = {"a", "b"}; 14260 const char* elmv1[] = {"a", "b"};
14294 CheckProperties( 14261 CheckProperties(elms->Get(v8::Integer::New(1)), elmc1, elmv1);
14295 isolate, elms->Get(v8::Integer::New(isolate, 1)), elmc1, elmv1); 14262 CheckOwnProperties(elms->Get(v8::Integer::New(1)), elmc1, elmv1);
14296 CheckOwnProperties(
14297 isolate, elms->Get(v8::Integer::New(isolate, 1)), elmc1, elmv1);
14298 int elmc2 = 3; 14263 int elmc2 = 3;
14299 const char* elmv2[] = {"0", "1", "2"}; 14264 const char* elmv2[] = {"0", "1", "2"};
14300 CheckProperties( 14265 CheckProperties(elms->Get(v8::Integer::New(2)), elmc2, elmv2);
14301 isolate, elms->Get(v8::Integer::New(isolate, 2)), elmc2, elmv2); 14266 CheckOwnProperties(elms->Get(v8::Integer::New(2)), elmc2, elmv2);
14302 CheckOwnProperties(
14303 isolate, elms->Get(v8::Integer::New(isolate, 2)), elmc2, elmv2);
14304 int elmc3 = 4; 14267 int elmc3 = 4;
14305 const char* elmv3[] = {"w", "z", "x", "y"}; 14268 const char* elmv3[] = {"w", "z", "x", "y"};
14306 CheckProperties( 14269 CheckProperties(elms->Get(v8::Integer::New(3)), elmc3, elmv3);
14307 isolate, elms->Get(v8::Integer::New(isolate, 3)), elmc3, elmv3);
14308 int elmc4 = 2; 14270 int elmc4 = 2;
14309 const char* elmv4[] = {"w", "z"}; 14271 const char* elmv4[] = {"w", "z"};
14310 CheckOwnProperties( 14272 CheckOwnProperties(elms->Get(v8::Integer::New(3)), elmc4, elmv4);
14311 isolate, elms->Get(v8::Integer::New(isolate, 3)), elmc4, elmv4);
14312 } 14273 }
14313 14274
14314 14275
14315 THREADED_TEST(PropertyEnumeration2) { 14276 THREADED_TEST(PropertyEnumeration2) {
14316 LocalContext context; 14277 LocalContext context;
14317 v8::Isolate* isolate = context->GetIsolate(); 14278 v8::HandleScope scope(context->GetIsolate());
14318 v8::HandleScope scope(isolate);
14319 v8::Handle<v8::Value> obj = v8::Script::Compile(v8::String::NewFromUtf8( 14279 v8::Handle<v8::Value> obj = v8::Script::Compile(v8::String::NewFromUtf8(
14320 context->GetIsolate(), 14280 context->GetIsolate(),
14321 "var result = [];" 14281 "var result = [];"
14322 "result[0] = {};" 14282 "result[0] = {};"
14323 "result[1] = {a: 1, b: 2};" 14283 "result[1] = {a: 1, b: 2};"
14324 "result[2] = [1, 2, 3];" 14284 "result[2] = [1, 2, 3];"
14325 "var proto = {x: 1, y: 2, z: 3};" 14285 "var proto = {x: 1, y: 2, z: 3};"
14326 "var x = { __proto__: proto, w: 0, z: 1 };" 14286 "var x = { __proto__: proto, w: 0, z: 1 };"
14327 "result[3] = x;" 14287 "result[3] = x;"
14328 "result;"))->Run(); 14288 "result;"))->Run();
14329 v8::Handle<v8::Array> elms = obj.As<v8::Array>(); 14289 v8::Handle<v8::Array> elms = obj.As<v8::Array>();
14330 CHECK_EQ(4, elms->Length()); 14290 CHECK_EQ(4, elms->Length());
14331 int elmc0 = 0; 14291 int elmc0 = 0;
14332 const char** elmv0 = NULL; 14292 const char** elmv0 = NULL;
14333 CheckProperties(isolate, 14293 CheckProperties(elms->Get(v8::Integer::New(0)), elmc0, elmv0);
14334 elms->Get(v8::Integer::New(isolate, 0)), elmc0, elmv0);
14335 14294
14336 v8::Handle<v8::Value> val = elms->Get(v8::Integer::New(isolate, 0)); 14295 v8::Handle<v8::Value> val = elms->Get(v8::Integer::New(0));
14337 v8::Handle<v8::Array> props = val.As<v8::Object>()->GetPropertyNames(); 14296 v8::Handle<v8::Array> props = val.As<v8::Object>()->GetPropertyNames();
14338 CHECK_EQ(0, props->Length()); 14297 CHECK_EQ(0, props->Length());
14339 for (uint32_t i = 0; i < props->Length(); i++) { 14298 for (uint32_t i = 0; i < props->Length(); i++) {
14340 printf("p[%d]\n", i); 14299 printf("p[%d]\n", i);
14341 } 14300 }
14342 } 14301 }
14343 14302
14344 static bool NamedSetAccessBlocker(Local<v8::Object> obj, 14303 static bool NamedSetAccessBlocker(Local<v8::Object> obj,
14345 Local<Value> name, 14304 Local<Value> name,
14346 v8::AccessType type, 14305 v8::AccessType type,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
14400 // so that the constructor will force copying map. 14359 // so that the constructor will force copying map.
14401 // Cannot sprintf, gcc complains unsafety. 14360 // Cannot sprintf, gcc complains unsafety.
14402 char buf[4]; 14361 char buf[4];
14403 for (char i = '0'; i <= '9' ; i++) { 14362 for (char i = '0'; i <= '9' ; i++) {
14404 buf[0] = i; 14363 buf[0] = i;
14405 for (char j = '0'; j <= '9'; j++) { 14364 for (char j = '0'; j <= '9'; j++) {
14406 buf[1] = j; 14365 buf[1] = j;
14407 for (char k = '0'; k <= '9'; k++) { 14366 for (char k = '0'; k <= '9'; k++) {
14408 buf[2] = k; 14367 buf[2] = k;
14409 buf[3] = 0; 14368 buf[3] = 0;
14410 templ->Set(v8_str(buf), v8::Number::New(context->GetIsolate(), k)); 14369 templ->Set(v8_str(buf), v8::Number::New(k));
14411 } 14370 }
14412 } 14371 }
14413 } 14372 }
14414 14373
14415 Local<v8::Object> instance_1 = templ->NewInstance(); 14374 Local<v8::Object> instance_1 = templ->NewInstance();
14416 context->Global()->Set(v8_str("obj_1"), instance_1); 14375 context->Global()->Set(v8_str("obj_1"), instance_1);
14417 14376
14418 Local<Value> value_1 = CompileRun("obj_1.a"); 14377 Local<Value> value_1 = CompileRun("obj_1.a");
14419 CHECK(value_1->IsUndefined()); 14378 CHECK(value_1->IsUndefined());
14420 14379
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
14831 Local<Value> value = CompileRun("var instance = new other.C(); instance.x"); 14790 Local<Value> value = CompileRun("var instance = new other.C(); instance.x");
14832 CHECK(value->IsInt32()); 14791 CHECK(value->IsInt32());
14833 CHECK_EQ(42, value->Int32Value()); 14792 CHECK_EQ(42, value->Int32Value());
14834 context1->Exit(); 14793 context1->Exit();
14835 } 14794 }
14836 14795
14837 14796
14838 // Verify that we can clone an object 14797 // Verify that we can clone an object
14839 TEST(ObjectClone) { 14798 TEST(ObjectClone) {
14840 LocalContext env; 14799 LocalContext env;
14841 v8::Isolate* isolate = env->GetIsolate(); 14800 v8::HandleScope scope(env->GetIsolate());
14842 v8::HandleScope scope(isolate);
14843 14801
14844 const char* sample = 14802 const char* sample =
14845 "var rv = {};" \ 14803 "var rv = {};" \
14846 "rv.alpha = 'hello';" \ 14804 "rv.alpha = 'hello';" \
14847 "rv.beta = 123;" \ 14805 "rv.beta = 123;" \
14848 "rv;"; 14806 "rv;";
14849 14807
14850 // Create an object, verify basics. 14808 // Create an object, verify basics.
14851 Local<Value> val = CompileRun(sample); 14809 Local<Value> val = CompileRun(sample);
14852 CHECK(val->IsObject()); 14810 CHECK(val->IsObject());
14853 Local<v8::Object> obj = val.As<v8::Object>(); 14811 Local<v8::Object> obj = val.As<v8::Object>();
14854 obj->Set(v8_str("gamma"), v8_str("cloneme")); 14812 obj->Set(v8_str("gamma"), v8_str("cloneme"));
14855 14813
14856 CHECK_EQ(v8_str("hello"), obj->Get(v8_str("alpha"))); 14814 CHECK_EQ(v8_str("hello"), obj->Get(v8_str("alpha")));
14857 CHECK_EQ(v8::Integer::New(isolate, 123), obj->Get(v8_str("beta"))); 14815 CHECK_EQ(v8::Integer::New(123), obj->Get(v8_str("beta")));
14858 CHECK_EQ(v8_str("cloneme"), obj->Get(v8_str("gamma"))); 14816 CHECK_EQ(v8_str("cloneme"), obj->Get(v8_str("gamma")));
14859 14817
14860 // Clone it. 14818 // Clone it.
14861 Local<v8::Object> clone = obj->Clone(); 14819 Local<v8::Object> clone = obj->Clone();
14862 CHECK_EQ(v8_str("hello"), clone->Get(v8_str("alpha"))); 14820 CHECK_EQ(v8_str("hello"), clone->Get(v8_str("alpha")));
14863 CHECK_EQ(v8::Integer::New(isolate, 123), clone->Get(v8_str("beta"))); 14821 CHECK_EQ(v8::Integer::New(123), clone->Get(v8_str("beta")));
14864 CHECK_EQ(v8_str("cloneme"), clone->Get(v8_str("gamma"))); 14822 CHECK_EQ(v8_str("cloneme"), clone->Get(v8_str("gamma")));
14865 14823
14866 // Set a property on the clone, verify each object. 14824 // Set a property on the clone, verify each object.
14867 clone->Set(v8_str("beta"), v8::Integer::New(isolate, 456)); 14825 clone->Set(v8_str("beta"), v8::Integer::New(456));
14868 CHECK_EQ(v8::Integer::New(isolate, 123), obj->Get(v8_str("beta"))); 14826 CHECK_EQ(v8::Integer::New(123), obj->Get(v8_str("beta")));
14869 CHECK_EQ(v8::Integer::New(isolate, 456), clone->Get(v8_str("beta"))); 14827 CHECK_EQ(v8::Integer::New(456), clone->Get(v8_str("beta")));
14870 } 14828 }
14871 14829
14872 14830
14873 class AsciiVectorResource : public v8::String::ExternalAsciiStringResource { 14831 class AsciiVectorResource : public v8::String::ExternalAsciiStringResource {
14874 public: 14832 public:
14875 explicit AsciiVectorResource(i::Vector<const char> vector) 14833 explicit AsciiVectorResource(i::Vector<const char> vector)
14876 : data_(vector) {} 14834 : data_(vector) {}
14877 virtual ~AsciiVectorResource() {} 14835 virtual ~AsciiVectorResource() {}
14878 virtual size_t length() const { return data_.length(); } 14836 virtual size_t length() const { return data_.length(); }
14879 virtual const char* data() const { return data_.start(); } 14837 virtual const char* data() const { return data_.start(); }
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
15087 regexp_interruption_data.string.Reset(); 15045 regexp_interruption_data.string.Reset();
15088 } 15046 }
15089 15047
15090 #endif // V8_INTERPRETED_REGEXP 15048 #endif // V8_INTERPRETED_REGEXP
15091 15049
15092 15050
15093 // Test that we cannot set a property on the global object if there 15051 // Test that we cannot set a property on the global object if there
15094 // is a read-only property in the prototype chain. 15052 // is a read-only property in the prototype chain.
15095 TEST(ReadOnlyPropertyInGlobalProto) { 15053 TEST(ReadOnlyPropertyInGlobalProto) {
15096 i::FLAG_es5_readonly = true; 15054 i::FLAG_es5_readonly = true;
15097 v8::Isolate* isolate = CcTest::isolate(); 15055 v8::HandleScope scope(CcTest::isolate());
15098 v8::HandleScope scope(isolate);
15099 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); 15056 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New();
15100 LocalContext context(0, templ); 15057 LocalContext context(0, templ);
15101 v8::Handle<v8::Object> global = context->Global(); 15058 v8::Handle<v8::Object> global = context->Global();
15102 v8::Handle<v8::Object> global_proto = 15059 v8::Handle<v8::Object> global_proto =
15103 v8::Handle<v8::Object>::Cast(global->Get(v8_str("__proto__"))); 15060 v8::Handle<v8::Object>::Cast(global->Get(v8_str("__proto__")));
15104 global_proto->Set(v8_str("x"), v8::Integer::New(isolate, 0), v8::ReadOnly); 15061 global_proto->Set(v8_str("x"), v8::Integer::New(0), v8::ReadOnly);
15105 global_proto->Set(v8_str("y"), v8::Integer::New(isolate, 0), v8::ReadOnly); 15062 global_proto->Set(v8_str("y"), v8::Integer::New(0), v8::ReadOnly);
15106 // Check without 'eval' or 'with'. 15063 // Check without 'eval' or 'with'.
15107 v8::Handle<v8::Value> res = 15064 v8::Handle<v8::Value> res =
15108 CompileRun("function f() { x = 42; return x; }; f()"); 15065 CompileRun("function f() { x = 42; return x; }; f()");
15109 CHECK_EQ(v8::Integer::New(isolate, 0), res); 15066 CHECK_EQ(v8::Integer::New(0), res);
15110 // Check with 'eval'. 15067 // Check with 'eval'.
15111 res = CompileRun("function f() { eval('1'); y = 43; return y; }; f()"); 15068 res = CompileRun("function f() { eval('1'); y = 43; return y; }; f()");
15112 CHECK_EQ(v8::Integer::New(isolate, 0), res); 15069 CHECK_EQ(v8::Integer::New(0), res);
15113 // Check with 'with'. 15070 // Check with 'with'.
15114 res = CompileRun("function f() { with (this) { y = 44 }; return y; }; f()"); 15071 res = CompileRun("function f() { with (this) { y = 44 }; return y; }; f()");
15115 CHECK_EQ(v8::Integer::New(isolate, 0), res); 15072 CHECK_EQ(v8::Integer::New(0), res);
15116 } 15073 }
15117 15074
15118 static int force_set_set_count = 0; 15075 static int force_set_set_count = 0;
15119 static int force_set_get_count = 0; 15076 static int force_set_get_count = 0;
15120 bool pass_on_get = false; 15077 bool pass_on_get = false;
15121 15078
15122 static void ForceSetGetter(v8::Local<v8::String> name, 15079 static void ForceSetGetter(v8::Local<v8::String> name,
15123 const v8::PropertyCallbackInfo<v8::Value>& info) { 15080 const v8::PropertyCallbackInfo<v8::Value>& info) {
15124 force_set_get_count++; 15081 force_set_get_count++;
15125 if (pass_on_get) { 15082 if (pass_on_get) {
(...skipping 15 matching lines...) Expand all
15141 force_set_set_count++; 15098 force_set_set_count++;
15142 info.GetReturnValue().SetUndefined(); 15099 info.GetReturnValue().SetUndefined();
15143 } 15100 }
15144 15101
15145 15102
15146 TEST(ForceSet) { 15103 TEST(ForceSet) {
15147 force_set_get_count = 0; 15104 force_set_get_count = 0;
15148 force_set_set_count = 0; 15105 force_set_set_count = 0;
15149 pass_on_get = false; 15106 pass_on_get = false;
15150 15107
15151 v8::Isolate* isolate = CcTest::isolate(); 15108 v8::HandleScope scope(CcTest::isolate());
15152 v8::HandleScope scope(isolate);
15153 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); 15109 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New();
15154 v8::Handle<v8::String> access_property = 15110 v8::Handle<v8::String> access_property =
15155 v8::String::NewFromUtf8(isolate, "a"); 15111 v8::String::NewFromUtf8(CcTest::isolate(), "a");
15156 templ->SetAccessor(access_property, ForceSetGetter, ForceSetSetter); 15112 templ->SetAccessor(access_property, ForceSetGetter, ForceSetSetter);
15157 LocalContext context(NULL, templ); 15113 LocalContext context(NULL, templ);
15158 v8::Handle<v8::Object> global = context->Global(); 15114 v8::Handle<v8::Object> global = context->Global();
15159 15115
15160 // Ordinary properties 15116 // Ordinary properties
15161 v8::Handle<v8::String> simple_property = 15117 v8::Handle<v8::String> simple_property =
15162 v8::String::NewFromUtf8(isolate, "p"); 15118 v8::String::NewFromUtf8(CcTest::isolate(), "p");
15163 global->Set(simple_property, v8::Int32::New(isolate, 4), v8::ReadOnly); 15119 global->Set(simple_property, v8::Int32::New(4), v8::ReadOnly);
15164 CHECK_EQ(4, global->Get(simple_property)->Int32Value()); 15120 CHECK_EQ(4, global->Get(simple_property)->Int32Value());
15165 // This should fail because the property is read-only 15121 // This should fail because the property is read-only
15166 global->Set(simple_property, v8::Int32::New(isolate, 5)); 15122 global->Set(simple_property, v8::Int32::New(5));
15167 CHECK_EQ(4, global->Get(simple_property)->Int32Value()); 15123 CHECK_EQ(4, global->Get(simple_property)->Int32Value());
15168 // This should succeed even though the property is read-only 15124 // This should succeed even though the property is read-only
15169 global->ForceSet(simple_property, v8::Int32::New(isolate, 6)); 15125 global->ForceSet(simple_property, v8::Int32::New(6));
15170 CHECK_EQ(6, global->Get(simple_property)->Int32Value()); 15126 CHECK_EQ(6, global->Get(simple_property)->Int32Value());
15171 15127
15172 // Accessors 15128 // Accessors
15173 CHECK_EQ(0, force_set_set_count); 15129 CHECK_EQ(0, force_set_set_count);
15174 CHECK_EQ(0, force_set_get_count); 15130 CHECK_EQ(0, force_set_get_count);
15175 CHECK_EQ(3, global->Get(access_property)->Int32Value()); 15131 CHECK_EQ(3, global->Get(access_property)->Int32Value());
15176 // CHECK_EQ the property shouldn't override it, just call the setter 15132 // CHECK_EQ the property shouldn't override it, just call the setter
15177 // which in this case does nothing. 15133 // which in this case does nothing.
15178 global->Set(access_property, v8::Int32::New(isolate, 7)); 15134 global->Set(access_property, v8::Int32::New(7));
15179 CHECK_EQ(3, global->Get(access_property)->Int32Value()); 15135 CHECK_EQ(3, global->Get(access_property)->Int32Value());
15180 CHECK_EQ(1, force_set_set_count); 15136 CHECK_EQ(1, force_set_set_count);
15181 CHECK_EQ(2, force_set_get_count); 15137 CHECK_EQ(2, force_set_get_count);
15182 // Forcing the property to be set should override the accessor without 15138 // Forcing the property to be set should override the accessor without
15183 // calling it 15139 // calling it
15184 global->ForceSet(access_property, v8::Int32::New(isolate, 8)); 15140 global->ForceSet(access_property, v8::Int32::New(8));
15185 CHECK_EQ(8, global->Get(access_property)->Int32Value()); 15141 CHECK_EQ(8, global->Get(access_property)->Int32Value());
15186 CHECK_EQ(1, force_set_set_count); 15142 CHECK_EQ(1, force_set_set_count);
15187 CHECK_EQ(2, force_set_get_count); 15143 CHECK_EQ(2, force_set_get_count);
15188 } 15144 }
15189 15145
15190 15146
15191 TEST(ForceSetWithInterceptor) { 15147 TEST(ForceSetWithInterceptor) {
15192 force_set_get_count = 0; 15148 force_set_get_count = 0;
15193 force_set_set_count = 0; 15149 force_set_set_count = 0;
15194 pass_on_get = false; 15150 pass_on_get = false;
15195 15151
15196 v8::Isolate* isolate = CcTest::isolate(); 15152 v8::HandleScope scope(CcTest::isolate());
15197 v8::HandleScope scope(isolate);
15198 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); 15153 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New();
15199 templ->SetNamedPropertyHandler(ForceSetGetter, ForceSetInterceptSetter); 15154 templ->SetNamedPropertyHandler(ForceSetGetter, ForceSetInterceptSetter);
15200 LocalContext context(NULL, templ); 15155 LocalContext context(NULL, templ);
15201 v8::Handle<v8::Object> global = context->Global(); 15156 v8::Handle<v8::Object> global = context->Global();
15202 15157
15203 v8::Handle<v8::String> some_property = 15158 v8::Handle<v8::String> some_property =
15204 v8::String::NewFromUtf8(isolate, "a"); 15159 v8::String::NewFromUtf8(CcTest::isolate(), "a");
15205 CHECK_EQ(0, force_set_set_count); 15160 CHECK_EQ(0, force_set_set_count);
15206 CHECK_EQ(0, force_set_get_count); 15161 CHECK_EQ(0, force_set_get_count);
15207 CHECK_EQ(3, global->Get(some_property)->Int32Value()); 15162 CHECK_EQ(3, global->Get(some_property)->Int32Value());
15208 // Setting the property shouldn't override it, just call the setter 15163 // Setting the property shouldn't override it, just call the setter
15209 // which in this case does nothing. 15164 // which in this case does nothing.
15210 global->Set(some_property, v8::Int32::New(isolate, 7)); 15165 global->Set(some_property, v8::Int32::New(7));
15211 CHECK_EQ(3, global->Get(some_property)->Int32Value()); 15166 CHECK_EQ(3, global->Get(some_property)->Int32Value());
15212 CHECK_EQ(1, force_set_set_count); 15167 CHECK_EQ(1, force_set_set_count);
15213 CHECK_EQ(2, force_set_get_count); 15168 CHECK_EQ(2, force_set_get_count);
15214 // Getting the property when the interceptor returns an empty handle 15169 // Getting the property when the interceptor returns an empty handle
15215 // should yield undefined, since the property isn't present on the 15170 // should yield undefined, since the property isn't present on the
15216 // object itself yet. 15171 // object itself yet.
15217 pass_on_get = true; 15172 pass_on_get = true;
15218 CHECK(global->Get(some_property)->IsUndefined()); 15173 CHECK(global->Get(some_property)->IsUndefined());
15219 CHECK_EQ(1, force_set_set_count); 15174 CHECK_EQ(1, force_set_set_count);
15220 CHECK_EQ(3, force_set_get_count); 15175 CHECK_EQ(3, force_set_get_count);
15221 // Forcing the property to be set should cause the value to be 15176 // Forcing the property to be set should cause the value to be
15222 // set locally without calling the interceptor. 15177 // set locally without calling the interceptor.
15223 global->ForceSet(some_property, v8::Int32::New(isolate, 8)); 15178 global->ForceSet(some_property, v8::Int32::New(8));
15224 CHECK_EQ(8, global->Get(some_property)->Int32Value()); 15179 CHECK_EQ(8, global->Get(some_property)->Int32Value());
15225 CHECK_EQ(1, force_set_set_count); 15180 CHECK_EQ(1, force_set_set_count);
15226 CHECK_EQ(4, force_set_get_count); 15181 CHECK_EQ(4, force_set_get_count);
15227 // Reenabling the interceptor should cause it to take precedence over 15182 // Reenabling the interceptor should cause it to take precedence over
15228 // the property 15183 // the property
15229 pass_on_get = false; 15184 pass_on_get = false;
15230 CHECK_EQ(3, global->Get(some_property)->Int32Value()); 15185 CHECK_EQ(3, global->Get(some_property)->Int32Value());
15231 CHECK_EQ(1, force_set_set_count); 15186 CHECK_EQ(1, force_set_set_count);
15232 CHECK_EQ(5, force_set_get_count); 15187 CHECK_EQ(5, force_set_get_count);
15233 // The interceptor should also work for other properties 15188 // The interceptor should also work for other properties
15234 CHECK_EQ(3, global->Get(v8::String::NewFromUtf8(isolate, "b")) 15189 CHECK_EQ(3, global->Get(v8::String::NewFromUtf8(CcTest::isolate(), "b"))
15235 ->Int32Value()); 15190 ->Int32Value());
15236 CHECK_EQ(1, force_set_set_count); 15191 CHECK_EQ(1, force_set_set_count);
15237 CHECK_EQ(6, force_set_get_count); 15192 CHECK_EQ(6, force_set_get_count);
15238 } 15193 }
15239 15194
15240 15195
15241 THREADED_TEST(ForceDelete) { 15196 THREADED_TEST(ForceDelete) {
15242 v8::Isolate* isolate = CcTest::isolate(); 15197 v8::HandleScope scope(CcTest::isolate());
15243 v8::HandleScope scope(isolate);
15244 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); 15198 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New();
15245 LocalContext context(NULL, templ); 15199 LocalContext context(NULL, templ);
15246 v8::Handle<v8::Object> global = context->Global(); 15200 v8::Handle<v8::Object> global = context->Global();
15247 15201
15248 // Ordinary properties 15202 // Ordinary properties
15249 v8::Handle<v8::String> simple_property = 15203 v8::Handle<v8::String> simple_property =
15250 v8::String::NewFromUtf8(isolate, "p"); 15204 v8::String::NewFromUtf8(CcTest::isolate(), "p");
15251 global->Set(simple_property, v8::Int32::New(isolate, 4), v8::DontDelete); 15205 global->Set(simple_property, v8::Int32::New(4), v8::DontDelete);
15252 CHECK_EQ(4, global->Get(simple_property)->Int32Value()); 15206 CHECK_EQ(4, global->Get(simple_property)->Int32Value());
15253 // This should fail because the property is dont-delete. 15207 // This should fail because the property is dont-delete.
15254 CHECK(!global->Delete(simple_property)); 15208 CHECK(!global->Delete(simple_property));
15255 CHECK_EQ(4, global->Get(simple_property)->Int32Value()); 15209 CHECK_EQ(4, global->Get(simple_property)->Int32Value());
15256 // This should succeed even though the property is dont-delete. 15210 // This should succeed even though the property is dont-delete.
15257 CHECK(global->ForceDelete(simple_property)); 15211 CHECK(global->ForceDelete(simple_property));
15258 CHECK(global->Get(simple_property)->IsUndefined()); 15212 CHECK(global->Get(simple_property)->IsUndefined());
15259 } 15213 }
15260 15214
15261 15215
15262 static int force_delete_interceptor_count = 0; 15216 static int force_delete_interceptor_count = 0;
15263 static bool pass_on_delete = false; 15217 static bool pass_on_delete = false;
15264 15218
15265 15219
15266 static void ForceDeleteDeleter( 15220 static void ForceDeleteDeleter(
15267 v8::Local<v8::String> name, 15221 v8::Local<v8::String> name,
15268 const v8::PropertyCallbackInfo<v8::Boolean>& info) { 15222 const v8::PropertyCallbackInfo<v8::Boolean>& info) {
15269 force_delete_interceptor_count++; 15223 force_delete_interceptor_count++;
15270 if (pass_on_delete) return; 15224 if (pass_on_delete) return;
15271 info.GetReturnValue().Set(true); 15225 info.GetReturnValue().Set(true);
15272 } 15226 }
15273 15227
15274 15228
15275 THREADED_TEST(ForceDeleteWithInterceptor) { 15229 THREADED_TEST(ForceDeleteWithInterceptor) {
15276 force_delete_interceptor_count = 0; 15230 force_delete_interceptor_count = 0;
15277 pass_on_delete = false; 15231 pass_on_delete = false;
15278 15232
15279 v8::Isolate* isolate = CcTest::isolate(); 15233 v8::HandleScope scope(CcTest::isolate());
15280 v8::HandleScope scope(isolate);
15281 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); 15234 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New();
15282 templ->SetNamedPropertyHandler(0, 0, 0, ForceDeleteDeleter); 15235 templ->SetNamedPropertyHandler(0, 0, 0, ForceDeleteDeleter);
15283 LocalContext context(NULL, templ); 15236 LocalContext context(NULL, templ);
15284 v8::Handle<v8::Object> global = context->Global(); 15237 v8::Handle<v8::Object> global = context->Global();
15285 15238
15286 v8::Handle<v8::String> some_property = 15239 v8::Handle<v8::String> some_property =
15287 v8::String::NewFromUtf8(isolate, "a"); 15240 v8::String::NewFromUtf8(CcTest::isolate(), "a");
15288 global->Set(some_property, v8::Integer::New(isolate, 42), v8::DontDelete); 15241 global->Set(some_property, v8::Integer::New(42), v8::DontDelete);
15289 15242
15290 // Deleting a property should get intercepted and nothing should 15243 // Deleting a property should get intercepted and nothing should
15291 // happen. 15244 // happen.
15292 CHECK_EQ(0, force_delete_interceptor_count); 15245 CHECK_EQ(0, force_delete_interceptor_count);
15293 CHECK(global->Delete(some_property)); 15246 CHECK(global->Delete(some_property));
15294 CHECK_EQ(1, force_delete_interceptor_count); 15247 CHECK_EQ(1, force_delete_interceptor_count);
15295 CHECK_EQ(42, global->Get(some_property)->Int32Value()); 15248 CHECK_EQ(42, global->Get(some_property)->Int32Value());
15296 // Deleting the property when the interceptor returns an empty 15249 // Deleting the property when the interceptor returns an empty
15297 // handle should not delete the property since it is DontDelete. 15250 // handle should not delete the property since it is DontDelete.
15298 pass_on_delete = true; 15251 pass_on_delete = true;
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
15461 15414
15462 // Regression test for issue 398. 15415 // Regression test for issue 398.
15463 // If a function is added to an object, creating a constant function 15416 // If a function is added to an object, creating a constant function
15464 // field, and the result is cloned, replacing the constant function on the 15417 // field, and the result is cloned, replacing the constant function on the
15465 // original should not affect the clone. 15418 // original should not affect the clone.
15466 // See http://code.google.com/p/v8/issues/detail?id=398 15419 // See http://code.google.com/p/v8/issues/detail?id=398
15467 THREADED_TEST(ReplaceConstantFunction) { 15420 THREADED_TEST(ReplaceConstantFunction) {
15468 LocalContext context; 15421 LocalContext context;
15469 v8::Isolate* isolate = context->GetIsolate(); 15422 v8::Isolate* isolate = context->GetIsolate();
15470 v8::HandleScope scope(isolate); 15423 v8::HandleScope scope(isolate);
15471 v8::Handle<v8::Object> obj = v8::Object::New(isolate); 15424 v8::Handle<v8::Object> obj = v8::Object::New();
15472 v8::Handle<v8::FunctionTemplate> func_templ = 15425 v8::Handle<v8::FunctionTemplate> func_templ =
15473 v8::FunctionTemplate::New(isolate); 15426 v8::FunctionTemplate::New(isolate);
15474 v8::Handle<v8::String> foo_string = 15427 v8::Handle<v8::String> foo_string =
15475 v8::String::NewFromUtf8(isolate, "foo"); 15428 v8::String::NewFromUtf8(isolate, "foo");
15476 obj->Set(foo_string, func_templ->GetFunction()); 15429 obj->Set(foo_string, func_templ->GetFunction());
15477 v8::Handle<v8::Object> obj_clone = obj->Clone(); 15430 v8::Handle<v8::Object> obj_clone = obj->Clone();
15478 obj_clone->Set(foo_string, 15431 obj_clone->Set(foo_string,
15479 v8::String::NewFromUtf8(isolate, "Hello")); 15432 v8::String::NewFromUtf8(isolate, "Hello"));
15480 CHECK(!obj->Get(foo_string)->IsUndefined()); 15433 CHECK(!obj->Get(foo_string)->IsUndefined());
15481 } 15434 }
(...skipping 25 matching lines...) Expand all
15507 for (int i = 0; i < kElementCount; i++) { 15460 for (int i = 0; i < kElementCount; i++) {
15508 pixels->set(i, i % 256); 15461 pixels->set(i, i % 256);
15509 } 15462 }
15510 // Force GC to trigger verification. 15463 // Force GC to trigger verification.
15511 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 15464 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
15512 for (int i = 0; i < kElementCount; i++) { 15465 for (int i = 0; i < kElementCount; i++) {
15513 CHECK_EQ(i % 256, pixels->get_scalar(i)); 15466 CHECK_EQ(i % 256, pixels->get_scalar(i));
15514 CHECK_EQ(i % 256, pixel_data[i]); 15467 CHECK_EQ(i % 256, pixel_data[i]);
15515 } 15468 }
15516 15469
15517 v8::Handle<v8::Object> obj = v8::Object::New(context->GetIsolate()); 15470 v8::Handle<v8::Object> obj = v8::Object::New();
15518 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); 15471 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj);
15519 // Set the elements to be the pixels. 15472 // Set the elements to be the pixels.
15520 // jsobj->set_elements(*pixels); 15473 // jsobj->set_elements(*pixels);
15521 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount); 15474 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount);
15522 CheckElementValue(isolate, 1, jsobj, 1); 15475 CheckElementValue(isolate, 1, jsobj, 1);
15523 obj->Set(v8_str("field"), v8::Int32::New(CcTest::isolate(), 1503)); 15476 obj->Set(v8_str("field"), v8::Int32::New(1503));
15524 context->Global()->Set(v8_str("pixels"), obj); 15477 context->Global()->Set(v8_str("pixels"), obj);
15525 v8::Handle<v8::Value> result = CompileRun("pixels.field"); 15478 v8::Handle<v8::Value> result = CompileRun("pixels.field");
15526 CHECK_EQ(1503, result->Int32Value()); 15479 CHECK_EQ(1503, result->Int32Value());
15527 result = CompileRun("pixels[1]"); 15480 result = CompileRun("pixels[1]");
15528 CHECK_EQ(1, result->Int32Value()); 15481 CHECK_EQ(1, result->Int32Value());
15529 15482
15530 result = CompileRun("var sum = 0;" 15483 result = CompileRun("var sum = 0;"
15531 "for (var i = 0; i < 8; i++) {" 15484 "for (var i = 0; i < 8; i++) {"
15532 " sum += pixels[i] = pixels[i] = -i;" 15485 " sum += pixels[i] = pixels[i] = -i;"
15533 "}" 15486 "}"
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
15872 15825
15873 free(pixel_data); 15826 free(pixel_data);
15874 } 15827 }
15875 15828
15876 15829
15877 THREADED_TEST(PixelArrayInfo) { 15830 THREADED_TEST(PixelArrayInfo) {
15878 LocalContext context; 15831 LocalContext context;
15879 v8::HandleScope scope(context->GetIsolate()); 15832 v8::HandleScope scope(context->GetIsolate());
15880 for (int size = 0; size < 100; size += 10) { 15833 for (int size = 0; size < 100; size += 10) {
15881 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(size)); 15834 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(size));
15882 v8::Handle<v8::Object> obj = v8::Object::New(context->GetIsolate()); 15835 v8::Handle<v8::Object> obj = v8::Object::New();
15883 obj->SetIndexedPropertiesToPixelData(pixel_data, size); 15836 obj->SetIndexedPropertiesToPixelData(pixel_data, size);
15884 CHECK(obj->HasIndexedPropertiesInPixelData()); 15837 CHECK(obj->HasIndexedPropertiesInPixelData());
15885 CHECK_EQ(pixel_data, obj->GetIndexedPropertiesPixelData()); 15838 CHECK_EQ(pixel_data, obj->GetIndexedPropertiesPixelData());
15886 CHECK_EQ(size, obj->GetIndexedPropertiesPixelDataLength()); 15839 CHECK_EQ(size, obj->GetIndexedPropertiesPixelDataLength());
15887 free(pixel_data); 15840 free(pixel_data);
15888 } 15841 }
15889 } 15842 }
15890 15843
15891 15844
15892 static void NotHandledIndexedPropertyGetter( 15845 static void NotHandledIndexedPropertyGetter(
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
15968 15921
15969 template <class ExternalArrayClass, class ElementType> 15922 template <class ExternalArrayClass, class ElementType>
15970 static void ObjectWithExternalArrayTestHelper( 15923 static void ObjectWithExternalArrayTestHelper(
15971 Handle<Context> context, 15924 Handle<Context> context,
15972 v8::Handle<Object> obj, 15925 v8::Handle<Object> obj,
15973 int element_count, 15926 int element_count,
15974 v8::ExternalArrayType array_type, 15927 v8::ExternalArrayType array_type,
15975 int64_t low, int64_t high) { 15928 int64_t low, int64_t high) {
15976 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); 15929 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj);
15977 i::Isolate* isolate = jsobj->GetIsolate(); 15930 i::Isolate* isolate = jsobj->GetIsolate();
15978 obj->Set(v8_str("field"), 15931 obj->Set(v8_str("field"), v8::Int32::New(1503));
15979 v8::Int32::New(reinterpret_cast<v8::Isolate*>(isolate), 1503));
15980 context->Global()->Set(v8_str("ext_array"), obj); 15932 context->Global()->Set(v8_str("ext_array"), obj);
15981 v8::Handle<v8::Value> result = CompileRun("ext_array.field"); 15933 v8::Handle<v8::Value> result = CompileRun("ext_array.field");
15982 CHECK_EQ(1503, result->Int32Value()); 15934 CHECK_EQ(1503, result->Int32Value());
15983 result = CompileRun("ext_array[1]"); 15935 result = CompileRun("ext_array[1]");
15984 CHECK_EQ(1, result->Int32Value()); 15936 CHECK_EQ(1, result->Int32Value());
15985 15937
15986 // Check pass through of assigned smis 15938 // Check pass through of assigned smis
15987 result = CompileRun("var sum = 0;" 15939 result = CompileRun("var sum = 0;"
15988 "for (var i = 0; i < 8; i++) {" 15940 "for (var i = 0; i < 8; i++) {"
15989 " sum += ext_array[i] = ext_array[i] = -i;" 15941 " sum += ext_array[i] = ext_array[i] = -i;"
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
16289 array->set(i, static_cast<ElementType>(i)); 16241 array->set(i, static_cast<ElementType>(i));
16290 } 16242 }
16291 // Force GC to trigger verification. 16243 // Force GC to trigger verification.
16292 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 16244 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
16293 for (int i = 0; i < kElementCount; i++) { 16245 for (int i = 0; i < kElementCount; i++) {
16294 CHECK_EQ(static_cast<int64_t>(i), 16246 CHECK_EQ(static_cast<int64_t>(i),
16295 static_cast<int64_t>(array->get_scalar(i))); 16247 static_cast<int64_t>(array->get_scalar(i)));
16296 CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(array_data[i])); 16248 CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(array_data[i]));
16297 } 16249 }
16298 16250
16299 v8::Handle<v8::Object> obj = v8::Object::New(context->GetIsolate()); 16251 v8::Handle<v8::Object> obj = v8::Object::New();
16300 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); 16252 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj);
16301 // Set the elements to be the external array. 16253 // Set the elements to be the external array.
16302 obj->SetIndexedPropertiesToExternalArrayData(array_data, 16254 obj->SetIndexedPropertiesToExternalArrayData(array_data,
16303 array_type, 16255 array_type,
16304 kElementCount); 16256 kElementCount);
16305 CHECK_EQ(1, 16257 CHECK_EQ(1,
16306 static_cast<int>( 16258 static_cast<int>(
16307 jsobj->GetElement(isolate, 1)->ToObjectChecked()->Number())); 16259 jsobj->GetElement(isolate, 1)->ToObjectChecked()->Number()));
16308 16260
16309 ObjectWithExternalArrayTestHelper<ExternalArrayClass, ElementType>( 16261 ObjectWithExternalArrayTestHelper<ExternalArrayClass, ElementType>(
16310 context.local(), obj, kElementCount, array_type, low, high); 16262 context.local(), obj, kElementCount, array_type, low, high);
16311 16263
16312 v8::Handle<v8::Value> result; 16264 v8::Handle<v8::Value> result;
16313 16265
16314 // Test more complex manipulations which cause eax to contain values 16266 // Test more complex manipulations which cause eax to contain values
16315 // that won't be completely overwritten by loads from the arrays. 16267 // that won't be completely overwritten by loads from the arrays.
16316 // This catches bugs in the instructions used for the KeyedLoadIC 16268 // This catches bugs in the instructions used for the KeyedLoadIC
16317 // for byte and word types. 16269 // for byte and word types.
16318 { 16270 {
16319 const int kXSize = 300; 16271 const int kXSize = 300;
16320 const int kYSize = 300; 16272 const int kYSize = 300;
16321 const int kLargeElementCount = kXSize * kYSize * 4; 16273 const int kLargeElementCount = kXSize * kYSize * 4;
16322 ElementType* large_array_data = 16274 ElementType* large_array_data =
16323 static_cast<ElementType*>(malloc(kLargeElementCount * element_size)); 16275 static_cast<ElementType*>(malloc(kLargeElementCount * element_size));
16324 v8::Handle<v8::Object> large_obj = v8::Object::New(context->GetIsolate()); 16276 v8::Handle<v8::Object> large_obj = v8::Object::New();
16325 // Set the elements to be the external array. 16277 // Set the elements to be the external array.
16326 large_obj->SetIndexedPropertiesToExternalArrayData(large_array_data, 16278 large_obj->SetIndexedPropertiesToExternalArrayData(large_array_data,
16327 array_type, 16279 array_type,
16328 kLargeElementCount); 16280 kLargeElementCount);
16329 context->Global()->Set(v8_str("large_array"), large_obj); 16281 context->Global()->Set(v8_str("large_array"), large_obj);
16330 // Initialize contents of a few rows. 16282 // Initialize contents of a few rows.
16331 for (int x = 0; x < 300; x++) { 16283 for (int x = 0; x < 300; x++) {
16332 int row = 0; 16284 int row = 0;
16333 int offset = row * 300 * 4; 16285 int offset = row * 300 * 4;
16334 large_array_data[offset + 4 * x + 0] = (ElementType) 127; 16286 large_array_data[offset + 4 * x + 0] = (ElementType) 127;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
16387 16339
16388 // The "" property descriptor is overloaded to store information about 16340 // The "" property descriptor is overloaded to store information about
16389 // the external array. Ensure that setting and accessing the "" property 16341 // the external array. Ensure that setting and accessing the "" property
16390 // works (it should overwrite the information cached about the external 16342 // works (it should overwrite the information cached about the external
16391 // array in the DescriptorArray) in various situations. 16343 // array in the DescriptorArray) in various situations.
16392 result = CompileRun("ext_array[''] = 23; ext_array['']"); 16344 result = CompileRun("ext_array[''] = 23; ext_array['']");
16393 CHECK_EQ(23, result->Int32Value()); 16345 CHECK_EQ(23, result->Int32Value());
16394 16346
16395 // Property "" set after the external array is associated with the object. 16347 // Property "" set after the external array is associated with the object.
16396 { 16348 {
16397 v8::Handle<v8::Object> obj2 = v8::Object::New(context->GetIsolate()); 16349 v8::Handle<v8::Object> obj2 = v8::Object::New();
16398 obj2->Set(v8_str("ee_test_field"), 16350 obj2->Set(v8_str("ee_test_field"), v8::Int32::New(256));
16399 v8::Int32::New(context->GetIsolate(), 256)); 16351 obj2->Set(v8_str(""), v8::Int32::New(1503));
16400 obj2->Set(v8_str(""), v8::Int32::New(context->GetIsolate(), 1503));
16401 // Set the elements to be the external array. 16352 // Set the elements to be the external array.
16402 obj2->SetIndexedPropertiesToExternalArrayData(array_data, 16353 obj2->SetIndexedPropertiesToExternalArrayData(array_data,
16403 array_type, 16354 array_type,
16404 kElementCount); 16355 kElementCount);
16405 context->Global()->Set(v8_str("ext_array"), obj2); 16356 context->Global()->Set(v8_str("ext_array"), obj2);
16406 result = CompileRun("ext_array['']"); 16357 result = CompileRun("ext_array['']");
16407 CHECK_EQ(1503, result->Int32Value()); 16358 CHECK_EQ(1503, result->Int32Value());
16408 } 16359 }
16409 16360
16410 // Property "" set after the external array is associated with the object. 16361 // Property "" set after the external array is associated with the object.
16411 { 16362 {
16412 v8::Handle<v8::Object> obj2 = v8::Object::New(context->GetIsolate()); 16363 v8::Handle<v8::Object> obj2 = v8::Object::New();
16413 obj2->Set(v8_str("ee_test_field_2"), 16364 obj2->Set(v8_str("ee_test_field_2"), v8::Int32::New(256));
16414 v8::Int32::New(context->GetIsolate(), 256));
16415 // Set the elements to be the external array. 16365 // Set the elements to be the external array.
16416 obj2->SetIndexedPropertiesToExternalArrayData(array_data, 16366 obj2->SetIndexedPropertiesToExternalArrayData(array_data,
16417 array_type, 16367 array_type,
16418 kElementCount); 16368 kElementCount);
16419 obj2->Set(v8_str(""), v8::Int32::New(context->GetIsolate(), 1503)); 16369 obj2->Set(v8_str(""), v8::Int32::New(1503));
16420 context->Global()->Set(v8_str("ext_array"), obj2); 16370 context->Global()->Set(v8_str("ext_array"), obj2);
16421 result = CompileRun("ext_array['']"); 16371 result = CompileRun("ext_array['']");
16422 CHECK_EQ(1503, result->Int32Value()); 16372 CHECK_EQ(1503, result->Int32Value());
16423 } 16373 }
16424 16374
16425 // Should reuse the map from previous test. 16375 // Should reuse the map from previous test.
16426 { 16376 {
16427 v8::Handle<v8::Object> obj2 = v8::Object::New(context->GetIsolate()); 16377 v8::Handle<v8::Object> obj2 = v8::Object::New();
16428 obj2->Set(v8_str("ee_test_field_2"), 16378 obj2->Set(v8_str("ee_test_field_2"), v8::Int32::New(256));
16429 v8::Int32::New(context->GetIsolate(), 256));
16430 // Set the elements to be the external array. Should re-use the map 16379 // Set the elements to be the external array. Should re-use the map
16431 // from previous test. 16380 // from previous test.
16432 obj2->SetIndexedPropertiesToExternalArrayData(array_data, 16381 obj2->SetIndexedPropertiesToExternalArrayData(array_data,
16433 array_type, 16382 array_type,
16434 kElementCount); 16383 kElementCount);
16435 context->Global()->Set(v8_str("ext_array"), obj2); 16384 context->Global()->Set(v8_str("ext_array"), obj2);
16436 result = CompileRun("ext_array['']"); 16385 result = CompileRun("ext_array['']");
16437 } 16386 }
16438 16387
16439 // Property "" is a constant function that shouldn't not be interfered with 16388 // Property "" is a constant function that shouldn't not be interfered with
16440 // when an external array is set. 16389 // when an external array is set.
16441 { 16390 {
16442 v8::Handle<v8::Object> obj2 = v8::Object::New(context->GetIsolate()); 16391 v8::Handle<v8::Object> obj2 = v8::Object::New();
16443 // Start 16392 // Start
16444 obj2->Set(v8_str("ee_test_field3"), 16393 obj2->Set(v8_str("ee_test_field3"), v8::Int32::New(256));
16445 v8::Int32::New(context->GetIsolate(), 256));
16446 16394
16447 // Add a constant function to an object. 16395 // Add a constant function to an object.
16448 context->Global()->Set(v8_str("ext_array"), obj2); 16396 context->Global()->Set(v8_str("ext_array"), obj2);
16449 result = CompileRun("ext_array[''] = function() {return 1503;};" 16397 result = CompileRun("ext_array[''] = function() {return 1503;};"
16450 "ext_array['']();"); 16398 "ext_array['']();");
16451 16399
16452 // Add an external array transition to the same map that 16400 // Add an external array transition to the same map that
16453 // has the constant transition. 16401 // has the constant transition.
16454 v8::Handle<v8::Object> obj3 = v8::Object::New(context->GetIsolate()); 16402 v8::Handle<v8::Object> obj3 = v8::Object::New();
16455 obj3->Set(v8_str("ee_test_field3"), 16403 obj3->Set(v8_str("ee_test_field3"), v8::Int32::New(256));
16456 v8::Int32::New(context->GetIsolate(), 256));
16457 obj3->SetIndexedPropertiesToExternalArrayData(array_data, 16404 obj3->SetIndexedPropertiesToExternalArrayData(array_data,
16458 array_type, 16405 array_type,
16459 kElementCount); 16406 kElementCount);
16460 context->Global()->Set(v8_str("ext_array"), obj3); 16407 context->Global()->Set(v8_str("ext_array"), obj3);
16461 } 16408 }
16462 16409
16463 // If a external array transition is in the map, it should get clobbered 16410 // If a external array transition is in the map, it should get clobbered
16464 // by a constant function. 16411 // by a constant function.
16465 { 16412 {
16466 // Add an external array transition. 16413 // Add an external array transition.
16467 v8::Handle<v8::Object> obj3 = v8::Object::New(context->GetIsolate()); 16414 v8::Handle<v8::Object> obj3 = v8::Object::New();
16468 obj3->Set(v8_str("ee_test_field4"), 16415 obj3->Set(v8_str("ee_test_field4"), v8::Int32::New(256));
16469 v8::Int32::New(context->GetIsolate(), 256));
16470 obj3->SetIndexedPropertiesToExternalArrayData(array_data, 16416 obj3->SetIndexedPropertiesToExternalArrayData(array_data,
16471 array_type, 16417 array_type,
16472 kElementCount); 16418 kElementCount);
16473 16419
16474 // Add a constant function to the same map that just got an external array 16420 // Add a constant function to the same map that just got an external array
16475 // transition. 16421 // transition.
16476 v8::Handle<v8::Object> obj2 = v8::Object::New(context->GetIsolate()); 16422 v8::Handle<v8::Object> obj2 = v8::Object::New();
16477 obj2->Set(v8_str("ee_test_field4"), 16423 obj2->Set(v8_str("ee_test_field4"), v8::Int32::New(256));
16478 v8::Int32::New(context->GetIsolate(), 256));
16479 context->Global()->Set(v8_str("ext_array"), obj2); 16424 context->Global()->Set(v8_str("ext_array"), obj2);
16480 result = CompileRun("ext_array[''] = function() {return 1503;};" 16425 result = CompileRun("ext_array[''] = function() {return 1503;};"
16481 "ext_array['']();"); 16426 "ext_array['']();");
16482 } 16427 }
16483 16428
16484 free(array_data); 16429 free(array_data);
16485 } 16430 }
16486 16431
16487 16432
16488 THREADED_TEST(ExternalByteArray) { 16433 THREADED_TEST(ExternalByteArray) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
16567 TestExternalFloatArray(); 16512 TestExternalFloatArray();
16568 } 16513 }
16569 16514
16570 16515
16571 void ExternalArrayInfoTestHelper(v8::ExternalArrayType array_type) { 16516 void ExternalArrayInfoTestHelper(v8::ExternalArrayType array_type) {
16572 LocalContext context; 16517 LocalContext context;
16573 v8::HandleScope scope(context->GetIsolate()); 16518 v8::HandleScope scope(context->GetIsolate());
16574 for (int size = 0; size < 100; size += 10) { 16519 for (int size = 0; size < 100; size += 10) {
16575 int element_size = ExternalArrayElementSize(array_type); 16520 int element_size = ExternalArrayElementSize(array_type);
16576 void* external_data = malloc(size * element_size); 16521 void* external_data = malloc(size * element_size);
16577 v8::Handle<v8::Object> obj = v8::Object::New(context->GetIsolate()); 16522 v8::Handle<v8::Object> obj = v8::Object::New();
16578 obj->SetIndexedPropertiesToExternalArrayData( 16523 obj->SetIndexedPropertiesToExternalArrayData(
16579 external_data, array_type, size); 16524 external_data, array_type, size);
16580 CHECK(obj->HasIndexedPropertiesInExternalArrayData()); 16525 CHECK(obj->HasIndexedPropertiesInExternalArrayData());
16581 CHECK_EQ(external_data, obj->GetIndexedPropertiesExternalArrayData()); 16526 CHECK_EQ(external_data, obj->GetIndexedPropertiesExternalArrayData());
16582 CHECK_EQ(array_type, obj->GetIndexedPropertiesExternalArrayDataType()); 16527 CHECK_EQ(array_type, obj->GetIndexedPropertiesExternalArrayDataType());
16583 CHECK_EQ(size, obj->GetIndexedPropertiesExternalArrayDataLength()); 16528 CHECK_EQ(size, obj->GetIndexedPropertiesExternalArrayDataLength());
16584 free(external_data); 16529 free(external_data);
16585 } 16530 }
16586 } 16531 }
16587 16532
16588 16533
16589 THREADED_TEST(ExternalArrayInfo) { 16534 THREADED_TEST(ExternalArrayInfo) {
16590 ExternalArrayInfoTestHelper(v8::kExternalByteArray); 16535 ExternalArrayInfoTestHelper(v8::kExternalByteArray);
16591 ExternalArrayInfoTestHelper(v8::kExternalUnsignedByteArray); 16536 ExternalArrayInfoTestHelper(v8::kExternalUnsignedByteArray);
16592 ExternalArrayInfoTestHelper(v8::kExternalShortArray); 16537 ExternalArrayInfoTestHelper(v8::kExternalShortArray);
16593 ExternalArrayInfoTestHelper(v8::kExternalUnsignedShortArray); 16538 ExternalArrayInfoTestHelper(v8::kExternalUnsignedShortArray);
16594 ExternalArrayInfoTestHelper(v8::kExternalIntArray); 16539 ExternalArrayInfoTestHelper(v8::kExternalIntArray);
16595 ExternalArrayInfoTestHelper(v8::kExternalUnsignedIntArray); 16540 ExternalArrayInfoTestHelper(v8::kExternalUnsignedIntArray);
16596 ExternalArrayInfoTestHelper(v8::kExternalFloatArray); 16541 ExternalArrayInfoTestHelper(v8::kExternalFloatArray);
16597 ExternalArrayInfoTestHelper(v8::kExternalDoubleArray); 16542 ExternalArrayInfoTestHelper(v8::kExternalDoubleArray);
16598 ExternalArrayInfoTestHelper(v8::kExternalPixelArray); 16543 ExternalArrayInfoTestHelper(v8::kExternalPixelArray);
16599 } 16544 }
16600 16545
16601 16546
16602 void ExtArrayLimitsHelper(v8::Isolate* isolate, 16547 void ExternalArrayLimitTestHelper(v8::ExternalArrayType array_type, int size) {
16603 v8::ExternalArrayType array_type, 16548 v8::Handle<v8::Object> obj = v8::Object::New();
16604 int size) {
16605 v8::Handle<v8::Object> obj = v8::Object::New(isolate);
16606 v8::V8::SetFatalErrorHandler(StoringErrorCallback); 16549 v8::V8::SetFatalErrorHandler(StoringErrorCallback);
16607 last_location = last_message = NULL; 16550 last_location = last_message = NULL;
16608 obj->SetIndexedPropertiesToExternalArrayData(NULL, array_type, size); 16551 obj->SetIndexedPropertiesToExternalArrayData(NULL, array_type, size);
16609 CHECK(!obj->HasIndexedPropertiesInExternalArrayData()); 16552 CHECK(!obj->HasIndexedPropertiesInExternalArrayData());
16610 CHECK_NE(NULL, last_location); 16553 CHECK_NE(NULL, last_location);
16611 CHECK_NE(NULL, last_message); 16554 CHECK_NE(NULL, last_message);
16612 } 16555 }
16613 16556
16614 16557
16615 TEST(ExternalArrayLimits) { 16558 TEST(ExternalArrayLimits) {
16616 LocalContext context; 16559 LocalContext context;
16617 v8::Isolate* isolate = context->GetIsolate(); 16560 v8::HandleScope scope(context->GetIsolate());
16618 v8::HandleScope scope(isolate); 16561 ExternalArrayLimitTestHelper(v8::kExternalByteArray, 0x40000000);
16619 ExtArrayLimitsHelper(isolate, v8::kExternalByteArray, 0x40000000); 16562 ExternalArrayLimitTestHelper(v8::kExternalByteArray, 0xffffffff);
16620 ExtArrayLimitsHelper(isolate, v8::kExternalByteArray, 0xffffffff); 16563 ExternalArrayLimitTestHelper(v8::kExternalUnsignedByteArray, 0x40000000);
16621 ExtArrayLimitsHelper(isolate, v8::kExternalUnsignedByteArray, 0x40000000); 16564 ExternalArrayLimitTestHelper(v8::kExternalUnsignedByteArray, 0xffffffff);
16622 ExtArrayLimitsHelper(isolate, v8::kExternalUnsignedByteArray, 0xffffffff); 16565 ExternalArrayLimitTestHelper(v8::kExternalShortArray, 0x40000000);
16623 ExtArrayLimitsHelper(isolate, v8::kExternalShortArray, 0x40000000); 16566 ExternalArrayLimitTestHelper(v8::kExternalShortArray, 0xffffffff);
16624 ExtArrayLimitsHelper(isolate, v8::kExternalShortArray, 0xffffffff); 16567 ExternalArrayLimitTestHelper(v8::kExternalUnsignedShortArray, 0x40000000);
16625 ExtArrayLimitsHelper(isolate, v8::kExternalUnsignedShortArray, 0x40000000); 16568 ExternalArrayLimitTestHelper(v8::kExternalUnsignedShortArray, 0xffffffff);
16626 ExtArrayLimitsHelper(isolate, v8::kExternalUnsignedShortArray, 0xffffffff); 16569 ExternalArrayLimitTestHelper(v8::kExternalIntArray, 0x40000000);
16627 ExtArrayLimitsHelper(isolate, v8::kExternalIntArray, 0x40000000); 16570 ExternalArrayLimitTestHelper(v8::kExternalIntArray, 0xffffffff);
16628 ExtArrayLimitsHelper(isolate, v8::kExternalIntArray, 0xffffffff); 16571 ExternalArrayLimitTestHelper(v8::kExternalUnsignedIntArray, 0x40000000);
16629 ExtArrayLimitsHelper(isolate, v8::kExternalUnsignedIntArray, 0x40000000); 16572 ExternalArrayLimitTestHelper(v8::kExternalUnsignedIntArray, 0xffffffff);
16630 ExtArrayLimitsHelper(isolate, v8::kExternalUnsignedIntArray, 0xffffffff); 16573 ExternalArrayLimitTestHelper(v8::kExternalFloatArray, 0x40000000);
16631 ExtArrayLimitsHelper(isolate, v8::kExternalFloatArray, 0x40000000); 16574 ExternalArrayLimitTestHelper(v8::kExternalFloatArray, 0xffffffff);
16632 ExtArrayLimitsHelper(isolate, v8::kExternalFloatArray, 0xffffffff); 16575 ExternalArrayLimitTestHelper(v8::kExternalDoubleArray, 0x40000000);
16633 ExtArrayLimitsHelper(isolate, v8::kExternalDoubleArray, 0x40000000); 16576 ExternalArrayLimitTestHelper(v8::kExternalDoubleArray, 0xffffffff);
16634 ExtArrayLimitsHelper(isolate, v8::kExternalDoubleArray, 0xffffffff); 16577 ExternalArrayLimitTestHelper(v8::kExternalPixelArray, 0x40000000);
16635 ExtArrayLimitsHelper(isolate, v8::kExternalPixelArray, 0x40000000); 16578 ExternalArrayLimitTestHelper(v8::kExternalPixelArray, 0xffffffff);
16636 ExtArrayLimitsHelper(isolate, v8::kExternalPixelArray, 0xffffffff);
16637 } 16579 }
16638 16580
16639 16581
16640 template <typename ElementType, typename TypedArray, 16582 template <typename ElementType, typename TypedArray,
16641 class ExternalArrayClass> 16583 class ExternalArrayClass>
16642 void TypedArrayTestHelper(v8::ExternalArrayType array_type, 16584 void TypedArrayTestHelper(v8::ExternalArrayType array_type,
16643 int64_t low, int64_t high) { 16585 int64_t low, int64_t high) {
16644 const int kElementCount = 50; 16586 const int kElementCount = 50;
16645 16587
16646 i::ScopedVector<ElementType> backing_store(kElementCount+2); 16588 i::ScopedVector<ElementType> backing_store(kElementCount+2);
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
16778 16720
16779 THREADED_TEST(ScriptContextDependence) { 16721 THREADED_TEST(ScriptContextDependence) {
16780 LocalContext c1; 16722 LocalContext c1;
16781 v8::HandleScope scope(c1->GetIsolate()); 16723 v8::HandleScope scope(c1->GetIsolate());
16782 const char *source = "foo"; 16724 const char *source = "foo";
16783 v8::Handle<v8::Script> dep = 16725 v8::Handle<v8::Script> dep =
16784 v8::Script::Compile(v8::String::NewFromUtf8(c1->GetIsolate(), source)); 16726 v8::Script::Compile(v8::String::NewFromUtf8(c1->GetIsolate(), source));
16785 v8::Handle<v8::Script> indep = 16727 v8::Handle<v8::Script> indep =
16786 v8::Script::New(v8::String::NewFromUtf8(c1->GetIsolate(), source)); 16728 v8::Script::New(v8::String::NewFromUtf8(c1->GetIsolate(), source));
16787 c1->Global()->Set(v8::String::NewFromUtf8(c1->GetIsolate(), "foo"), 16729 c1->Global()->Set(v8::String::NewFromUtf8(c1->GetIsolate(), "foo"),
16788 v8::Integer::New(c1->GetIsolate(), 100)); 16730 v8::Integer::New(100));
16789 CHECK_EQ(dep->Run()->Int32Value(), 100); 16731 CHECK_EQ(dep->Run()->Int32Value(), 100);
16790 CHECK_EQ(indep->Run()->Int32Value(), 100); 16732 CHECK_EQ(indep->Run()->Int32Value(), 100);
16791 LocalContext c2; 16733 LocalContext c2;
16792 c2->Global()->Set(v8::String::NewFromUtf8(c2->GetIsolate(), "foo"), 16734 c2->Global()->Set(v8::String::NewFromUtf8(c2->GetIsolate(), "foo"),
16793 v8::Integer::New(c2->GetIsolate(), 101)); 16735 v8::Integer::New(101));
16794 CHECK_EQ(dep->Run()->Int32Value(), 100); 16736 CHECK_EQ(dep->Run()->Int32Value(), 100);
16795 CHECK_EQ(indep->Run()->Int32Value(), 101); 16737 CHECK_EQ(indep->Run()->Int32Value(), 101);
16796 } 16738 }
16797 16739
16798 16740
16799 THREADED_TEST(StackTrace) { 16741 THREADED_TEST(StackTrace) {
16800 LocalContext context; 16742 LocalContext context;
16801 v8::HandleScope scope(context->GetIsolate()); 16743 v8::HandleScope scope(context->GetIsolate());
16802 v8::TryCatch try_catch; 16744 v8::TryCatch try_catch;
16803 const char *source = "function foo() { FAIL.FAIL; }; foo();"; 16745 const char *source = "function foo() { FAIL.FAIL; }; foo();";
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
16921 "function bat() {AnalyzeStackInNativeCode(2);\n" 16863 "function bat() {AnalyzeStackInNativeCode(2);\n"
16922 "}\n" 16864 "}\n"
16923 "\n" 16865 "\n"
16924 "function baz() {\n" 16866 "function baz() {\n"
16925 " bat();\n" 16867 " bat();\n"
16926 "}\n" 16868 "}\n"
16927 "eval('new baz();');"; 16869 "eval('new baz();');";
16928 v8::Handle<v8::String> detailed_src = 16870 v8::Handle<v8::String> detailed_src =
16929 v8::String::NewFromUtf8(isolate, detailed_source); 16871 v8::String::NewFromUtf8(isolate, detailed_source);
16930 // Make the script using a non-zero line and column offset. 16872 // Make the script using a non-zero line and column offset.
16931 v8::Handle<v8::Integer> line_offset = v8::Integer::New(isolate, 3); 16873 v8::Handle<v8::Integer> line_offset = v8::Integer::New(3);
16932 v8::Handle<v8::Integer> column_offset = v8::Integer::New(isolate, 5); 16874 v8::Handle<v8::Integer> column_offset = v8::Integer::New(5);
16933 v8::ScriptOrigin detailed_origin(origin, line_offset, column_offset); 16875 v8::ScriptOrigin detailed_origin(origin, line_offset, column_offset);
16934 v8::Handle<v8::Script> detailed_script( 16876 v8::Handle<v8::Script> detailed_script(
16935 v8::Script::New(detailed_src, &detailed_origin)); 16877 v8::Script::New(detailed_src, &detailed_origin));
16936 v8::Handle<Value> detailed_result(detailed_script->Run()); 16878 v8::Handle<Value> detailed_result(detailed_script->Run());
16937 CHECK(!detailed_result.IsEmpty()); 16879 CHECK(!detailed_result.IsEmpty());
16938 CHECK(detailed_result->IsObject()); 16880 CHECK(detailed_result->IsObject());
16939 } 16881 }
16940 16882
16941 16883
16942 static void StackTraceForUncaughtExceptionListener( 16884 static void StackTraceForUncaughtExceptionListener(
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after
17671 17613
17672 // We don't have a consistent way to write 64-bit constants syntactically, so we 17614 // We don't have a consistent way to write 64-bit constants syntactically, so we
17673 // split them into two 32-bit constants and combine them programmatically. 17615 // split them into two 32-bit constants and combine them programmatically.
17674 static double DoubleFromBits(uint32_t high_bits, uint32_t low_bits) { 17616 static double DoubleFromBits(uint32_t high_bits, uint32_t low_bits) {
17675 return DoubleFromBits((static_cast<uint64_t>(high_bits) << 32) | low_bits); 17617 return DoubleFromBits((static_cast<uint64_t>(high_bits) << 32) | low_bits);
17676 } 17618 }
17677 17619
17678 17620
17679 THREADED_TEST(QuietSignalingNaNs) { 17621 THREADED_TEST(QuietSignalingNaNs) {
17680 LocalContext context; 17622 LocalContext context;
17681 v8::Isolate* isolate = context->GetIsolate(); 17623 v8::HandleScope scope(context->GetIsolate());
17682 v8::HandleScope scope(isolate);
17683 v8::TryCatch try_catch; 17624 v8::TryCatch try_catch;
17684 17625
17685 // Special double values. 17626 // Special double values.
17686 double snan = DoubleFromBits(0x7ff00000, 0x00000001); 17627 double snan = DoubleFromBits(0x7ff00000, 0x00000001);
17687 double qnan = DoubleFromBits(0x7ff80000, 0x00000000); 17628 double qnan = DoubleFromBits(0x7ff80000, 0x00000000);
17688 double infinity = DoubleFromBits(0x7ff00000, 0x00000000); 17629 double infinity = DoubleFromBits(0x7ff00000, 0x00000000);
17689 double max_normal = DoubleFromBits(0x7fefffff, 0xffffffffu); 17630 double max_normal = DoubleFromBits(0x7fefffff, 0xffffffffu);
17690 double min_normal = DoubleFromBits(0x00100000, 0x00000000); 17631 double min_normal = DoubleFromBits(0x00100000, 0x00000000);
17691 double max_denormal = DoubleFromBits(0x000fffff, 0xffffffffu); 17632 double max_denormal = DoubleFromBits(0x000fffff, 0xffffffffu);
17692 double min_denormal = DoubleFromBits(0x00000000, 0x00000001); 17633 double min_denormal = DoubleFromBits(0x00000000, 0x00000001);
(...skipping 23 matching lines...) Expand all
17716 -infinity, 17657 -infinity,
17717 -qnan, 17658 -qnan,
17718 -snan 17659 -snan
17719 }; 17660 };
17720 int num_test_values = 20; 17661 int num_test_values = 20;
17721 17662
17722 for (int i = 0; i < num_test_values; i++) { 17663 for (int i = 0; i < num_test_values; i++) {
17723 double test_value = test_values[i]; 17664 double test_value = test_values[i];
17724 17665
17725 // Check that Number::New preserves non-NaNs and quiets SNaNs. 17666 // Check that Number::New preserves non-NaNs and quiets SNaNs.
17726 v8::Handle<v8::Value> number = v8::Number::New(isolate, test_value); 17667 v8::Handle<v8::Value> number = v8::Number::New(test_value);
17727 double stored_number = number->NumberValue(); 17668 double stored_number = number->NumberValue();
17728 if (!std::isnan(test_value)) { 17669 if (!std::isnan(test_value)) {
17729 CHECK_EQ(test_value, stored_number); 17670 CHECK_EQ(test_value, stored_number);
17730 } else { 17671 } else {
17731 uint64_t stored_bits = DoubleToBits(stored_number); 17672 uint64_t stored_bits = DoubleToBits(stored_number);
17732 // Check if quiet nan (bits 51..62 all set). 17673 // Check if quiet nan (bits 51..62 all set).
17733 #if defined(V8_TARGET_ARCH_MIPS) && !defined(USE_SIMULATOR) 17674 #if defined(V8_TARGET_ARCH_MIPS) && !defined(USE_SIMULATOR)
17734 // Most significant fraction bit for quiet nan is set to 0 17675 // Most significant fraction bit for quiet nan is set to 0
17735 // on MIPS architecture. Allowed by IEEE-754. 17676 // on MIPS architecture. Allowed by IEEE-754.
17736 CHECK_EQ(0xffe, static_cast<int>((stored_bits >> 51) & 0xfff)); 17677 CHECK_EQ(0xffe, static_cast<int>((stored_bits >> 51) & 0xfff));
17737 #else 17678 #else
17738 CHECK_EQ(0xfff, static_cast<int>((stored_bits >> 51) & 0xfff)); 17679 CHECK_EQ(0xfff, static_cast<int>((stored_bits >> 51) & 0xfff));
17739 #endif 17680 #endif
17740 } 17681 }
17741 17682
17742 // Check that Date::New preserves non-NaNs in the date range and 17683 // Check that Date::New preserves non-NaNs in the date range and
17743 // quiets SNaNs. 17684 // quiets SNaNs.
17744 v8::Handle<v8::Value> date = 17685 v8::Handle<v8::Value> date =
17745 v8::Date::New(isolate, test_value); 17686 v8::Date::New(context->GetIsolate(), test_value);
17746 double expected_stored_date = DoubleToDateTime(test_value); 17687 double expected_stored_date = DoubleToDateTime(test_value);
17747 double stored_date = date->NumberValue(); 17688 double stored_date = date->NumberValue();
17748 if (!std::isnan(expected_stored_date)) { 17689 if (!std::isnan(expected_stored_date)) {
17749 CHECK_EQ(expected_stored_date, stored_date); 17690 CHECK_EQ(expected_stored_date, stored_date);
17750 } else { 17691 } else {
17751 uint64_t stored_bits = DoubleToBits(stored_date); 17692 uint64_t stored_bits = DoubleToBits(stored_date);
17752 // Check if quiet nan (bits 51..62 all set). 17693 // Check if quiet nan (bits 51..62 all set).
17753 #if defined(V8_TARGET_ARCH_MIPS) && !defined(USE_SIMULATOR) 17694 #if defined(V8_TARGET_ARCH_MIPS) && !defined(USE_SIMULATOR)
17754 // Most significant fraction bit for quiet nan is set to 0 17695 // Most significant fraction bit for quiet nan is set to 0
17755 // on MIPS architecture. Allowed by IEEE-754. 17696 // on MIPS architecture. Allowed by IEEE-754.
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
18007 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); 17948 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f")));
18008 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast( 17949 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast(
18009 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "g"))); 17950 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "g")));
18010 CHECK_EQ(0, f->GetScriptLineNumber()); 17951 CHECK_EQ(0, f->GetScriptLineNumber());
18011 CHECK_EQ(2, g->GetScriptLineNumber()); 17952 CHECK_EQ(2, g->GetScriptLineNumber());
18012 } 17953 }
18013 17954
18014 17955
18015 THREADED_TEST(ScriptColumnNumber) { 17956 THREADED_TEST(ScriptColumnNumber) {
18016 LocalContext env; 17957 LocalContext env;
18017 v8::Isolate* isolate = env->GetIsolate(); 17958 v8::HandleScope scope(env->GetIsolate());
18018 v8::HandleScope scope(isolate);
18019 v8::ScriptOrigin origin = 17959 v8::ScriptOrigin origin =
18020 v8::ScriptOrigin(v8::String::NewFromUtf8(isolate, "test"), 17960 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "test"),
18021 v8::Integer::New(isolate, 3), 17961 v8::Integer::New(3), v8::Integer::New(2));
18022 v8::Integer::New(isolate, 2));
18023 v8::Handle<v8::String> script = v8::String::NewFromUtf8( 17962 v8::Handle<v8::String> script = v8::String::NewFromUtf8(
18024 isolate, "function foo() {}\n\n function bar() {}"); 17963 env->GetIsolate(), "function foo() {}\n\n function bar() {}");
18025 v8::Script::Compile(script, &origin)->Run(); 17964 v8::Script::Compile(script, &origin)->Run();
18026 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( 17965 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast(
18027 env->Global()->Get(v8::String::NewFromUtf8(isolate, "foo"))); 17966 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo")));
18028 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast( 17967 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast(
18029 env->Global()->Get(v8::String::NewFromUtf8(isolate, "bar"))); 17968 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "bar")));
18030 CHECK_EQ(14, foo->GetScriptColumnNumber()); 17969 CHECK_EQ(14, foo->GetScriptColumnNumber());
18031 CHECK_EQ(17, bar->GetScriptColumnNumber()); 17970 CHECK_EQ(17, bar->GetScriptColumnNumber());
18032 } 17971 }
18033 17972
18034 17973
18035 THREADED_TEST(FunctionIsBuiltin) { 17974 THREADED_TEST(FunctionIsBuiltin) {
18036 LocalContext env; 17975 LocalContext env;
18037 v8::Isolate* isolate = env->GetIsolate(); 17976 v8::HandleScope scope(env->GetIsolate());
18038 v8::HandleScope scope(isolate);
18039 v8::Local<v8::Function> f; 17977 v8::Local<v8::Function> f;
18040 f = v8::Local<v8::Function>::Cast(CompileRun("Math.floor")); 17978 f = v8::Local<v8::Function>::Cast(CompileRun("Math.floor"));
18041 CHECK(f->IsBuiltin()); 17979 CHECK(f->IsBuiltin());
18042 f = v8::Local<v8::Function>::Cast(CompileRun("Object")); 17980 f = v8::Local<v8::Function>::Cast(CompileRun("Object"));
18043 CHECK(f->IsBuiltin()); 17981 CHECK(f->IsBuiltin());
18044 f = v8::Local<v8::Function>::Cast(CompileRun("Object.__defineSetter__")); 17982 f = v8::Local<v8::Function>::Cast(CompileRun("Object.__defineSetter__"));
18045 CHECK(f->IsBuiltin()); 17983 CHECK(f->IsBuiltin());
18046 f = v8::Local<v8::Function>::Cast(CompileRun("Array.prototype.toString")); 17984 f = v8::Local<v8::Function>::Cast(CompileRun("Array.prototype.toString"));
18047 CHECK(f->IsBuiltin()); 17985 CHECK(f->IsBuiltin());
18048 f = v8::Local<v8::Function>::Cast(CompileRun("function a() {}; a;")); 17986 f = v8::Local<v8::Function>::Cast(CompileRun("function a() {}; a;"));
18049 CHECK(!f->IsBuiltin()); 17987 CHECK(!f->IsBuiltin());
18050 } 17988 }
18051 17989
18052 17990
18053 THREADED_TEST(FunctionGetScriptId) { 17991 THREADED_TEST(FunctionGetScriptId) {
18054 LocalContext env; 17992 LocalContext env;
18055 v8::Isolate* isolate = env->GetIsolate(); 17993 v8::HandleScope scope(env->GetIsolate());
18056 v8::HandleScope scope(isolate);
18057 v8::ScriptOrigin origin = 17994 v8::ScriptOrigin origin =
18058 v8::ScriptOrigin(v8::String::NewFromUtf8(isolate, "test"), 17995 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "test"),
18059 v8::Integer::New(isolate, 3), 17996 v8::Integer::New(3), v8::Integer::New(2));
18060 v8::Integer::New(isolate, 2));
18061 v8::Handle<v8::String> scriptSource = v8::String::NewFromUtf8( 17997 v8::Handle<v8::String> scriptSource = v8::String::NewFromUtf8(
18062 isolate, "function foo() {}\n\n function bar() {}"); 17998 env->GetIsolate(), "function foo() {}\n\n function bar() {}");
18063 v8::Local<v8::Script> script(v8::Script::Compile(scriptSource, &origin)); 17999 v8::Local<v8::Script> script(v8::Script::Compile(scriptSource, &origin));
18064 script->Run(); 18000 script->Run();
18065 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( 18001 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast(
18066 env->Global()->Get(v8::String::NewFromUtf8(isolate, "foo"))); 18002 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo")));
18067 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast( 18003 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast(
18068 env->Global()->Get(v8::String::NewFromUtf8(isolate, "bar"))); 18004 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "bar")));
18069 CHECK_EQ(script->GetId(), foo->ScriptId()); 18005 CHECK_EQ(script->GetId(), foo->ScriptId());
18070 CHECK_EQ(script->GetId(), bar->ScriptId()); 18006 CHECK_EQ(script->GetId(), bar->ScriptId());
18071 } 18007 }
18072 18008
18073 18009
18074 THREADED_TEST(FunctionGetBoundFunction) { 18010 THREADED_TEST(FunctionGetBoundFunction) {
18075 LocalContext env; 18011 LocalContext env;
18076 v8::HandleScope scope(env->GetIsolate()); 18012 v8::HandleScope scope(env->GetIsolate());
18077 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::NewFromUtf8( 18013 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::NewFromUtf8(
18078 env->GetIsolate(), "test")); 18014 env->GetIsolate(), "test"));
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
18227 const char* source = "function C1() {" 18163 const char* source = "function C1() {"
18228 " this.x = 23;" 18164 " this.x = 23;"
18229 "};" 18165 "};"
18230 "C1.prototype = P;"; 18166 "C1.prototype = P;";
18231 18167
18232 LocalContext context; 18168 LocalContext context;
18233 v8::HandleScope scope(context->GetIsolate()); 18169 v8::HandleScope scope(context->GetIsolate());
18234 v8::Local<v8::Script> script; 18170 v8::Local<v8::Script> script;
18235 18171
18236 // Use a simple object as prototype. 18172 // Use a simple object as prototype.
18237 v8::Local<v8::Object> prototype = v8::Object::New(context->GetIsolate()); 18173 v8::Local<v8::Object> prototype = v8::Object::New();
18238 prototype->Set(v8_str("y"), v8_num(42)); 18174 prototype->Set(v8_str("y"), v8_num(42));
18239 context->Global()->Set(v8_str("P"), prototype); 18175 context->Global()->Set(v8_str("P"), prototype);
18240 18176
18241 // This compile will add the code to the compilation cache. 18177 // This compile will add the code to the compilation cache.
18242 CompileRun(source); 18178 CompileRun(source);
18243 18179
18244 script = v8::Script::Compile(v8_str("new C1();")); 18180 script = v8::Script::Compile(v8_str("new C1();"));
18245 // Allow enough iterations for the inobject slack tracking logic 18181 // Allow enough iterations for the inobject slack tracking logic
18246 // to finalize instance size and install the fast construct stub. 18182 // to finalize instance size and install the fast construct stub.
18247 for (int i = 0; i < 256; i++) { 18183 for (int i = 0; i < 256; i++) {
(...skipping 1043 matching lines...) Expand 10 before | Expand all | Expand 10 after
19291 19227
19292 int counter_; 19228 int counter_;
19293 v8::Persistent<v8::Object>* object_; 19229 v8::Persistent<v8::Object>* object_;
19294 }; 19230 };
19295 19231
19296 19232
19297 TEST(PersistentHandleVisitor) { 19233 TEST(PersistentHandleVisitor) {
19298 LocalContext context; 19234 LocalContext context;
19299 v8::Isolate* isolate = context->GetIsolate(); 19235 v8::Isolate* isolate = context->GetIsolate();
19300 v8::HandleScope scope(isolate); 19236 v8::HandleScope scope(isolate);
19301 v8::Persistent<v8::Object> object(isolate, v8::Object::New(isolate)); 19237 v8::Persistent<v8::Object> object(isolate, v8::Object::New());
19302 CHECK_EQ(0, object.WrapperClassId()); 19238 CHECK_EQ(0, object.WrapperClassId());
19303 object.SetWrapperClassId(42); 19239 object.SetWrapperClassId(42);
19304 CHECK_EQ(42, object.WrapperClassId()); 19240 CHECK_EQ(42, object.WrapperClassId());
19305 19241
19306 Visitor42 visitor(&object); 19242 Visitor42 visitor(&object);
19307 v8::V8::VisitHandlesWithClassIds(&visitor); 19243 v8::V8::VisitHandlesWithClassIds(&visitor);
19308 CHECK_EQ(1, visitor.counter_); 19244 CHECK_EQ(1, visitor.counter_);
19309 19245
19310 object.Reset(); 19246 object.Reset();
19311 } 19247 }
19312 19248
19313 19249
19314 TEST(WrapperClassId) { 19250 TEST(WrapperClassId) {
19315 LocalContext context; 19251 LocalContext context;
19316 v8::Isolate* isolate = context->GetIsolate(); 19252 v8::Isolate* isolate = context->GetIsolate();
19317 v8::HandleScope scope(isolate); 19253 v8::HandleScope scope(isolate);
19318 v8::Persistent<v8::Object> object(isolate, v8::Object::New(isolate)); 19254 v8::Persistent<v8::Object> object(isolate, v8::Object::New());
19319 CHECK_EQ(0, object.WrapperClassId()); 19255 CHECK_EQ(0, object.WrapperClassId());
19320 object.SetWrapperClassId(65535); 19256 object.SetWrapperClassId(65535);
19321 CHECK_EQ(65535, object.WrapperClassId()); 19257 CHECK_EQ(65535, object.WrapperClassId());
19322 object.Reset(); 19258 object.Reset();
19323 } 19259 }
19324 19260
19325 19261
19326 TEST(PersistentHandleInNewSpaceVisitor) { 19262 TEST(PersistentHandleInNewSpaceVisitor) {
19327 LocalContext context; 19263 LocalContext context;
19328 v8::Isolate* isolate = context->GetIsolate(); 19264 v8::Isolate* isolate = context->GetIsolate();
19329 v8::HandleScope scope(isolate); 19265 v8::HandleScope scope(isolate);
19330 v8::Persistent<v8::Object> object1(isolate, v8::Object::New(isolate)); 19266 v8::Persistent<v8::Object> object1(isolate, v8::Object::New());
19331 CHECK_EQ(0, object1.WrapperClassId()); 19267 CHECK_EQ(0, object1.WrapperClassId());
19332 object1.SetWrapperClassId(42); 19268 object1.SetWrapperClassId(42);
19333 CHECK_EQ(42, object1.WrapperClassId()); 19269 CHECK_EQ(42, object1.WrapperClassId());
19334 19270
19335 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 19271 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
19336 19272
19337 v8::Persistent<v8::Object> object2(isolate, v8::Object::New(isolate)); 19273 v8::Persistent<v8::Object> object2(isolate, v8::Object::New());
19338 CHECK_EQ(0, object2.WrapperClassId()); 19274 CHECK_EQ(0, object2.WrapperClassId());
19339 object2.SetWrapperClassId(42); 19275 object2.SetWrapperClassId(42);
19340 CHECK_EQ(42, object2.WrapperClassId()); 19276 CHECK_EQ(42, object2.WrapperClassId());
19341 19277
19342 Visitor42 visitor(&object2); 19278 Visitor42 visitor(&object2);
19343 v8::V8::VisitHandlesForPartialDependence(isolate, &visitor); 19279 v8::V8::VisitHandlesForPartialDependence(isolate, &visitor);
19344 CHECK_EQ(1, visitor.counter_); 19280 CHECK_EQ(1, visitor.counter_);
19345 19281
19346 object1.Reset(); 19282 object1.Reset();
19347 object2.Reset(); 19283 object2.Reset();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
19398 v8::RegExp::kMultiline)); 19334 v8::RegExp::kMultiline));
19399 CHECK(re->IsRegExp()); 19335 CHECK(re->IsRegExp());
19400 CHECK(re->GetSource()->Equals(v8_str("foobarbaz"))); 19336 CHECK(re->GetSource()->Equals(v8_str("foobarbaz")));
19401 CHECK_EQ(v8::RegExp::kIgnoreCase | v8::RegExp::kMultiline, 19337 CHECK_EQ(v8::RegExp::kIgnoreCase | v8::RegExp::kMultiline,
19402 static_cast<int>(re->GetFlags())); 19338 static_cast<int>(re->GetFlags()));
19403 19339
19404 context->Global()->Set(v8_str("re"), re); 19340 context->Global()->Set(v8_str("re"), re);
19405 ExpectTrue("re.test('FoobarbaZ')"); 19341 ExpectTrue("re.test('FoobarbaZ')");
19406 19342
19407 // RegExps are objects on which you can set properties. 19343 // RegExps are objects on which you can set properties.
19408 re->Set(v8_str("property"), v8::Integer::New(context->GetIsolate(), 32)); 19344 re->Set(v8_str("property"), v8::Integer::New(32));
19409 v8::Handle<v8::Value> value(CompileRun("re.property")); 19345 v8::Handle<v8::Value> value(CompileRun("re.property"));
19410 CHECK_EQ(32, value->Int32Value()); 19346 CHECK_EQ(32, value->Int32Value());
19411 19347
19412 v8::TryCatch try_catch; 19348 v8::TryCatch try_catch;
19413 re = v8::RegExp::New(v8_str("foo["), v8::RegExp::kNone); 19349 re = v8::RegExp::New(v8_str("foo["), v8::RegExp::kNone);
19414 CHECK(re.IsEmpty()); 19350 CHECK(re.IsEmpty());
19415 CHECK(try_catch.HasCaught()); 19351 CHECK(try_catch.HasCaught());
19416 context->Global()->Set(v8_str("ex"), try_catch.Exception()); 19352 context->Global()->Set(v8_str("ex"), try_catch.Exception());
19417 ExpectTrue("ex instanceof SyntaxError"); 19353 ExpectTrue("ex instanceof SyntaxError");
19418 } 19354 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
19477 " { configurable: true, enumerable: true, value: 3 });" 19413 " { configurable: true, enumerable: true, value: 3 });"
19478 "})").As<Function>(); 19414 "})").As<Function>();
19479 context->DetachGlobal(); 19415 context->DetachGlobal();
19480 define_property->Call(proxy, 0, NULL); 19416 define_property->Call(proxy, 0, NULL);
19481 } 19417 }
19482 19418
19483 19419
19484 static void InstallContextId(v8::Handle<Context> context, int id) { 19420 static void InstallContextId(v8::Handle<Context> context, int id) {
19485 Context::Scope scope(context); 19421 Context::Scope scope(context);
19486 CompileRun("Object.prototype").As<Object>()-> 19422 CompileRun("Object.prototype").As<Object>()->
19487 Set(v8_str("context_id"), v8::Integer::New(context->GetIsolate(), id)); 19423 Set(v8_str("context_id"), v8::Integer::New(id));
19488 } 19424 }
19489 19425
19490 19426
19491 static void CheckContextId(v8::Handle<Object> object, int expected) { 19427 static void CheckContextId(v8::Handle<Object> object, int expected) {
19492 CHECK_EQ(expected, object->Get(v8_str("context_id"))->Int32Value()); 19428 CHECK_EQ(expected, object->Get(v8_str("context_id"))->Int32Value());
19493 } 19429 }
19494 19430
19495 19431
19496 THREADED_TEST(CreationContext) { 19432 THREADED_TEST(CreationContext) {
19497 v8::Isolate* isolate = CcTest::isolate(); 19433 v8::Isolate* isolate = CcTest::isolate();
19498 HandleScope handle_scope(isolate); 19434 HandleScope handle_scope(isolate);
19499 Handle<Context> context1 = Context::New(isolate); 19435 Handle<Context> context1 = Context::New(isolate);
19500 InstallContextId(context1, 1); 19436 InstallContextId(context1, 1);
19501 Handle<Context> context2 = Context::New(isolate); 19437 Handle<Context> context2 = Context::New(isolate);
19502 InstallContextId(context2, 2); 19438 InstallContextId(context2, 2);
19503 Handle<Context> context3 = Context::New(isolate); 19439 Handle<Context> context3 = Context::New(isolate);
19504 InstallContextId(context3, 3); 19440 InstallContextId(context3, 3);
19505 19441
19506 Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(isolate); 19442 Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(isolate);
19507 19443
19508 Local<Object> object1; 19444 Local<Object> object1;
19509 Local<Function> func1; 19445 Local<Function> func1;
19510 { 19446 {
19511 Context::Scope scope(context1); 19447 Context::Scope scope(context1);
19512 object1 = Object::New(isolate); 19448 object1 = Object::New();
19513 func1 = tmpl->GetFunction(); 19449 func1 = tmpl->GetFunction();
19514 } 19450 }
19515 19451
19516 Local<Object> object2; 19452 Local<Object> object2;
19517 Local<Function> func2; 19453 Local<Function> func2;
19518 { 19454 {
19519 Context::Scope scope(context2); 19455 Context::Scope scope(context2);
19520 object2 = Object::New(isolate); 19456 object2 = Object::New();
19521 func2 = tmpl->GetFunction(); 19457 func2 = tmpl->GetFunction();
19522 } 19458 }
19523 19459
19524 Local<Object> instance1; 19460 Local<Object> instance1;
19525 Local<Object> instance2; 19461 Local<Object> instance2;
19526 19462
19527 { 19463 {
19528 Context::Scope scope(context3); 19464 Context::Scope scope(context3);
19529 instance1 = func1->NewInstance(); 19465 instance1 = func1->NewInstance();
19530 instance2 = func2->NewInstance(); 19466 instance2 = func2->NewInstance();
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
19921 protected_hidden_proto_template->InstanceTemplate()->SetAccessCheckCallbacks( 19857 protected_hidden_proto_template->InstanceTemplate()->SetAccessCheckCallbacks(
19922 BlockProtoNamedSecurityTestCallback, 19858 BlockProtoNamedSecurityTestCallback,
19923 IndexedSecurityTestCallback); 19859 IndexedSecurityTestCallback);
19924 protected_hidden_proto_template->SetHiddenPrototype(true); 19860 protected_hidden_proto_template->SetHiddenPrototype(true);
19925 19861
19926 // Context for "foreign" objects used in test. 19862 // Context for "foreign" objects used in test.
19927 Local<Context> context = v8::Context::New(isolate); 19863 Local<Context> context = v8::Context::New(isolate);
19928 context->Enter(); 19864 context->Enter();
19929 19865
19930 // Plain object, no security check. 19866 // Plain object, no security check.
19931 Local<Object> simple_object = Object::New(isolate); 19867 Local<Object> simple_object = Object::New();
19932 19868
19933 // Object with explicit security check. 19869 // Object with explicit security check.
19934 Local<Object> protected_object = 19870 Local<Object> protected_object =
19935 no_proto_template->NewInstance(); 19871 no_proto_template->NewInstance();
19936 19872
19937 // JSGlobalProxy object, always have security check. 19873 // JSGlobalProxy object, always have security check.
19938 Local<Object> proxy_object = 19874 Local<Object> proxy_object =
19939 context->Global(); 19875 context->Global();
19940 19876
19941 // Global object, the prototype of proxy_object. No security checks. 19877 // Global object, the prototype of proxy_object. No security checks.
19942 Local<Object> global_object = 19878 Local<Object> global_object =
19943 proxy_object->GetPrototype()->ToObject(); 19879 proxy_object->GetPrototype()->ToObject();
19944 19880
19945 // Hidden prototype without security check. 19881 // Hidden prototype without security check.
19946 Local<Object> hidden_prototype = 19882 Local<Object> hidden_prototype =
19947 hidden_proto_template->GetFunction()->NewInstance(); 19883 hidden_proto_template->GetFunction()->NewInstance();
19948 Local<Object> object_with_hidden = 19884 Local<Object> object_with_hidden =
19949 Object::New(isolate); 19885 Object::New();
19950 object_with_hidden->SetPrototype(hidden_prototype); 19886 object_with_hidden->SetPrototype(hidden_prototype);
19951 19887
19952 // Hidden prototype with security check on the hidden prototype. 19888 // Hidden prototype with security check on the hidden prototype.
19953 Local<Object> protected_hidden_prototype = 19889 Local<Object> protected_hidden_prototype =
19954 protected_hidden_proto_template->GetFunction()->NewInstance(); 19890 protected_hidden_proto_template->GetFunction()->NewInstance();
19955 Local<Object> object_with_protected_hidden = 19891 Local<Object> object_with_protected_hidden =
19956 Object::New(isolate); 19892 Object::New();
19957 object_with_protected_hidden->SetPrototype(protected_hidden_prototype); 19893 object_with_protected_hidden->SetPrototype(protected_hidden_prototype);
19958 19894
19959 context->Exit(); 19895 context->Exit();
19960 19896
19961 // Template for object for second context. Values to test are put on it as 19897 // Template for object for second context. Values to test are put on it as
19962 // properties. 19898 // properties.
19963 Local<ObjectTemplate> global_template = ObjectTemplate::New(); 19899 Local<ObjectTemplate> global_template = ObjectTemplate::New();
19964 global_template->Set(v8_str("simple"), simple_object); 19900 global_template->Set(v8_str("simple"), simple_object);
19965 global_template->Set(v8_str("protected"), protected_object); 19901 global_template->Set(v8_str("protected"), protected_object);
19966 global_template->Set(v8_str("global"), global_object); 19902 global_template->Set(v8_str("global"), global_object);
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
20355 isolate->Dispose(); 20291 isolate->Dispose();
20356 } 20292 }
20357 20293
20358 20294
20359 TEST(StringEmpty) { 20295 TEST(StringEmpty) {
20360 LocalContext context; 20296 LocalContext context;
20361 i::Factory* factory = CcTest::i_isolate()->factory(); 20297 i::Factory* factory = CcTest::i_isolate()->factory();
20362 v8::Isolate* isolate = CcTest::isolate(); 20298 v8::Isolate* isolate = CcTest::isolate();
20363 v8::HandleScope scope(isolate); 20299 v8::HandleScope scope(isolate);
20364 i::Handle<i::Object> empty_string = factory->empty_string(); 20300 i::Handle<i::Object> empty_string = factory->empty_string();
20301 CHECK(*v8::Utils::OpenHandle(*v8::String::Empty()) == *empty_string);
20365 CHECK(*v8::Utils::OpenHandle(*v8::String::Empty(isolate)) == *empty_string); 20302 CHECK(*v8::Utils::OpenHandle(*v8::String::Empty(isolate)) == *empty_string);
20366 } 20303 }
20367 20304
20368 20305
20369 static int instance_checked_getter_count = 0; 20306 static int instance_checked_getter_count = 0;
20370 static void InstanceCheckedGetter( 20307 static void InstanceCheckedGetter(
20371 Local<String> name, 20308 Local<String> name,
20372 const v8::PropertyCallbackInfo<v8::Value>& info) { 20309 const v8::PropertyCallbackInfo<v8::Value>& info) {
20373 CHECK_EQ(name, v8_str("foo")); 20310 CHECK_EQ(name, v8_str("foo"));
20374 instance_checked_getter_count++; 20311 instance_checked_getter_count++;
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
20768 Local<Value> map_value = CompileRun("new Map();"); 20705 Local<Value> map_value = CompileRun("new Map();");
20769 Local<Object> map_object(Local<Object>::Cast(map_value)); 20706 Local<Object> map_object(Local<Object>::Cast(map_value));
20770 CHECK_EQ(0, map_object->InternalFieldCount()); 20707 CHECK_EQ(0, map_object->InternalFieldCount());
20771 } 20708 }
20772 20709
20773 20710
20774 THREADED_TEST(Regress2746) { 20711 THREADED_TEST(Regress2746) {
20775 LocalContext context; 20712 LocalContext context;
20776 v8::Isolate* isolate = context->GetIsolate(); 20713 v8::Isolate* isolate = context->GetIsolate();
20777 v8::HandleScope scope(isolate); 20714 v8::HandleScope scope(isolate);
20778 Local<Object> obj = Object::New(isolate); 20715 Local<Object> obj = Object::New();
20779 Local<String> key = String::NewFromUtf8(context->GetIsolate(), "key"); 20716 Local<String> key = String::NewFromUtf8(context->GetIsolate(), "key");
20780 obj->SetHiddenValue(key, v8::Undefined(isolate)); 20717 obj->SetHiddenValue(key, v8::Undefined(isolate));
20781 Local<Value> value = obj->GetHiddenValue(key); 20718 Local<Value> value = obj->GetHiddenValue(key);
20782 CHECK(!value.IsEmpty()); 20719 CHECK(!value.IsEmpty());
20783 CHECK(value->IsUndefined()); 20720 CHECK(value->IsUndefined());
20784 } 20721 }
20785 20722
20786 20723
20787 THREADED_TEST(Regress260106) { 20724 THREADED_TEST(Regress260106) {
20788 LocalContext context; 20725 LocalContext context;
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
21426 static void FunctionNewCallback(const v8::FunctionCallbackInfo<Value>& info) { 21363 static void FunctionNewCallback(const v8::FunctionCallbackInfo<Value>& info) {
21427 CHECK_EQ(function_new_expected_env, info.Data()); 21364 CHECK_EQ(function_new_expected_env, info.Data());
21428 info.GetReturnValue().Set(17); 21365 info.GetReturnValue().Set(17);
21429 } 21366 }
21430 21367
21431 21368
21432 THREADED_TEST(FunctionNew) { 21369 THREADED_TEST(FunctionNew) {
21433 LocalContext env; 21370 LocalContext env;
21434 v8::Isolate* isolate = env->GetIsolate(); 21371 v8::Isolate* isolate = env->GetIsolate();
21435 v8::HandleScope scope(isolate); 21372 v8::HandleScope scope(isolate);
21436 Local<Object> data = v8::Object::New(isolate); 21373 Local<Object> data = v8::Object::New();
21437 function_new_expected_env = data; 21374 function_new_expected_env = data;
21438 Local<Function> func = Function::New(isolate, FunctionNewCallback, data); 21375 Local<Function> func = Function::New(isolate, FunctionNewCallback, data);
21439 env->Global()->Set(v8_str("func"), func); 21376 env->Global()->Set(v8_str("func"), func);
21440 Local<Value> result = CompileRun("func();"); 21377 Local<Value> result = CompileRun("func();");
21441 CHECK_EQ(v8::Integer::New(isolate, 17), result); 21378 CHECK_EQ(v8::Integer::New(17, isolate), result);
21442 // Verify function not cached 21379 // Verify function not cached
21443 int serial_number = 21380 int serial_number =
21444 i::Smi::cast(v8::Utils::OpenHandle(*func) 21381 i::Smi::cast(v8::Utils::OpenHandle(*func)
21445 ->shared()->get_api_func_data()->serial_number())->value(); 21382 ->shared()->get_api_func_data()->serial_number())->value();
21446 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 21383 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
21447 i::Object* elm = i_isolate->native_context()->function_cache() 21384 i::Object* elm = i_isolate->native_context()->function_cache()
21448 ->GetElementNoExceptionThrown(i_isolate, serial_number); 21385 ->GetElementNoExceptionThrown(i_isolate, serial_number);
21449 CHECK(elm->IsUndefined()); 21386 CHECK(elm->IsUndefined());
21450 // Verify that each Function::New creates a new function instance 21387 // Verify that each Function::New creates a new function instance
21451 Local<Object> data2 = v8::Object::New(isolate); 21388 Local<Object> data2 = v8::Object::New();
21452 function_new_expected_env = data2; 21389 function_new_expected_env = data2;
21453 Local<Function> func2 = Function::New(isolate, FunctionNewCallback, data2); 21390 Local<Function> func2 = Function::New(isolate, FunctionNewCallback, data2);
21454 CHECK(!func2->IsNull()); 21391 CHECK(!func2->IsNull());
21455 CHECK_NE(func, func2); 21392 CHECK_NE(func, func2);
21456 env->Global()->Set(v8_str("func2"), func2); 21393 env->Global()->Set(v8_str("func2"), func2);
21457 Local<Value> result2 = CompileRun("func2();"); 21394 Local<Value> result2 = CompileRun("func2();");
21458 CHECK_EQ(v8::Integer::New(isolate, 17), result2); 21395 CHECK_EQ(v8::Integer::New(17, isolate), result2);
21459 } 21396 }
21460 21397
21461 21398
21462 TEST(EscapeableHandleScope) { 21399 TEST(EscapeableHandleScope) {
21463 HandleScope outer_scope(CcTest::isolate()); 21400 HandleScope outer_scope(CcTest::isolate());
21464 LocalContext context; 21401 LocalContext context;
21465 const int runs = 10; 21402 const int runs = 10;
21466 Local<String> values[runs]; 21403 Local<String> values[runs];
21467 for (int i = 0; i < runs; i++) { 21404 for (int i = 0; i < runs; i++) {
21468 v8::EscapableHandleScope inner_scope(CcTest::isolate()); 21405 v8::EscapableHandleScope inner_scope(CcTest::isolate());
21469 Local<String> value; 21406 Local<String> value;
21470 if (i != 0) value = v8_str("escape value"); 21407 if (i != 0) value = v8_str("escape value");
21471 values[i] = inner_scope.Escape(value); 21408 values[i] = inner_scope.Escape(value);
21472 } 21409 }
21473 for (int i = 0; i < runs; i++) { 21410 for (int i = 0; i < runs; i++) {
21474 Local<String> expected; 21411 Local<String> expected;
21475 if (i != 0) { 21412 if (i != 0) {
21476 CHECK_EQ(v8_str("escape value"), values[i]); 21413 CHECK_EQ(v8_str("escape value"), values[i]);
21477 } else { 21414 } else {
21478 CHECK(values[i].IsEmpty()); 21415 CHECK(values[i].IsEmpty());
21479 } 21416 }
21480 } 21417 }
21481 } 21418 }
OLDNEW
« no previous file with comments | « test/cctest/test-accessors.cc ('k') | test/cctest/test-assembler-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698