OLD | NEW |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4470 "for (var i = 0; i < 22; i++) { str = str + str; }"); | 4457 "for (var i = 0; i < 22; i++) { str = str + str; }"); |
4471 | 4458 |
4472 // Check for out of memory state. | 4459 // Check for out of memory state. |
4473 CHECK(result.IsEmpty()); | 4460 CHECK(result.IsEmpty()); |
4474 CHECK(context->HasOutOfMemoryException()); | 4461 CHECK(context->HasOutOfMemoryException()); |
4475 } | 4462 } |
4476 | 4463 |
4477 | 4464 |
4478 THREADED_TEST(ConstructCall) { | 4465 THREADED_TEST(ConstructCall) { |
4479 LocalContext context; | 4466 LocalContext context; |
4480 v8::Isolate* isolate = context->GetIsolate(); | 4467 v8::HandleScope scope(context->GetIsolate()); |
4481 v8::HandleScope scope(isolate); | |
4482 CompileRun( | 4468 CompileRun( |
4483 "function Foo() {" | 4469 "function Foo() {" |
4484 " var result = [];" | 4470 " var result = [];" |
4485 " for (var i = 0; i < arguments.length; i++) {" | 4471 " for (var i = 0; i < arguments.length; i++) {" |
4486 " result.push(arguments[i]);" | 4472 " result.push(arguments[i]);" |
4487 " }" | 4473 " }" |
4488 " return result;" | 4474 " return result;" |
4489 "}"); | 4475 "}"); |
4490 Local<Function> Foo = | 4476 Local<Function> Foo = |
4491 Local<Function>::Cast(context->Global()->Get(v8_str("Foo"))); | 4477 Local<Function>::Cast(context->Global()->Get(v8_str("Foo"))); |
4492 | 4478 |
4493 v8::Handle<Value>* args0 = NULL; | 4479 v8::Handle<Value>* args0 = NULL; |
4494 Local<v8::Array> a0 = Local<v8::Array>::Cast(Foo->NewInstance(0, args0)); | 4480 Local<v8::Array> a0 = Local<v8::Array>::Cast(Foo->NewInstance(0, args0)); |
4495 CHECK_EQ(0, a0->Length()); | 4481 CHECK_EQ(0, a0->Length()); |
4496 | 4482 |
4497 v8::Handle<Value> args1[] = { v8_num(1.1) }; | 4483 v8::Handle<Value> args1[] = { v8_num(1.1) }; |
4498 Local<v8::Array> a1 = Local<v8::Array>::Cast(Foo->NewInstance(1, args1)); | 4484 Local<v8::Array> a1 = Local<v8::Array>::Cast(Foo->NewInstance(1, args1)); |
4499 CHECK_EQ(1, a1->Length()); | 4485 CHECK_EQ(1, a1->Length()); |
4500 CHECK_EQ(1.1, a1->Get(v8::Integer::New(isolate, 0))->NumberValue()); | 4486 CHECK_EQ(1.1, a1->Get(v8::Integer::New(0))->NumberValue()); |
4501 | 4487 |
4502 v8::Handle<Value> args2[] = { v8_num(2.2), | 4488 v8::Handle<Value> args2[] = { v8_num(2.2), |
4503 v8_num(3.3) }; | 4489 v8_num(3.3) }; |
4504 Local<v8::Array> a2 = Local<v8::Array>::Cast(Foo->NewInstance(2, args2)); | 4490 Local<v8::Array> a2 = Local<v8::Array>::Cast(Foo->NewInstance(2, args2)); |
4505 CHECK_EQ(2, a2->Length()); | 4491 CHECK_EQ(2, a2->Length()); |
4506 CHECK_EQ(2.2, a2->Get(v8::Integer::New(isolate, 0))->NumberValue()); | 4492 CHECK_EQ(2.2, a2->Get(v8::Integer::New(0))->NumberValue()); |
4507 CHECK_EQ(3.3, a2->Get(v8::Integer::New(isolate, 1))->NumberValue()); | 4493 CHECK_EQ(3.3, a2->Get(v8::Integer::New(1))->NumberValue()); |
4508 | 4494 |
4509 v8::Handle<Value> args3[] = { v8_num(4.4), | 4495 v8::Handle<Value> args3[] = { v8_num(4.4), |
4510 v8_num(5.5), | 4496 v8_num(5.5), |
4511 v8_num(6.6) }; | 4497 v8_num(6.6) }; |
4512 Local<v8::Array> a3 = Local<v8::Array>::Cast(Foo->NewInstance(3, args3)); | 4498 Local<v8::Array> a3 = Local<v8::Array>::Cast(Foo->NewInstance(3, args3)); |
4513 CHECK_EQ(3, a3->Length()); | 4499 CHECK_EQ(3, a3->Length()); |
4514 CHECK_EQ(4.4, a3->Get(v8::Integer::New(isolate, 0))->NumberValue()); | 4500 CHECK_EQ(4.4, a3->Get(v8::Integer::New(0))->NumberValue()); |
4515 CHECK_EQ(5.5, a3->Get(v8::Integer::New(isolate, 1))->NumberValue()); | 4501 CHECK_EQ(5.5, a3->Get(v8::Integer::New(1))->NumberValue()); |
4516 CHECK_EQ(6.6, a3->Get(v8::Integer::New(isolate, 2))->NumberValue()); | 4502 CHECK_EQ(6.6, a3->Get(v8::Integer::New(2))->NumberValue()); |
4517 | 4503 |
4518 v8::Handle<Value> args4[] = { v8_num(7.7), | 4504 v8::Handle<Value> args4[] = { v8_num(7.7), |
4519 v8_num(8.8), | 4505 v8_num(8.8), |
4520 v8_num(9.9), | 4506 v8_num(9.9), |
4521 v8_num(10.11) }; | 4507 v8_num(10.11) }; |
4522 Local<v8::Array> a4 = Local<v8::Array>::Cast(Foo->NewInstance(4, args4)); | 4508 Local<v8::Array> a4 = Local<v8::Array>::Cast(Foo->NewInstance(4, args4)); |
4523 CHECK_EQ(4, a4->Length()); | 4509 CHECK_EQ(4, a4->Length()); |
4524 CHECK_EQ(7.7, a4->Get(v8::Integer::New(isolate, 0))->NumberValue()); | 4510 CHECK_EQ(7.7, a4->Get(v8::Integer::New(0))->NumberValue()); |
4525 CHECK_EQ(8.8, a4->Get(v8::Integer::New(isolate, 1))->NumberValue()); | 4511 CHECK_EQ(8.8, a4->Get(v8::Integer::New(1))->NumberValue()); |
4526 CHECK_EQ(9.9, a4->Get(v8::Integer::New(isolate, 2))->NumberValue()); | 4512 CHECK_EQ(9.9, a4->Get(v8::Integer::New(2))->NumberValue()); |
4527 CHECK_EQ(10.11, a4->Get(v8::Integer::New(isolate, 3))->NumberValue()); | 4513 CHECK_EQ(10.11, a4->Get(v8::Integer::New(3))->NumberValue()); |
4528 } | 4514 } |
4529 | 4515 |
4530 | 4516 |
4531 static void CheckUncle(v8::TryCatch* try_catch) { | 4517 static void CheckUncle(v8::TryCatch* try_catch) { |
4532 CHECK(try_catch->HasCaught()); | 4518 CHECK(try_catch->HasCaught()); |
4533 String::Utf8Value str_value(try_catch->Exception()); | 4519 String::Utf8Value str_value(try_catch->Exception()); |
4534 CHECK_EQ(*str_value, "uncle?"); | 4520 CHECK_EQ(*str_value, "uncle?"); |
4535 try_catch->Reset(); | 4521 try_catch->Reset(); |
4536 } | 4522 } |
4537 | 4523 |
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5131 "function Run(obj) {" | 5117 "function Run(obj) {" |
5132 " try {" | 5118 " try {" |
5133 " Throw(obj);" | 5119 " Throw(obj);" |
5134 " } catch (e) {" | 5120 " } catch (e) {" |
5135 " return e;" | 5121 " return e;" |
5136 " }" | 5122 " }" |
5137 " return 'no exception';" | 5123 " return 'no exception';" |
5138 "}" | 5124 "}" |
5139 "[Run('str'), Run(1), Run(0), Run(null), Run(void 0)];")); | 5125 "[Run('str'), Run(1), Run(0), Run(null), Run(void 0)];")); |
5140 CHECK_EQ(5, result->Length()); | 5126 CHECK_EQ(5, result->Length()); |
5141 CHECK(result->Get(v8::Integer::New(isolate, 0))->IsString()); | 5127 CHECK(result->Get(v8::Integer::New(0))->IsString()); |
5142 CHECK(result->Get(v8::Integer::New(isolate, 1))->IsNumber()); | 5128 CHECK(result->Get(v8::Integer::New(1))->IsNumber()); |
5143 CHECK_EQ(1, result->Get(v8::Integer::New(isolate, 1))->Int32Value()); | 5129 CHECK_EQ(1, result->Get(v8::Integer::New(1))->Int32Value()); |
5144 CHECK(result->Get(v8::Integer::New(isolate, 2))->IsNumber()); | 5130 CHECK(result->Get(v8::Integer::New(2))->IsNumber()); |
5145 CHECK_EQ(0, result->Get(v8::Integer::New(isolate, 2))->Int32Value()); | 5131 CHECK_EQ(0, result->Get(v8::Integer::New(2))->Int32Value()); |
5146 CHECK(result->Get(v8::Integer::New(isolate, 3))->IsNull()); | 5132 CHECK(result->Get(v8::Integer::New(3))->IsNull()); |
5147 CHECK(result->Get(v8::Integer::New(isolate, 4))->IsUndefined()); | 5133 CHECK(result->Get(v8::Integer::New(4))->IsUndefined()); |
5148 } | 5134 } |
5149 | 5135 |
5150 | 5136 |
5151 THREADED_TEST(CatchZero) { | 5137 THREADED_TEST(CatchZero) { |
5152 LocalContext context; | 5138 LocalContext context; |
5153 v8::HandleScope scope(context->GetIsolate()); | 5139 v8::HandleScope scope(context->GetIsolate()); |
5154 v8::TryCatch try_catch; | 5140 v8::TryCatch try_catch; |
5155 CHECK(!try_catch.HasCaught()); | 5141 CHECK(!try_catch.HasCaught()); |
5156 Script::Compile(v8_str("throw 10"))->Run(); | 5142 Script::Compile(v8_str("throw 10"))->Run(); |
5157 CHECK(try_catch.HasCaught()); | 5143 CHECK(try_catch.HasCaught()); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5294 CHECK(!v8_str("a")->StrictEquals(v8_str("b"))); | 5280 CHECK(!v8_str("a")->StrictEquals(v8_str("b"))); |
5295 CHECK(!v8_str("5")->StrictEquals(v8_num(5))); | 5281 CHECK(!v8_str("5")->StrictEquals(v8_num(5))); |
5296 CHECK(v8_num(1)->StrictEquals(v8_num(1))); | 5282 CHECK(v8_num(1)->StrictEquals(v8_num(1))); |
5297 CHECK(!v8_num(1)->StrictEquals(v8_num(2))); | 5283 CHECK(!v8_num(1)->StrictEquals(v8_num(2))); |
5298 CHECK(v8_num(0.0)->StrictEquals(v8_num(-0.0))); | 5284 CHECK(v8_num(0.0)->StrictEquals(v8_num(-0.0))); |
5299 Local<Value> not_a_number = v8_num(i::OS::nan_value()); | 5285 Local<Value> not_a_number = v8_num(i::OS::nan_value()); |
5300 CHECK(!not_a_number->StrictEquals(not_a_number)); | 5286 CHECK(!not_a_number->StrictEquals(not_a_number)); |
5301 CHECK(v8::False(isolate)->StrictEquals(v8::False(isolate))); | 5287 CHECK(v8::False(isolate)->StrictEquals(v8::False(isolate))); |
5302 CHECK(!v8::False(isolate)->StrictEquals(v8::Undefined(isolate))); | 5288 CHECK(!v8::False(isolate)->StrictEquals(v8::Undefined(isolate))); |
5303 | 5289 |
5304 v8::Handle<v8::Object> obj = v8::Object::New(isolate); | 5290 v8::Handle<v8::Object> obj = v8::Object::New(); |
5305 v8::Persistent<v8::Object> alias(isolate, obj); | 5291 v8::Persistent<v8::Object> alias(isolate, obj); |
5306 CHECK(v8::Local<v8::Object>::New(isolate, alias)->StrictEquals(obj)); | 5292 CHECK(v8::Local<v8::Object>::New(isolate, alias)->StrictEquals(obj)); |
5307 alias.Reset(); | 5293 alias.Reset(); |
5308 | 5294 |
5309 CHECK(v8_str("a")->SameValue(v8_str("a"))); | 5295 CHECK(v8_str("a")->SameValue(v8_str("a"))); |
5310 CHECK(!v8_str("a")->SameValue(v8_str("b"))); | 5296 CHECK(!v8_str("a")->SameValue(v8_str("b"))); |
5311 CHECK(!v8_str("5")->SameValue(v8_num(5))); | 5297 CHECK(!v8_str("5")->SameValue(v8_num(5))); |
5312 CHECK(v8_num(1)->SameValue(v8_num(1))); | 5298 CHECK(v8_num(1)->SameValue(v8_num(1))); |
5313 CHECK(!v8_num(1)->SameValue(v8_num(2))); | 5299 CHECK(!v8_num(1)->SameValue(v8_num(2))); |
5314 CHECK(!v8_num(0.0)->SameValue(v8_num(-0.0))); | 5300 CHECK(!v8_num(0.0)->SameValue(v8_num(-0.0))); |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5757 CompileRun("var obj = { x : 0 }; delete obj.x;"); | 5743 CompileRun("var obj = { x : 0 }; delete obj.x;"); |
5758 context1->Exit(); | 5744 context1->Exit(); |
5759 } | 5745 } |
5760 | 5746 |
5761 | 5747 |
5762 static void SetXOnPrototypeGetter( | 5748 static void SetXOnPrototypeGetter( |
5763 Local<String> property, | 5749 Local<String> property, |
5764 const v8::PropertyCallbackInfo<v8::Value>& info) { | 5750 const v8::PropertyCallbackInfo<v8::Value>& info) { |
5765 // Set x on the prototype object and do not handle the get request. | 5751 // Set x on the prototype object and do not handle the get request. |
5766 v8::Handle<v8::Value> proto = info.Holder()->GetPrototype(); | 5752 v8::Handle<v8::Value> proto = info.Holder()->GetPrototype(); |
5767 proto.As<v8::Object>()->Set(v8_str("x"), | 5753 proto.As<v8::Object>()->Set(v8_str("x"), v8::Integer::New(23)); |
5768 v8::Integer::New(info.GetIsolate(), 23)); | |
5769 } | 5754 } |
5770 | 5755 |
5771 | 5756 |
5772 // This is a regression test for http://crbug.com/20104. Map | 5757 // This is a regression test for http://crbug.com/20104. Map |
5773 // transitions should not interfere with post interceptor lookup. | 5758 // transitions should not interfere with post interceptor lookup. |
5774 THREADED_TEST(NamedInterceptorMapTransitionRead) { | 5759 THREADED_TEST(NamedInterceptorMapTransitionRead) { |
5775 v8::Isolate* isolate = CcTest::isolate(); | 5760 v8::Isolate* isolate = CcTest::isolate(); |
5776 v8::HandleScope scope(isolate); | 5761 v8::HandleScope scope(isolate); |
5777 Local<v8::FunctionTemplate> function_template = | 5762 Local<v8::FunctionTemplate> function_template = |
5778 v8::FunctionTemplate::New(isolate); | 5763 v8::FunctionTemplate::New(isolate); |
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6415 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable | 6400 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable |
6416 | 6401 |
6417 Local<v8::Object> obj = desc->GetFunction()->NewInstance(); | 6402 Local<v8::Object> obj = desc->GetFunction()->NewInstance(); |
6418 env->Global()->Set(v8_str("undetectable"), obj); | 6403 env->Global()->Set(v8_str("undetectable"), obj); |
6419 | 6404 |
6420 Local<String> source = v8_str("undetectable.x = 42;" | 6405 Local<String> source = v8_str("undetectable.x = 42;" |
6421 "undetectable.x"); | 6406 "undetectable.x"); |
6422 | 6407 |
6423 Local<Script> script = Script::Compile(source); | 6408 Local<Script> script = Script::Compile(source); |
6424 | 6409 |
6425 CHECK_EQ(v8::Integer::New(isolate, 42), script->Run()); | 6410 CHECK_EQ(v8::Integer::New(42), script->Run()); |
6426 | 6411 |
6427 ExpectBoolean("Object.isExtensible(undetectable)", true); | 6412 ExpectBoolean("Object.isExtensible(undetectable)", true); |
6428 | 6413 |
6429 source = v8_str("Object.preventExtensions(undetectable);"); | 6414 source = v8_str("Object.preventExtensions(undetectable);"); |
6430 script = Script::Compile(source); | 6415 script = Script::Compile(source); |
6431 script->Run(); | 6416 script->Run(); |
6432 ExpectBoolean("Object.isExtensible(undetectable)", false); | 6417 ExpectBoolean("Object.isExtensible(undetectable)", false); |
6433 | 6418 |
6434 source = v8_str("undetectable.y = 2000;"); | 6419 source = v8_str("undetectable.y = 2000;"); |
6435 script = Script::Compile(source); | 6420 script = Script::Compile(source); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6560 | 6545 |
6561 THREADED_TEST(SimpleExtensions) { | 6546 THREADED_TEST(SimpleExtensions) { |
6562 v8::HandleScope handle_scope(CcTest::isolate()); | 6547 v8::HandleScope handle_scope(CcTest::isolate()); |
6563 v8::RegisterExtension(new Extension("simpletest", kSimpleExtensionSource)); | 6548 v8::RegisterExtension(new Extension("simpletest", kSimpleExtensionSource)); |
6564 const char* extension_names[] = { "simpletest" }; | 6549 const char* extension_names[] = { "simpletest" }; |
6565 v8::ExtensionConfiguration extensions(1, extension_names); | 6550 v8::ExtensionConfiguration extensions(1, extension_names); |
6566 v8::Handle<Context> context = | 6551 v8::Handle<Context> context = |
6567 Context::New(CcTest::isolate(), &extensions); | 6552 Context::New(CcTest::isolate(), &extensions); |
6568 Context::Scope lock(context); | 6553 Context::Scope lock(context); |
6569 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run(); | 6554 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run(); |
6570 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 4)); | 6555 CHECK_EQ(result, v8::Integer::New(4)); |
6571 } | 6556 } |
6572 | 6557 |
6573 | 6558 |
6574 THREADED_TEST(NullExtensions) { | 6559 THREADED_TEST(NullExtensions) { |
6575 v8::HandleScope handle_scope(CcTest::isolate()); | 6560 v8::HandleScope handle_scope(CcTest::isolate()); |
6576 v8::RegisterExtension(new Extension("nulltest", NULL)); | 6561 v8::RegisterExtension(new Extension("nulltest", NULL)); |
6577 const char* extension_names[] = { "nulltest" }; | 6562 const char* extension_names[] = { "nulltest" }; |
6578 v8::ExtensionConfiguration extensions(1, extension_names); | 6563 v8::ExtensionConfiguration extensions(1, extension_names); |
6579 v8::Handle<Context> context = | 6564 v8::Handle<Context> context = |
6580 Context::New(CcTest::isolate(), &extensions); | 6565 Context::New(CcTest::isolate(), &extensions); |
6581 Context::Scope lock(context); | 6566 Context::Scope lock(context); |
6582 v8::Handle<Value> result = Script::Compile(v8_str("1+3"))->Run(); | 6567 v8::Handle<Value> result = Script::Compile(v8_str("1+3"))->Run(); |
6583 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 4)); | 6568 CHECK_EQ(result, v8::Integer::New(4)); |
6584 } | 6569 } |
6585 | 6570 |
6586 | 6571 |
6587 static const char* kEmbeddedExtensionSource = | 6572 static const char* kEmbeddedExtensionSource = |
6588 "function Ret54321(){return 54321;}~~@@$" | 6573 "function Ret54321(){return 54321;}~~@@$" |
6589 "$%% THIS IS A SERIES OF NON-NULL-TERMINATED STRINGS."; | 6574 "$%% THIS IS A SERIES OF NON-NULL-TERMINATED STRINGS."; |
6590 static const int kEmbeddedExtensionSourceValidLen = 34; | 6575 static const int kEmbeddedExtensionSourceValidLen = 34; |
6591 | 6576 |
6592 | 6577 |
6593 THREADED_TEST(ExtensionMissingSourceLength) { | 6578 THREADED_TEST(ExtensionMissingSourceLength) { |
(...skipping 17 matching lines...) Expand all Loading... |
6611 v8::RegisterExtension(new Extension(extension_name.start(), | 6596 v8::RegisterExtension(new Extension(extension_name.start(), |
6612 kEmbeddedExtensionSource, 0, 0, | 6597 kEmbeddedExtensionSource, 0, 0, |
6613 source_len)); | 6598 source_len)); |
6614 const char* extension_names[1] = { extension_name.start() }; | 6599 const char* extension_names[1] = { extension_name.start() }; |
6615 v8::ExtensionConfiguration extensions(1, extension_names); | 6600 v8::ExtensionConfiguration extensions(1, extension_names); |
6616 v8::Handle<Context> context = | 6601 v8::Handle<Context> context = |
6617 Context::New(CcTest::isolate(), &extensions); | 6602 Context::New(CcTest::isolate(), &extensions); |
6618 if (source_len == kEmbeddedExtensionSourceValidLen) { | 6603 if (source_len == kEmbeddedExtensionSourceValidLen) { |
6619 Context::Scope lock(context); | 6604 Context::Scope lock(context); |
6620 v8::Handle<Value> result = Script::Compile(v8_str("Ret54321()"))->Run(); | 6605 v8::Handle<Value> result = Script::Compile(v8_str("Ret54321()"))->Run(); |
6621 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 54321), result); | 6606 CHECK_EQ(v8::Integer::New(54321), result); |
6622 } else { | 6607 } else { |
6623 // Anything but exactly the right length should fail to compile. | 6608 // Anything but exactly the right length should fail to compile. |
6624 CHECK_EQ(0, *context); | 6609 CHECK_EQ(0, *context); |
6625 } | 6610 } |
6626 } | 6611 } |
6627 } | 6612 } |
6628 | 6613 |
6629 | 6614 |
6630 static const char* kEvalExtensionSource1 = | 6615 static const char* kEvalExtensionSource1 = |
6631 "function UseEval1() {" | 6616 "function UseEval1() {" |
(...skipping 15 matching lines...) Expand all Loading... |
6647 THREADED_TEST(UseEvalFromExtension) { | 6632 THREADED_TEST(UseEvalFromExtension) { |
6648 v8::HandleScope handle_scope(CcTest::isolate()); | 6633 v8::HandleScope handle_scope(CcTest::isolate()); |
6649 v8::RegisterExtension(new Extension("evaltest1", kEvalExtensionSource1)); | 6634 v8::RegisterExtension(new Extension("evaltest1", kEvalExtensionSource1)); |
6650 v8::RegisterExtension(new Extension("evaltest2", kEvalExtensionSource2)); | 6635 v8::RegisterExtension(new Extension("evaltest2", kEvalExtensionSource2)); |
6651 const char* extension_names[] = { "evaltest1", "evaltest2" }; | 6636 const char* extension_names[] = { "evaltest1", "evaltest2" }; |
6652 v8::ExtensionConfiguration extensions(2, extension_names); | 6637 v8::ExtensionConfiguration extensions(2, extension_names); |
6653 v8::Handle<Context> context = | 6638 v8::Handle<Context> context = |
6654 Context::New(CcTest::isolate(), &extensions); | 6639 Context::New(CcTest::isolate(), &extensions); |
6655 Context::Scope lock(context); | 6640 Context::Scope lock(context); |
6656 v8::Handle<Value> result = Script::Compile(v8_str("UseEval1()"))->Run(); | 6641 v8::Handle<Value> result = Script::Compile(v8_str("UseEval1()"))->Run(); |
6657 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 42)); | 6642 CHECK_EQ(result, v8::Integer::New(42)); |
6658 result = Script::Compile(v8_str("UseEval2()"))->Run(); | 6643 result = Script::Compile(v8_str("UseEval2()"))->Run(); |
6659 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 42)); | 6644 CHECK_EQ(result, v8::Integer::New(42)); |
6660 } | 6645 } |
6661 | 6646 |
6662 | 6647 |
6663 static const char* kWithExtensionSource1 = | 6648 static const char* kWithExtensionSource1 = |
6664 "function UseWith1() {" | 6649 "function UseWith1() {" |
6665 " var x = 42;" | 6650 " var x = 42;" |
6666 " with({x:87}) { return x; }" | 6651 " with({x:87}) { return x; }" |
6667 "}"; | 6652 "}"; |
6668 | 6653 |
6669 | 6654 |
(...skipping 11 matching lines...) Expand all Loading... |
6681 THREADED_TEST(UseWithFromExtension) { | 6666 THREADED_TEST(UseWithFromExtension) { |
6682 v8::HandleScope handle_scope(CcTest::isolate()); | 6667 v8::HandleScope handle_scope(CcTest::isolate()); |
6683 v8::RegisterExtension(new Extension("withtest1", kWithExtensionSource1)); | 6668 v8::RegisterExtension(new Extension("withtest1", kWithExtensionSource1)); |
6684 v8::RegisterExtension(new Extension("withtest2", kWithExtensionSource2)); | 6669 v8::RegisterExtension(new Extension("withtest2", kWithExtensionSource2)); |
6685 const char* extension_names[] = { "withtest1", "withtest2" }; | 6670 const char* extension_names[] = { "withtest1", "withtest2" }; |
6686 v8::ExtensionConfiguration extensions(2, extension_names); | 6671 v8::ExtensionConfiguration extensions(2, extension_names); |
6687 v8::Handle<Context> context = | 6672 v8::Handle<Context> context = |
6688 Context::New(CcTest::isolate(), &extensions); | 6673 Context::New(CcTest::isolate(), &extensions); |
6689 Context::Scope lock(context); | 6674 Context::Scope lock(context); |
6690 v8::Handle<Value> result = Script::Compile(v8_str("UseWith1()"))->Run(); | 6675 v8::Handle<Value> result = Script::Compile(v8_str("UseWith1()"))->Run(); |
6691 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 87)); | 6676 CHECK_EQ(result, v8::Integer::New(87)); |
6692 result = Script::Compile(v8_str("UseWith2()"))->Run(); | 6677 result = Script::Compile(v8_str("UseWith2()"))->Run(); |
6693 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 87)); | 6678 CHECK_EQ(result, v8::Integer::New(87)); |
6694 } | 6679 } |
6695 | 6680 |
6696 | 6681 |
6697 THREADED_TEST(AutoExtensions) { | 6682 THREADED_TEST(AutoExtensions) { |
6698 v8::HandleScope handle_scope(CcTest::isolate()); | 6683 v8::HandleScope handle_scope(CcTest::isolate()); |
6699 Extension* extension = new Extension("autotest", kSimpleExtensionSource); | 6684 Extension* extension = new Extension("autotest", kSimpleExtensionSource); |
6700 extension->set_auto_enable(true); | 6685 extension->set_auto_enable(true); |
6701 v8::RegisterExtension(extension); | 6686 v8::RegisterExtension(extension); |
6702 v8::Handle<Context> context = | 6687 v8::Handle<Context> context = |
6703 Context::New(CcTest::isolate()); | 6688 Context::New(CcTest::isolate()); |
6704 Context::Scope lock(context); | 6689 Context::Scope lock(context); |
6705 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run(); | 6690 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run(); |
6706 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 4)); | 6691 CHECK_EQ(result, v8::Integer::New(4)); |
6707 } | 6692 } |
6708 | 6693 |
6709 | 6694 |
6710 static const char* kSyntaxErrorInExtensionSource = | 6695 static const char* kSyntaxErrorInExtensionSource = |
6711 "["; | 6696 "["; |
6712 | 6697 |
6713 | 6698 |
6714 // Test that a syntax error in an extension does not cause a fatal | 6699 // Test that a syntax error in an extension does not cause a fatal |
6715 // error but results in an empty context. | 6700 // error but results in an empty context. |
6716 THREADED_TEST(SyntaxErrorExtensions) { | 6701 THREADED_TEST(SyntaxErrorExtensions) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6756 THREADED_TEST(NativeCallInExtensions) { | 6741 THREADED_TEST(NativeCallInExtensions) { |
6757 v8::HandleScope handle_scope(CcTest::isolate()); | 6742 v8::HandleScope handle_scope(CcTest::isolate()); |
6758 v8::RegisterExtension(new Extension("nativecall", | 6743 v8::RegisterExtension(new Extension("nativecall", |
6759 kNativeCallInExtensionSource)); | 6744 kNativeCallInExtensionSource)); |
6760 const char* extension_names[] = { "nativecall" }; | 6745 const char* extension_names[] = { "nativecall" }; |
6761 v8::ExtensionConfiguration extensions(1, extension_names); | 6746 v8::ExtensionConfiguration extensions(1, extension_names); |
6762 v8::Handle<Context> context = | 6747 v8::Handle<Context> context = |
6763 Context::New(CcTest::isolate(), &extensions); | 6748 Context::New(CcTest::isolate(), &extensions); |
6764 Context::Scope lock(context); | 6749 Context::Scope lock(context); |
6765 v8::Handle<Value> result = Script::Compile(v8_str(kNativeCallTest))->Run(); | 6750 v8::Handle<Value> result = Script::Compile(v8_str(kNativeCallTest))->Run(); |
6766 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 3)); | 6751 CHECK_EQ(result, v8::Integer::New(3)); |
6767 } | 6752 } |
6768 | 6753 |
6769 | 6754 |
6770 class NativeFunctionExtension : public Extension { | 6755 class NativeFunctionExtension : public Extension { |
6771 public: | 6756 public: |
6772 NativeFunctionExtension(const char* name, | 6757 NativeFunctionExtension(const char* name, |
6773 const char* source, | 6758 const char* source, |
6774 v8::FunctionCallback fun = &Echo) | 6759 v8::FunctionCallback fun = &Echo) |
6775 : Extension(name, source), | 6760 : Extension(name, source), |
6776 function_(fun) { } | 6761 function_(fun) { } |
(...skipping 16 matching lines...) Expand all Loading... |
6793 v8::HandleScope handle_scope(CcTest::isolate()); | 6778 v8::HandleScope handle_scope(CcTest::isolate()); |
6794 const char* name = "nativedecl"; | 6779 const char* name = "nativedecl"; |
6795 v8::RegisterExtension(new NativeFunctionExtension(name, | 6780 v8::RegisterExtension(new NativeFunctionExtension(name, |
6796 "native function foo();")); | 6781 "native function foo();")); |
6797 const char* extension_names[] = { name }; | 6782 const char* extension_names[] = { name }; |
6798 v8::ExtensionConfiguration extensions(1, extension_names); | 6783 v8::ExtensionConfiguration extensions(1, extension_names); |
6799 v8::Handle<Context> context = | 6784 v8::Handle<Context> context = |
6800 Context::New(CcTest::isolate(), &extensions); | 6785 Context::New(CcTest::isolate(), &extensions); |
6801 Context::Scope lock(context); | 6786 Context::Scope lock(context); |
6802 v8::Handle<Value> result = Script::Compile(v8_str("foo(42);"))->Run(); | 6787 v8::Handle<Value> result = Script::Compile(v8_str("foo(42);"))->Run(); |
6803 CHECK_EQ(result, v8::Integer::New(CcTest::isolate(), 42)); | 6788 CHECK_EQ(result, v8::Integer::New(42)); |
6804 } | 6789 } |
6805 | 6790 |
6806 | 6791 |
6807 THREADED_TEST(NativeFunctionDeclarationError) { | 6792 THREADED_TEST(NativeFunctionDeclarationError) { |
6808 v8::HandleScope handle_scope(CcTest::isolate()); | 6793 v8::HandleScope handle_scope(CcTest::isolate()); |
6809 const char* name = "nativedeclerr"; | 6794 const char* name = "nativedeclerr"; |
6810 // Syntax error in extension code. | 6795 // Syntax error in extension code. |
6811 v8::RegisterExtension(new NativeFunctionExtension(name, | 6796 v8::RegisterExtension(new NativeFunctionExtension(name, |
6812 "native\nfunction foo();")); | 6797 "native\nfunction foo();")); |
6813 const char* extension_names[] = { name }; | 6798 const char* extension_names[] = { name }; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6901 v8::Isolate* isolate, | 6886 v8::Isolate* isolate, |
6902 v8::Handle<String> name); | 6887 v8::Handle<String> name); |
6903 }; | 6888 }; |
6904 | 6889 |
6905 | 6890 |
6906 static int lookup_count = 0; | 6891 static int lookup_count = 0; |
6907 v8::Handle<v8::FunctionTemplate> FunctionExtension::GetNativeFunctionTemplate( | 6892 v8::Handle<v8::FunctionTemplate> FunctionExtension::GetNativeFunctionTemplate( |
6908 v8::Isolate* isolate, v8::Handle<String> name) { | 6893 v8::Isolate* isolate, v8::Handle<String> name) { |
6909 lookup_count++; | 6894 lookup_count++; |
6910 if (name->Equals(v8_str("A"))) { | 6895 if (name->Equals(v8_str("A"))) { |
6911 return v8::FunctionTemplate::New( | 6896 return v8::FunctionTemplate::New(isolate, CallFun, v8::Integer::New(8)); |
6912 isolate, CallFun, v8::Integer::New(isolate, 8)); | |
6913 } else if (name->Equals(v8_str("B"))) { | 6897 } else if (name->Equals(v8_str("B"))) { |
6914 return v8::FunctionTemplate::New( | 6898 return v8::FunctionTemplate::New(isolate, CallFun, v8::Integer::New(7)); |
6915 isolate, CallFun, v8::Integer::New(isolate, 7)); | |
6916 } else if (name->Equals(v8_str("C"))) { | 6899 } else if (name->Equals(v8_str("C"))) { |
6917 return v8::FunctionTemplate::New( | 6900 return v8::FunctionTemplate::New(isolate, CallFun, v8::Integer::New(6)); |
6918 isolate, CallFun, v8::Integer::New(isolate, 6)); | |
6919 } else { | 6901 } else { |
6920 return v8::Handle<v8::FunctionTemplate>(); | 6902 return v8::Handle<v8::FunctionTemplate>(); |
6921 } | 6903 } |
6922 } | 6904 } |
6923 | 6905 |
6924 | 6906 |
6925 THREADED_TEST(FunctionLookup) { | 6907 THREADED_TEST(FunctionLookup) { |
6926 v8::RegisterExtension(new FunctionExtension()); | 6908 v8::RegisterExtension(new FunctionExtension()); |
6927 v8::HandleScope handle_scope(CcTest::isolate()); | 6909 v8::HandleScope handle_scope(CcTest::isolate()); |
6928 static const char* exts[1] = { "functiontest" }; | 6910 static const char* exts[1] = { "functiontest" }; |
6929 v8::ExtensionConfiguration config(1, exts); | 6911 v8::ExtensionConfiguration config(1, exts); |
6930 LocalContext context(&config); | 6912 LocalContext context(&config); |
6931 CHECK_EQ(3, lookup_count); | 6913 CHECK_EQ(3, lookup_count); |
6932 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 8), | 6914 CHECK_EQ(v8::Integer::New(8), Script::Compile(v8_str("Foo(0)"))->Run()); |
6933 Script::Compile(v8_str("Foo(0)"))->Run()); | 6915 CHECK_EQ(v8::Integer::New(7), Script::Compile(v8_str("Foo(1)"))->Run()); |
6934 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 7), | 6916 CHECK_EQ(v8::Integer::New(6), Script::Compile(v8_str("Foo(2)"))->Run()); |
6935 Script::Compile(v8_str("Foo(1)"))->Run()); | |
6936 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 6), | |
6937 Script::Compile(v8_str("Foo(2)"))->Run()); | |
6938 } | 6917 } |
6939 | 6918 |
6940 | 6919 |
6941 THREADED_TEST(NativeFunctionConstructCall) { | 6920 THREADED_TEST(NativeFunctionConstructCall) { |
6942 v8::RegisterExtension(new FunctionExtension()); | 6921 v8::RegisterExtension(new FunctionExtension()); |
6943 v8::HandleScope handle_scope(CcTest::isolate()); | 6922 v8::HandleScope handle_scope(CcTest::isolate()); |
6944 static const char* exts[1] = { "functiontest" }; | 6923 static const char* exts[1] = { "functiontest" }; |
6945 v8::ExtensionConfiguration config(1, exts); | 6924 v8::ExtensionConfiguration config(1, exts); |
6946 LocalContext context(&config); | 6925 LocalContext context(&config); |
6947 for (int i = 0; i < 10; i++) { | 6926 for (int i = 0; i < 10; i++) { |
6948 // Run a few times to ensure that allocation of objects doesn't | 6927 // Run a few times to ensure that allocation of objects doesn't |
6949 // change behavior of a constructor function. | 6928 // change behavior of a constructor function. |
6950 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 8), | 6929 CHECK_EQ(v8::Integer::New(8), |
6951 Script::Compile(v8_str("(new A()).data"))->Run()); | 6930 Script::Compile(v8_str("(new A()).data"))->Run()); |
6952 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 7), | 6931 CHECK_EQ(v8::Integer::New(7), |
6953 Script::Compile(v8_str("(new B()).data"))->Run()); | 6932 Script::Compile(v8_str("(new B()).data"))->Run()); |
6954 CHECK_EQ(v8::Integer::New(CcTest::isolate(), 6), | 6933 CHECK_EQ(v8::Integer::New(6), |
6955 Script::Compile(v8_str("(new C()).data"))->Run()); | 6934 Script::Compile(v8_str("(new C()).data"))->Run()); |
6956 } | 6935 } |
6957 } | 6936 } |
6958 | 6937 |
6959 | 6938 |
6960 static const char* last_location; | 6939 static const char* last_location; |
6961 static const char* last_message; | 6940 static const char* last_message; |
6962 void StoringErrorCallback(const char* location, const char* message) { | 6941 void StoringErrorCallback(const char* location, const char* message) { |
6963 if (last_location == NULL) { | 6942 if (last_location == NULL) { |
6964 last_location = location; | 6943 last_location = location; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7065 delete data.GetParameter(); | 7044 delete data.GetParameter(); |
7066 } | 7045 } |
7067 | 7046 |
7068 void WhammyPropertyGetter(Local<String> name, | 7047 void WhammyPropertyGetter(Local<String> name, |
7069 const v8::PropertyCallbackInfo<v8::Value>& info) { | 7048 const v8::PropertyCallbackInfo<v8::Value>& info) { |
7070 Whammy* whammy = | 7049 Whammy* whammy = |
7071 static_cast<Whammy*>(v8::Handle<v8::External>::Cast(info.Data())->Value()); | 7050 static_cast<Whammy*>(v8::Handle<v8::External>::Cast(info.Data())->Value()); |
7072 | 7051 |
7073 v8::Persistent<v8::Object>& prev = whammy->objects_[whammy->cursor_]; | 7052 v8::Persistent<v8::Object>& prev = whammy->objects_[whammy->cursor_]; |
7074 | 7053 |
7075 v8::Handle<v8::Object> obj = v8::Object::New(info.GetIsolate()); | 7054 v8::Handle<v8::Object> obj = v8::Object::New(); |
7076 if (!prev.IsEmpty()) { | 7055 if (!prev.IsEmpty()) { |
7077 v8::Local<v8::Object>::New(info.GetIsolate(), prev) | 7056 v8::Local<v8::Object>::New(info.GetIsolate(), prev) |
7078 ->Set(v8_str("next"), obj); | 7057 ->Set(v8_str("next"), obj); |
7079 prev.SetWeak<Value, Snorkel<Value> >(new Snorkel<Value>(&prev.As<Value>()), | 7058 prev.SetWeak<Value, Snorkel<Value> >(new Snorkel<Value>(&prev.As<Value>()), |
7080 &HandleWeakReference); | 7059 &HandleWeakReference); |
7081 } | 7060 } |
7082 whammy->objects_[whammy->cursor_].Reset(info.GetIsolate(), obj); | 7061 whammy->objects_[whammy->cursor_].Reset(info.GetIsolate(), obj); |
7083 whammy->cursor_ = (whammy->cursor_ + 1) % Whammy::kObjectCount; | 7062 whammy->cursor_ = (whammy->cursor_ + 1) % Whammy::kObjectCount; |
7084 info.GetReturnValue().Set(whammy->getScript()->Run()); | 7063 info.GetReturnValue().Set(whammy->getScript()->Run()); |
7085 } | 7064 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7131 THREADED_TEST(IndependentWeakHandle) { | 7110 THREADED_TEST(IndependentWeakHandle) { |
7132 v8::Isolate* iso = CcTest::isolate(); | 7111 v8::Isolate* iso = CcTest::isolate(); |
7133 v8::HandleScope scope(iso); | 7112 v8::HandleScope scope(iso); |
7134 v8::Handle<Context> context = Context::New(iso); | 7113 v8::Handle<Context> context = Context::New(iso); |
7135 Context::Scope context_scope(context); | 7114 Context::Scope context_scope(context); |
7136 | 7115 |
7137 FlagAndPersistent object_a, object_b; | 7116 FlagAndPersistent object_a, object_b; |
7138 | 7117 |
7139 { | 7118 { |
7140 v8::HandleScope handle_scope(iso); | 7119 v8::HandleScope handle_scope(iso); |
7141 object_a.handle.Reset(iso, v8::Object::New(iso)); | 7120 object_a.handle.Reset(iso, v8::Object::New()); |
7142 object_b.handle.Reset(iso, v8::Object::New(iso)); | 7121 object_b.handle.Reset(iso, v8::Object::New()); |
7143 } | 7122 } |
7144 | 7123 |
7145 object_a.flag = false; | 7124 object_a.flag = false; |
7146 object_b.flag = false; | 7125 object_b.flag = false; |
7147 object_a.handle.SetWeak(&object_a, &DisposeAndSetFlag); | 7126 object_a.handle.SetWeak(&object_a, &DisposeAndSetFlag); |
7148 object_b.handle.SetWeak(&object_b, &DisposeAndSetFlag); | 7127 object_b.handle.SetWeak(&object_b, &DisposeAndSetFlag); |
7149 CHECK(!object_b.handle.IsIndependent()); | 7128 CHECK(!object_b.handle.IsIndependent()); |
7150 object_a.handle.MarkIndependent(); | 7129 object_a.handle.MarkIndependent(); |
7151 object_b.handle.MarkIndependent(); | 7130 object_b.handle.MarkIndependent(); |
7152 CHECK(object_b.handle.IsIndependent()); | 7131 CHECK(object_b.handle.IsIndependent()); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7195 {&ForceScavenge, &ForceMarkSweep}; | 7174 {&ForceScavenge, &ForceMarkSweep}; |
7196 | 7175 |
7197 typedef void (*GCInvoker)(); | 7176 typedef void (*GCInvoker)(); |
7198 GCInvoker invoke_gc[kNumberOfGCTypes] = {&InvokeScavenge, &InvokeMarkSweep}; | 7177 GCInvoker invoke_gc[kNumberOfGCTypes] = {&InvokeScavenge, &InvokeMarkSweep}; |
7199 | 7178 |
7200 for (int outer_gc = 0; outer_gc < kNumberOfGCTypes; outer_gc++) { | 7179 for (int outer_gc = 0; outer_gc < kNumberOfGCTypes; outer_gc++) { |
7201 for (int inner_gc = 0; inner_gc < kNumberOfGCTypes; inner_gc++) { | 7180 for (int inner_gc = 0; inner_gc < kNumberOfGCTypes; inner_gc++) { |
7202 FlagAndPersistent object; | 7181 FlagAndPersistent object; |
7203 { | 7182 { |
7204 v8::HandleScope handle_scope(isolate); | 7183 v8::HandleScope handle_scope(isolate); |
7205 object.handle.Reset(isolate, v8::Object::New(isolate)); | 7184 object.handle.Reset(isolate, v8::Object::New()); |
7206 } | 7185 } |
7207 object.flag = false; | 7186 object.flag = false; |
7208 object.handle.SetWeak(&object, gc_forcing_callback[inner_gc]); | 7187 object.handle.SetWeak(&object, gc_forcing_callback[inner_gc]); |
7209 object.handle.MarkIndependent(); | 7188 object.handle.MarkIndependent(); |
7210 invoke_gc[outer_gc](); | 7189 invoke_gc[outer_gc](); |
7211 CHECK(object.flag); | 7190 CHECK(object.flag); |
7212 } | 7191 } |
7213 } | 7192 } |
7214 } | 7193 } |
7215 | 7194 |
7216 | 7195 |
7217 static void RevivingCallback( | 7196 static void RevivingCallback( |
7218 const v8::WeakCallbackData<v8::Object, FlagAndPersistent>& data) { | 7197 const v8::WeakCallbackData<v8::Object, FlagAndPersistent>& data) { |
7219 data.GetParameter()->handle.ClearWeak(); | 7198 data.GetParameter()->handle.ClearWeak(); |
7220 data.GetParameter()->flag = true; | 7199 data.GetParameter()->flag = true; |
7221 } | 7200 } |
7222 | 7201 |
7223 | 7202 |
7224 THREADED_TEST(IndependentHandleRevival) { | 7203 THREADED_TEST(IndependentHandleRevival) { |
7225 v8::Isolate* isolate = CcTest::isolate(); | 7204 v8::Isolate* isolate = CcTest::isolate(); |
7226 v8::HandleScope scope(isolate); | 7205 v8::HandleScope scope(isolate); |
7227 v8::Handle<Context> context = Context::New(isolate); | 7206 v8::Handle<Context> context = Context::New(isolate); |
7228 Context::Scope context_scope(context); | 7207 Context::Scope context_scope(context); |
7229 | 7208 |
7230 FlagAndPersistent object; | 7209 FlagAndPersistent object; |
7231 { | 7210 { |
7232 v8::HandleScope handle_scope(isolate); | 7211 v8::HandleScope handle_scope(isolate); |
7233 v8::Local<v8::Object> o = v8::Object::New(isolate); | 7212 v8::Local<v8::Object> o = v8::Object::New(); |
7234 object.handle.Reset(isolate, o); | 7213 object.handle.Reset(isolate, o); |
7235 o->Set(v8_str("x"), v8::Integer::New(isolate, 1)); | 7214 o->Set(v8_str("x"), v8::Integer::New(1)); |
7236 v8::Local<String> y_str = v8_str("y"); | 7215 v8::Local<String> y_str = v8_str("y"); |
7237 o->Set(y_str, y_str); | 7216 o->Set(y_str, y_str); |
7238 } | 7217 } |
7239 object.flag = false; | 7218 object.flag = false; |
7240 object.handle.SetWeak(&object, &RevivingCallback); | 7219 object.handle.SetWeak(&object, &RevivingCallback); |
7241 object.handle.MarkIndependent(); | 7220 object.handle.MarkIndependent(); |
7242 CcTest::heap()->PerformScavenge(); | 7221 CcTest::heap()->PerformScavenge(); |
7243 CHECK(object.flag); | 7222 CHECK(object.flag); |
7244 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 7223 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); |
7245 { | 7224 { |
7246 v8::HandleScope handle_scope(isolate); | 7225 v8::HandleScope handle_scope(isolate); |
7247 v8::Local<v8::Object> o = | 7226 v8::Local<v8::Object> o = |
7248 v8::Local<v8::Object>::New(isolate, object.handle); | 7227 v8::Local<v8::Object>::New(isolate, object.handle); |
7249 v8::Local<String> y_str = v8_str("y"); | 7228 v8::Local<String> y_str = v8_str("y"); |
7250 CHECK_EQ(v8::Integer::New(isolate, 1), o->Get(v8_str("x"))); | 7229 CHECK_EQ(v8::Integer::New(1), o->Get(v8_str("x"))); |
7251 CHECK(o->Get(y_str)->Equals(y_str)); | 7230 CHECK(o->Get(y_str)->Equals(y_str)); |
7252 } | 7231 } |
7253 } | 7232 } |
7254 | 7233 |
7255 | 7234 |
7256 v8::Handle<Function> args_fun; | 7235 v8::Handle<Function> args_fun; |
7257 | 7236 |
7258 | 7237 |
7259 static void ArgumentsTestCallback( | 7238 static void ArgumentsTestCallback( |
7260 const v8::FunctionCallbackInfo<v8::Value>& args) { | 7239 const v8::FunctionCallbackInfo<v8::Value>& args) { |
7261 ApiTestFuzzer::Fuzz(); | 7240 ApiTestFuzzer::Fuzz(); |
7262 v8::Isolate* isolate = args.GetIsolate(); | 7241 v8::Isolate* isolate = args.GetIsolate(); |
7263 CHECK_EQ(args_fun, args.Callee()); | 7242 CHECK_EQ(args_fun, args.Callee()); |
7264 CHECK_EQ(3, args.Length()); | 7243 CHECK_EQ(3, args.Length()); |
7265 CHECK_EQ(v8::Integer::New(isolate, 1), args[0]); | 7244 CHECK_EQ(v8::Integer::New(1, isolate), args[0]); |
7266 CHECK_EQ(v8::Integer::New(isolate, 2), args[1]); | 7245 CHECK_EQ(v8::Integer::New(2, isolate), args[1]); |
7267 CHECK_EQ(v8::Integer::New(isolate, 3), args[2]); | 7246 CHECK_EQ(v8::Integer::New(3, isolate), args[2]); |
7268 CHECK_EQ(v8::Undefined(isolate), args[3]); | 7247 CHECK_EQ(v8::Undefined(isolate), args[3]); |
7269 v8::HandleScope scope(args.GetIsolate()); | 7248 v8::HandleScope scope(args.GetIsolate()); |
7270 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 7249 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
7271 } | 7250 } |
7272 | 7251 |
7273 | 7252 |
7274 THREADED_TEST(Arguments) { | 7253 THREADED_TEST(Arguments) { |
7275 v8::Isolate* isolate = CcTest::isolate(); | 7254 v8::Isolate* isolate = CcTest::isolate(); |
7276 v8::HandleScope scope(isolate); | 7255 v8::HandleScope scope(isolate); |
7277 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(); | 7256 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7353 static void IndexedGetK(uint32_t index, | 7332 static void IndexedGetK(uint32_t index, |
7354 const v8::PropertyCallbackInfo<v8::Value>& info) { | 7333 const v8::PropertyCallbackInfo<v8::Value>& info) { |
7355 ApiTestFuzzer::Fuzz(); | 7334 ApiTestFuzzer::Fuzz(); |
7356 if (index == 0 || index == 1) info.GetReturnValue().SetUndefined(); | 7335 if (index == 0 || index == 1) info.GetReturnValue().SetUndefined(); |
7357 } | 7336 } |
7358 | 7337 |
7359 | 7338 |
7360 static void NamedEnum(const v8::PropertyCallbackInfo<v8::Array>& info) { | 7339 static void NamedEnum(const v8::PropertyCallbackInfo<v8::Array>& info) { |
7361 ApiTestFuzzer::Fuzz(); | 7340 ApiTestFuzzer::Fuzz(); |
7362 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 3); | 7341 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 3); |
7363 result->Set(v8::Integer::New(info.GetIsolate(), 0), v8_str("foo")); | 7342 result->Set(v8::Integer::New(0), v8_str("foo")); |
7364 result->Set(v8::Integer::New(info.GetIsolate(), 1), v8_str("bar")); | 7343 result->Set(v8::Integer::New(1), v8_str("bar")); |
7365 result->Set(v8::Integer::New(info.GetIsolate(), 2), v8_str("baz")); | 7344 result->Set(v8::Integer::New(2), v8_str("baz")); |
7366 info.GetReturnValue().Set(result); | 7345 info.GetReturnValue().Set(result); |
7367 } | 7346 } |
7368 | 7347 |
7369 | 7348 |
7370 static void IndexedEnum(const v8::PropertyCallbackInfo<v8::Array>& info) { | 7349 static void IndexedEnum(const v8::PropertyCallbackInfo<v8::Array>& info) { |
7371 ApiTestFuzzer::Fuzz(); | 7350 ApiTestFuzzer::Fuzz(); |
7372 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 2); | 7351 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 2); |
7373 result->Set(v8::Integer::New(info.GetIsolate(), 0), v8_str("0")); | 7352 result->Set(v8::Integer::New(0), v8_str("0")); |
7374 result->Set(v8::Integer::New(info.GetIsolate(), 1), v8_str("1")); | 7353 result->Set(v8::Integer::New(1), v8_str("1")); |
7375 info.GetReturnValue().Set(result); | 7354 info.GetReturnValue().Set(result); |
7376 } | 7355 } |
7377 | 7356 |
7378 | 7357 |
7379 THREADED_TEST(Enumerators) { | 7358 THREADED_TEST(Enumerators) { |
7380 v8::Isolate* isolate = CcTest::isolate(); | 7359 v8::HandleScope scope(CcTest::isolate()); |
7381 v8::HandleScope scope(isolate); | |
7382 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); | 7360 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); |
7383 obj->SetNamedPropertyHandler(GetK, NULL, NULL, NULL, NamedEnum); | 7361 obj->SetNamedPropertyHandler(GetK, NULL, NULL, NULL, NamedEnum); |
7384 obj->SetIndexedPropertyHandler(IndexedGetK, NULL, NULL, NULL, IndexedEnum); | 7362 obj->SetIndexedPropertyHandler(IndexedGetK, NULL, NULL, NULL, IndexedEnum); |
7385 LocalContext context; | 7363 LocalContext context; |
7386 context->Global()->Set(v8_str("k"), obj->NewInstance()); | 7364 context->Global()->Set(v8_str("k"), obj->NewInstance()); |
7387 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( | 7365 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( |
7388 "k[10] = 0;" | 7366 "k[10] = 0;" |
7389 "k.a = 0;" | 7367 "k.a = 0;" |
7390 "k[5] = 0;" | 7368 "k[5] = 0;" |
7391 "k.b = 0;" | 7369 "k.b = 0;" |
(...skipping 11 matching lines...) Expand all Loading... |
7403 "}" | 7381 "}" |
7404 "result")); | 7382 "result")); |
7405 // Check that we get all the property names returned including the | 7383 // Check that we get all the property names returned including the |
7406 // ones from the enumerators in the right order: indexed properties | 7384 // ones from the enumerators in the right order: indexed properties |
7407 // in numerical order, indexed interceptor properties, named | 7385 // in numerical order, indexed interceptor properties, named |
7408 // properties in insertion order, named interceptor properties. | 7386 // properties in insertion order, named interceptor properties. |
7409 // This order is not mandated by the spec, so this test is just | 7387 // This order is not mandated by the spec, so this test is just |
7410 // documenting our behavior. | 7388 // documenting our behavior. |
7411 CHECK_EQ(17, result->Length()); | 7389 CHECK_EQ(17, result->Length()); |
7412 // Indexed properties in numerical order. | 7390 // Indexed properties in numerical order. |
7413 CHECK_EQ(v8_str("5"), result->Get(v8::Integer::New(isolate, 0))); | 7391 CHECK_EQ(v8_str("5"), result->Get(v8::Integer::New(0))); |
7414 CHECK_EQ(v8_str("10"), result->Get(v8::Integer::New(isolate, 1))); | 7392 CHECK_EQ(v8_str("10"), result->Get(v8::Integer::New(1))); |
7415 CHECK_EQ(v8_str("140000"), result->Get(v8::Integer::New(isolate, 2))); | 7393 CHECK_EQ(v8_str("140000"), result->Get(v8::Integer::New(2))); |
7416 CHECK_EQ(v8_str("4294967295"), result->Get(v8::Integer::New(isolate, 3))); | 7394 CHECK_EQ(v8_str("4294967295"), result->Get(v8::Integer::New(3))); |
7417 // Indexed interceptor properties in the order they are returned | 7395 // Indexed interceptor properties in the order they are returned |
7418 // from the enumerator interceptor. | 7396 // from the enumerator interceptor. |
7419 CHECK_EQ(v8_str("0"), result->Get(v8::Integer::New(isolate, 4))); | 7397 CHECK_EQ(v8_str("0"), result->Get(v8::Integer::New(4))); |
7420 CHECK_EQ(v8_str("1"), result->Get(v8::Integer::New(isolate, 5))); | 7398 CHECK_EQ(v8_str("1"), result->Get(v8::Integer::New(5))); |
7421 // Named properties in insertion order. | 7399 // Named properties in insertion order. |
7422 CHECK_EQ(v8_str("a"), result->Get(v8::Integer::New(isolate, 6))); | 7400 CHECK_EQ(v8_str("a"), result->Get(v8::Integer::New(6))); |
7423 CHECK_EQ(v8_str("b"), result->Get(v8::Integer::New(isolate, 7))); | 7401 CHECK_EQ(v8_str("b"), result->Get(v8::Integer::New(7))); |
7424 CHECK_EQ(v8_str("c"), result->Get(v8::Integer::New(isolate, 8))); | 7402 CHECK_EQ(v8_str("c"), result->Get(v8::Integer::New(8))); |
7425 CHECK_EQ(v8_str("4294967296"), result->Get(v8::Integer::New(isolate, 9))); | 7403 CHECK_EQ(v8_str("4294967296"), result->Get(v8::Integer::New(9))); |
7426 CHECK_EQ(v8_str("d"), result->Get(v8::Integer::New(isolate, 10))); | 7404 CHECK_EQ(v8_str("d"), result->Get(v8::Integer::New(10))); |
7427 CHECK_EQ(v8_str("e"), result->Get(v8::Integer::New(isolate, 11))); | 7405 CHECK_EQ(v8_str("e"), result->Get(v8::Integer::New(11))); |
7428 CHECK_EQ(v8_str("30000000000"), result->Get(v8::Integer::New(isolate, 12))); | 7406 CHECK_EQ(v8_str("30000000000"), result->Get(v8::Integer::New(12))); |
7429 CHECK_EQ(v8_str("f"), result->Get(v8::Integer::New(isolate, 13))); | 7407 CHECK_EQ(v8_str("f"), result->Get(v8::Integer::New(13))); |
7430 // Named interceptor properties. | 7408 // Named interceptor properties. |
7431 CHECK_EQ(v8_str("foo"), result->Get(v8::Integer::New(isolate, 14))); | 7409 CHECK_EQ(v8_str("foo"), result->Get(v8::Integer::New(14))); |
7432 CHECK_EQ(v8_str("bar"), result->Get(v8::Integer::New(isolate, 15))); | 7410 CHECK_EQ(v8_str("bar"), result->Get(v8::Integer::New(15))); |
7433 CHECK_EQ(v8_str("baz"), result->Get(v8::Integer::New(isolate, 16))); | 7411 CHECK_EQ(v8_str("baz"), result->Get(v8::Integer::New(16))); |
7434 } | 7412 } |
7435 | 7413 |
7436 | 7414 |
7437 int p_getter_count; | 7415 int p_getter_count; |
7438 int p_getter_count2; | 7416 int p_getter_count2; |
7439 | 7417 |
7440 | 7418 |
7441 static void PGetter(Local<String> name, | 7419 static void PGetter(Local<String> name, |
7442 const v8::PropertyCallbackInfo<v8::Value>& info) { | 7420 const v8::PropertyCallbackInfo<v8::Value>& info) { |
7443 ApiTestFuzzer::Fuzz(); | 7421 ApiTestFuzzer::Fuzz(); |
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8042 CHECK(SameSymbol(sym0b, Handle<String>::Cast(s0b))); | 8020 CHECK(SameSymbol(sym0b, Handle<String>::Cast(s0b))); |
8043 CHECK(SameSymbol(sym1, Handle<String>::Cast(s1))); | 8021 CHECK(SameSymbol(sym1, Handle<String>::Cast(s1))); |
8044 CHECK(SameSymbol(sym2, Handle<String>::Cast(s2))); | 8022 CHECK(SameSymbol(sym2, Handle<String>::Cast(s2))); |
8045 CHECK(SameSymbol(sym3, Handle<String>::Cast(s3))); | 8023 CHECK(SameSymbol(sym3, Handle<String>::Cast(s3))); |
8046 CHECK(SameSymbol(sym4, Handle<String>::Cast(s4))); | 8024 CHECK(SameSymbol(sym4, Handle<String>::Cast(s4))); |
8047 } | 8025 } |
8048 | 8026 |
8049 | 8027 |
8050 THREADED_TEST(ToArrayIndex) { | 8028 THREADED_TEST(ToArrayIndex) { |
8051 LocalContext context; | 8029 LocalContext context; |
8052 v8::Isolate* isolate = context->GetIsolate(); | 8030 v8::HandleScope scope(context->GetIsolate()); |
8053 v8::HandleScope scope(isolate); | |
8054 | 8031 |
8055 v8::Handle<String> str = v8_str("42"); | 8032 v8::Handle<String> str = v8_str("42"); |
8056 v8::Handle<v8::Uint32> index = str->ToArrayIndex(); | 8033 v8::Handle<v8::Uint32> index = str->ToArrayIndex(); |
8057 CHECK(!index.IsEmpty()); | 8034 CHECK(!index.IsEmpty()); |
8058 CHECK_EQ(42.0, index->Uint32Value()); | 8035 CHECK_EQ(42.0, index->Uint32Value()); |
8059 str = v8_str("42asdf"); | 8036 str = v8_str("42asdf"); |
8060 index = str->ToArrayIndex(); | 8037 index = str->ToArrayIndex(); |
8061 CHECK(index.IsEmpty()); | 8038 CHECK(index.IsEmpty()); |
8062 str = v8_str("-42"); | 8039 str = v8_str("-42"); |
8063 index = str->ToArrayIndex(); | 8040 index = str->ToArrayIndex(); |
8064 CHECK(index.IsEmpty()); | 8041 CHECK(index.IsEmpty()); |
8065 str = v8_str("4294967295"); | 8042 str = v8_str("4294967295"); |
8066 index = str->ToArrayIndex(); | 8043 index = str->ToArrayIndex(); |
8067 CHECK(!index.IsEmpty()); | 8044 CHECK(!index.IsEmpty()); |
8068 CHECK_EQ(4294967295.0, index->Uint32Value()); | 8045 CHECK_EQ(4294967295.0, index->Uint32Value()); |
8069 v8::Handle<v8::Number> num = v8::Number::New(isolate, 1); | 8046 v8::Handle<v8::Number> num = v8::Number::New(1); |
8070 index = num->ToArrayIndex(); | 8047 index = num->ToArrayIndex(); |
8071 CHECK(!index.IsEmpty()); | 8048 CHECK(!index.IsEmpty()); |
8072 CHECK_EQ(1.0, index->Uint32Value()); | 8049 CHECK_EQ(1.0, index->Uint32Value()); |
8073 num = v8::Number::New(isolate, -1); | 8050 num = v8::Number::New(-1); |
8074 index = num->ToArrayIndex(); | 8051 index = num->ToArrayIndex(); |
8075 CHECK(index.IsEmpty()); | 8052 CHECK(index.IsEmpty()); |
8076 v8::Handle<v8::Object> obj = v8::Object::New(isolate); | 8053 v8::Handle<v8::Object> obj = v8::Object::New(); |
8077 index = obj->ToArrayIndex(); | 8054 index = obj->ToArrayIndex(); |
8078 CHECK(index.IsEmpty()); | 8055 CHECK(index.IsEmpty()); |
8079 } | 8056 } |
8080 | 8057 |
8081 | 8058 |
8082 THREADED_TEST(ErrorConstruction) { | 8059 THREADED_TEST(ErrorConstruction) { |
8083 LocalContext context; | 8060 LocalContext context; |
8084 v8::HandleScope scope(context->GetIsolate()); | 8061 v8::HandleScope scope(context->GetIsolate()); |
8085 | 8062 |
8086 v8::Handle<String> foo = v8_str("foo"); | 8063 v8::Handle<String> foo = v8_str("foo"); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8135 | 8112 |
8136 THREADED_TEST(TypeSwitch) { | 8113 THREADED_TEST(TypeSwitch) { |
8137 v8::Isolate* isolate = CcTest::isolate(); | 8114 v8::Isolate* isolate = CcTest::isolate(); |
8138 v8::HandleScope scope(isolate); | 8115 v8::HandleScope scope(isolate); |
8139 v8::Handle<v8::FunctionTemplate> templ1 = v8::FunctionTemplate::New(isolate); | 8116 v8::Handle<v8::FunctionTemplate> templ1 = v8::FunctionTemplate::New(isolate); |
8140 v8::Handle<v8::FunctionTemplate> templ2 = v8::FunctionTemplate::New(isolate); | 8117 v8::Handle<v8::FunctionTemplate> templ2 = v8::FunctionTemplate::New(isolate); |
8141 v8::Handle<v8::FunctionTemplate> templ3 = v8::FunctionTemplate::New(isolate); | 8118 v8::Handle<v8::FunctionTemplate> templ3 = v8::FunctionTemplate::New(isolate); |
8142 v8::Handle<v8::FunctionTemplate> templs[3] = { templ1, templ2, templ3 }; | 8119 v8::Handle<v8::FunctionTemplate> templs[3] = { templ1, templ2, templ3 }; |
8143 v8::Handle<v8::TypeSwitch> type_switch = v8::TypeSwitch::New(3, templs); | 8120 v8::Handle<v8::TypeSwitch> type_switch = v8::TypeSwitch::New(3, templs); |
8144 LocalContext context; | 8121 LocalContext context; |
8145 v8::Handle<v8::Object> obj0 = v8::Object::New(isolate); | 8122 v8::Handle<v8::Object> obj0 = v8::Object::New(); |
8146 v8::Handle<v8::Object> obj1 = templ1->GetFunction()->NewInstance(); | 8123 v8::Handle<v8::Object> obj1 = templ1->GetFunction()->NewInstance(); |
8147 v8::Handle<v8::Object> obj2 = templ2->GetFunction()->NewInstance(); | 8124 v8::Handle<v8::Object> obj2 = templ2->GetFunction()->NewInstance(); |
8148 v8::Handle<v8::Object> obj3 = templ3->GetFunction()->NewInstance(); | 8125 v8::Handle<v8::Object> obj3 = templ3->GetFunction()->NewInstance(); |
8149 for (int i = 0; i < 10; i++) { | 8126 for (int i = 0; i < 10; i++) { |
8150 CHECK_EQ(0, type_switch->match(obj0)); | 8127 CHECK_EQ(0, type_switch->match(obj0)); |
8151 CHECK_EQ(1, type_switch->match(obj1)); | 8128 CHECK_EQ(1, type_switch->match(obj1)); |
8152 CHECK_EQ(2, type_switch->match(obj2)); | 8129 CHECK_EQ(2, type_switch->match(obj2)); |
8153 CHECK_EQ(3, type_switch->match(obj3)); | 8130 CHECK_EQ(3, type_switch->match(obj3)); |
8154 CHECK_EQ(3, type_switch->match(obj3)); | 8131 CHECK_EQ(3, type_switch->match(obj3)); |
8155 CHECK_EQ(2, type_switch->match(obj2)); | 8132 CHECK_EQ(2, type_switch->match(obj2)); |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8588 | 8565 |
8589 // Set to the same domain. | 8566 // Set to the same domain. |
8590 env1->SetSecurityToken(foo); | 8567 env1->SetSecurityToken(foo); |
8591 env2->SetSecurityToken(foo); | 8568 env2->SetSecurityToken(foo); |
8592 | 8569 |
8593 // Enter env2 | 8570 // Enter env2 |
8594 env2->Enter(); | 8571 env2->Enter(); |
8595 | 8572 |
8596 // Create a function in env2 and add a reference to it in env1. | 8573 // Create a function in env2 and add a reference to it in env1. |
8597 Local<v8::Object> global2 = env2->Global(); | 8574 Local<v8::Object> global2 = env2->Global(); |
8598 global2->Set(v8_str("prop"), v8::Integer::New(env2->GetIsolate(), 1)); | 8575 global2->Set(v8_str("prop"), v8::Integer::New(1)); |
8599 CompileRun("function getProp() {return prop;}"); | 8576 CompileRun("function getProp() {return prop;}"); |
8600 | 8577 |
8601 env1->Global()->Set(v8_str("getProp"), | 8578 env1->Global()->Set(v8_str("getProp"), |
8602 global2->Get(v8_str("getProp"))); | 8579 global2->Get(v8_str("getProp"))); |
8603 | 8580 |
8604 // Detach env2's global, and reuse the global object of env2 | 8581 // Detach env2's global, and reuse the global object of env2 |
8605 env2->Exit(); | 8582 env2->Exit(); |
8606 env2->DetachGlobal(); | 8583 env2->DetachGlobal(); |
8607 | 8584 |
8608 v8::Handle<Context> env3 = Context::New(env1->GetIsolate(), | 8585 v8::Handle<Context> env3 = Context::New(env1->GetIsolate(), |
8609 0, | 8586 0, |
8610 v8::Handle<v8::ObjectTemplate>(), | 8587 v8::Handle<v8::ObjectTemplate>(), |
8611 global2); | 8588 global2); |
8612 env3->SetSecurityToken(v8_str("bar")); | 8589 env3->SetSecurityToken(v8_str("bar")); |
8613 env3->Enter(); | 8590 env3->Enter(); |
8614 | 8591 |
8615 Local<v8::Object> global3 = env3->Global(); | 8592 Local<v8::Object> global3 = env3->Global(); |
8616 CHECK_EQ(global2, global3); | 8593 CHECK_EQ(global2, global3); |
8617 CHECK(global3->Get(v8_str("prop"))->IsUndefined()); | 8594 CHECK(global3->Get(v8_str("prop"))->IsUndefined()); |
8618 CHECK(global3->Get(v8_str("getProp"))->IsUndefined()); | 8595 CHECK(global3->Get(v8_str("getProp"))->IsUndefined()); |
8619 global3->Set(v8_str("prop"), v8::Integer::New(env3->GetIsolate(), -1)); | 8596 global3->Set(v8_str("prop"), v8::Integer::New(-1)); |
8620 global3->Set(v8_str("prop2"), v8::Integer::New(env3->GetIsolate(), 2)); | 8597 global3->Set(v8_str("prop2"), v8::Integer::New(2)); |
8621 env3->Exit(); | 8598 env3->Exit(); |
8622 | 8599 |
8623 // Call getProp in env1, and it should return the value 1 | 8600 // Call getProp in env1, and it should return the value 1 |
8624 { | 8601 { |
8625 Local<Value> get_prop = global1->Get(v8_str("getProp")); | 8602 Local<Value> get_prop = global1->Get(v8_str("getProp")); |
8626 CHECK(get_prop->IsFunction()); | 8603 CHECK(get_prop->IsFunction()); |
8627 v8::TryCatch try_catch; | 8604 v8::TryCatch try_catch; |
8628 Local<Value> r = Function::Cast(*get_prop)->Call(global1, 0, NULL); | 8605 Local<Value> r = Function::Cast(*get_prop)->Call(global1, 0, NULL); |
8629 CHECK(!try_catch.HasCaught()); | 8606 CHECK(!try_catch.HasCaught()); |
8630 CHECK_EQ(1, r->Int32Value()); | 8607 CHECK_EQ(1, r->Int32Value()); |
(...skipping 16 matching lines...) Expand all Loading... |
8647 | 8624 |
8648 Local<Value> foo = v8_str("foo"); | 8625 Local<Value> foo = v8_str("foo"); |
8649 | 8626 |
8650 // Set same security token for env1 and env2. | 8627 // Set same security token for env1 and env2. |
8651 env1->SetSecurityToken(foo); | 8628 env1->SetSecurityToken(foo); |
8652 env2->SetSecurityToken(foo); | 8629 env2->SetSecurityToken(foo); |
8653 | 8630 |
8654 // Create a property on the global object in env2. | 8631 // Create a property on the global object in env2. |
8655 { | 8632 { |
8656 v8::Context::Scope scope(env2); | 8633 v8::Context::Scope scope(env2); |
8657 env2->Global()->Set(v8_str("p"), v8::Integer::New(env2->GetIsolate(), 42)); | 8634 env2->Global()->Set(v8_str("p"), v8::Integer::New(42)); |
8658 } | 8635 } |
8659 | 8636 |
8660 // Create a reference to env2 global from env1 global. | 8637 // Create a reference to env2 global from env1 global. |
8661 env1->Global()->Set(v8_str("other"), env2->Global()); | 8638 env1->Global()->Set(v8_str("other"), env2->Global()); |
8662 | 8639 |
8663 // Check that we have access to other.p in env2 from env1. | 8640 // Check that we have access to other.p in env2 from env1. |
8664 Local<Value> result = CompileRun("other.p"); | 8641 Local<Value> result = CompileRun("other.p"); |
8665 CHECK(result->IsInt32()); | 8642 CHECK(result->IsInt32()); |
8666 CHECK_EQ(42, result->Int32Value()); | 8643 CHECK_EQ(42, result->Int32Value()); |
8667 | 8644 |
(...skipping 12 matching lines...) Expand all Loading... |
8680 v8::Handle<v8::ObjectTemplate>(), | 8657 v8::Handle<v8::ObjectTemplate>(), |
8681 global2); | 8658 global2); |
8682 CHECK_EQ(global2, env3->Global()); | 8659 CHECK_EQ(global2, env3->Global()); |
8683 | 8660 |
8684 // Start by using the same security token for env3 as for env1 and env2. | 8661 // Start by using the same security token for env3 as for env1 and env2. |
8685 env3->SetSecurityToken(foo); | 8662 env3->SetSecurityToken(foo); |
8686 | 8663 |
8687 // Create a property on the global object in env3. | 8664 // Create a property on the global object in env3. |
8688 { | 8665 { |
8689 v8::Context::Scope scope(env3); | 8666 v8::Context::Scope scope(env3); |
8690 env3->Global()->Set(v8_str("p"), v8::Integer::New(env3->GetIsolate(), 24)); | 8667 env3->Global()->Set(v8_str("p"), v8::Integer::New(24)); |
8691 } | 8668 } |
8692 | 8669 |
8693 // Check that other.p is now the property in env3 and that we have access. | 8670 // Check that other.p is now the property in env3 and that we have access. |
8694 result = CompileRun("other.p"); | 8671 result = CompileRun("other.p"); |
8695 CHECK(result->IsInt32()); | 8672 CHECK(result->IsInt32()); |
8696 CHECK_EQ(24, result->Int32Value()); | 8673 CHECK_EQ(24, result->Int32Value()); |
8697 | 8674 |
8698 // Change security token for env3 to something different from env1 and env2. | 8675 // Change security token for env3 to something different from env1 and env2. |
8699 env3->SetSecurityToken(v8_str("bar")); | 8676 env3->SetSecurityToken(v8_str("bar")); |
8700 | 8677 |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9192 Local<Value> data) { | 9169 Local<Value> data) { |
9193 return false; | 9170 return false; |
9194 } | 9171 } |
9195 | 9172 |
9196 | 9173 |
9197 THREADED_TEST(AccessControlGetOwnPropertyNames) { | 9174 THREADED_TEST(AccessControlGetOwnPropertyNames) { |
9198 v8::Isolate* isolate = CcTest::isolate(); | 9175 v8::Isolate* isolate = CcTest::isolate(); |
9199 v8::HandleScope handle_scope(isolate); | 9176 v8::HandleScope handle_scope(isolate); |
9200 v8::Handle<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(); | 9177 v8::Handle<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(); |
9201 | 9178 |
9202 obj_template->Set(v8_str("x"), v8::Integer::New(isolate, 42)); | 9179 obj_template->Set(v8_str("x"), v8::Integer::New(42)); |
9203 obj_template->SetAccessCheckCallbacks(GetOwnPropertyNamesNamedBlocker, | 9180 obj_template->SetAccessCheckCallbacks(GetOwnPropertyNamesNamedBlocker, |
9204 GetOwnPropertyNamesIndexedBlocker); | 9181 GetOwnPropertyNamesIndexedBlocker); |
9205 | 9182 |
9206 // Create an environment | 9183 // Create an environment |
9207 v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template); | 9184 v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template); |
9208 context0->Enter(); | 9185 context0->Enter(); |
9209 | 9186 |
9210 v8::Handle<v8::Object> global0 = context0->Global(); | 9187 v8::Handle<v8::Object> global0 = context0->Global(); |
9211 | 9188 |
9212 v8::HandleScope scope1(CcTest::isolate()); | 9189 v8::HandleScope scope1(CcTest::isolate()); |
(...skipping 19 matching lines...) Expand all Loading... |
9232 CHECK(value->IsTrue()); | 9209 CHECK(value->IsTrue()); |
9233 | 9210 |
9234 context1->Exit(); | 9211 context1->Exit(); |
9235 context0->Exit(); | 9212 context0->Exit(); |
9236 } | 9213 } |
9237 | 9214 |
9238 | 9215 |
9239 static void IndexedPropertyEnumerator( | 9216 static void IndexedPropertyEnumerator( |
9240 const v8::PropertyCallbackInfo<v8::Array>& info) { | 9217 const v8::PropertyCallbackInfo<v8::Array>& info) { |
9241 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 2); | 9218 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 2); |
9242 result->Set(0, v8::Integer::New(info.GetIsolate(), 7)); | 9219 result->Set(0, v8::Integer::New(7)); |
9243 result->Set(1, v8::Object::New(info.GetIsolate())); | 9220 result->Set(1, v8::Object::New()); |
9244 info.GetReturnValue().Set(result); | 9221 info.GetReturnValue().Set(result); |
9245 } | 9222 } |
9246 | 9223 |
9247 | 9224 |
9248 static void NamedPropertyEnumerator( | 9225 static void NamedPropertyEnumerator( |
9249 const v8::PropertyCallbackInfo<v8::Array>& info) { | 9226 const v8::PropertyCallbackInfo<v8::Array>& info) { |
9250 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 2); | 9227 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 2); |
9251 result->Set(0, v8_str("x")); | 9228 result->Set(0, v8_str("x")); |
9252 result->Set(1, v8::Object::New(info.GetIsolate())); | 9229 result->Set(1, v8::Object::New()); |
9253 info.GetReturnValue().Set(result); | 9230 info.GetReturnValue().Set(result); |
9254 } | 9231 } |
9255 | 9232 |
9256 | 9233 |
9257 THREADED_TEST(GetOwnPropertyNamesWithInterceptor) { | 9234 THREADED_TEST(GetOwnPropertyNamesWithInterceptor) { |
9258 v8::HandleScope handle_scope(CcTest::isolate()); | 9235 v8::HandleScope handle_scope(CcTest::isolate()); |
9259 v8::Handle<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(); | 9236 v8::Handle<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(); |
9260 | 9237 |
9261 obj_template->Set(v8_str("7"), v8::Integer::New(CcTest::isolate(), 7)); | 9238 obj_template->Set(v8_str("7"), v8::Integer::New(7)); |
9262 obj_template->Set(v8_str("x"), v8::Integer::New(CcTest::isolate(), 42)); | 9239 obj_template->Set(v8_str("x"), v8::Integer::New(42)); |
9263 obj_template->SetIndexedPropertyHandler(NULL, NULL, NULL, NULL, | 9240 obj_template->SetIndexedPropertyHandler(NULL, NULL, NULL, NULL, |
9264 IndexedPropertyEnumerator); | 9241 IndexedPropertyEnumerator); |
9265 obj_template->SetNamedPropertyHandler(NULL, NULL, NULL, NULL, | 9242 obj_template->SetNamedPropertyHandler(NULL, NULL, NULL, NULL, |
9266 NamedPropertyEnumerator); | 9243 NamedPropertyEnumerator); |
9267 | 9244 |
9268 LocalContext context; | 9245 LocalContext context; |
9269 v8::Handle<v8::Object> global = context->Global(); | 9246 v8::Handle<v8::Object> global = context->Global(); |
9270 global->Set(v8_str("object"), obj_template->NewInstance()); | 9247 global->Set(v8_str("object"), obj_template->NewInstance()); |
9271 | 9248 |
9272 v8::Handle<v8::Value> result = | 9249 v8::Handle<v8::Value> result = |
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9958 | 9935 |
9959 // Regression test for issue 2457. | 9936 // Regression test for issue 2457. |
9960 THREADED_TEST(HiddenPrototypeIdentityHash) { | 9937 THREADED_TEST(HiddenPrototypeIdentityHash) { |
9961 LocalContext context; | 9938 LocalContext context; |
9962 v8::HandleScope handle_scope(context->GetIsolate()); | 9939 v8::HandleScope handle_scope(context->GetIsolate()); |
9963 | 9940 |
9964 Handle<FunctionTemplate> t = FunctionTemplate::New(context->GetIsolate()); | 9941 Handle<FunctionTemplate> t = FunctionTemplate::New(context->GetIsolate()); |
9965 t->SetHiddenPrototype(true); | 9942 t->SetHiddenPrototype(true); |
9966 t->InstanceTemplate()->Set(v8_str("foo"), v8_num(75)); | 9943 t->InstanceTemplate()->Set(v8_str("foo"), v8_num(75)); |
9967 Handle<Object> p = t->GetFunction()->NewInstance(); | 9944 Handle<Object> p = t->GetFunction()->NewInstance(); |
9968 Handle<Object> o = Object::New(context->GetIsolate()); | 9945 Handle<Object> o = Object::New(); |
9969 o->SetPrototype(p); | 9946 o->SetPrototype(p); |
9970 | 9947 |
9971 int hash = o->GetIdentityHash(); | 9948 int hash = o->GetIdentityHash(); |
9972 USE(hash); | 9949 USE(hash); |
9973 o->Set(v8_str("foo"), v8_num(42)); | 9950 o->Set(v8_str("foo"), v8_num(42)); |
9974 ASSERT_EQ(hash, o->GetIdentityHash()); | 9951 ASSERT_EQ(hash, o->GetIdentityHash()); |
9975 } | 9952 } |
9976 | 9953 |
9977 | 9954 |
9978 THREADED_TEST(SetPrototype) { | 9955 THREADED_TEST(SetPrototype) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10041 LocalContext context; | 10018 LocalContext context; |
10042 v8::Isolate* isolate = context->GetIsolate(); | 10019 v8::Isolate* isolate = context->GetIsolate(); |
10043 v8::HandleScope handle_scope(isolate); | 10020 v8::HandleScope handle_scope(isolate); |
10044 | 10021 |
10045 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate); | 10022 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate); |
10046 t1->SetHiddenPrototype(true); | 10023 t1->SetHiddenPrototype(true); |
10047 t1->InstanceTemplate()->Set(v8_str("foo"), v8_num(1)); | 10024 t1->InstanceTemplate()->Set(v8_str("foo"), v8_num(1)); |
10048 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate); | 10025 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate); |
10049 t2->SetHiddenPrototype(true); | 10026 t2->SetHiddenPrototype(true); |
10050 t2->InstanceTemplate()->Set(v8_str("fuz1"), v8_num(2)); | 10027 t2->InstanceTemplate()->Set(v8_str("fuz1"), v8_num(2)); |
10051 t2->InstanceTemplate()->Set(v8_str("objects"), v8::Object::New(isolate)); | 10028 t2->InstanceTemplate()->Set(v8_str("objects"), v8::Object::New()); |
10052 t2->InstanceTemplate()->Set(v8_str("fuz2"), v8_num(2)); | 10029 t2->InstanceTemplate()->Set(v8_str("fuz2"), v8_num(2)); |
10053 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(isolate); | 10030 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(isolate); |
10054 t3->SetHiddenPrototype(true); | 10031 t3->SetHiddenPrototype(true); |
10055 t3->InstanceTemplate()->Set(v8_str("boo"), v8_num(3)); | 10032 t3->InstanceTemplate()->Set(v8_str("boo"), v8_num(3)); |
10056 Local<v8::FunctionTemplate> t4 = v8::FunctionTemplate::New(isolate); | 10033 Local<v8::FunctionTemplate> t4 = v8::FunctionTemplate::New(isolate); |
10057 t4->InstanceTemplate()->Set(v8_str("baz"), v8_num(4)); | 10034 t4->InstanceTemplate()->Set(v8_str("baz"), v8_num(4)); |
10058 | 10035 |
10059 // Force dictionary-based properties. | 10036 // Force dictionary-based properties. |
10060 i::ScopedVector<char> name_buf(1024); | 10037 i::ScopedVector<char> name_buf(1024); |
10061 for (int i = 1; i <= 1000; i++) { | 10038 for (int i = 1; i <= 1000; i++) { |
(...skipping 25 matching lines...) Expand all Loading... |
10087 ExpectFalse("names[1005] == undefined"); | 10064 ExpectFalse("names[1005] == undefined"); |
10088 } | 10065 } |
10089 | 10066 |
10090 | 10067 |
10091 THREADED_TEST(FunctionReadOnlyPrototype) { | 10068 THREADED_TEST(FunctionReadOnlyPrototype) { |
10092 LocalContext context; | 10069 LocalContext context; |
10093 v8::Isolate* isolate = context->GetIsolate(); | 10070 v8::Isolate* isolate = context->GetIsolate(); |
10094 v8::HandleScope handle_scope(isolate); | 10071 v8::HandleScope handle_scope(isolate); |
10095 | 10072 |
10096 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate); | 10073 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate); |
10097 t1->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(isolate, 42)); | 10074 t1->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(42)); |
10098 t1->ReadOnlyPrototype(); | 10075 t1->ReadOnlyPrototype(); |
10099 context->Global()->Set(v8_str("func1"), t1->GetFunction()); | 10076 context->Global()->Set(v8_str("func1"), t1->GetFunction()); |
10100 // Configured value of ReadOnly flag. | 10077 // Configured value of ReadOnly flag. |
10101 CHECK(CompileRun( | 10078 CHECK(CompileRun( |
10102 "(function() {" | 10079 "(function() {" |
10103 " descriptor = Object.getOwnPropertyDescriptor(func1, 'prototype');" | 10080 " descriptor = Object.getOwnPropertyDescriptor(func1, 'prototype');" |
10104 " return (descriptor['writable'] == false);" | 10081 " return (descriptor['writable'] == false);" |
10105 "})()")->BooleanValue()); | 10082 "})()")->BooleanValue()); |
10106 CHECK_EQ(42, CompileRun("func1.prototype.x")->Int32Value()); | 10083 CHECK_EQ(42, CompileRun("func1.prototype.x")->Int32Value()); |
10107 CHECK_EQ(42, | 10084 CHECK_EQ(42, |
10108 CompileRun("func1.prototype = {}; func1.prototype.x")->Int32Value()); | 10085 CompileRun("func1.prototype = {}; func1.prototype.x")->Int32Value()); |
10109 | 10086 |
10110 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate); | 10087 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate); |
10111 t2->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(isolate, 42)); | 10088 t2->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(42)); |
10112 context->Global()->Set(v8_str("func2"), t2->GetFunction()); | 10089 context->Global()->Set(v8_str("func2"), t2->GetFunction()); |
10113 // Default value of ReadOnly flag. | 10090 // Default value of ReadOnly flag. |
10114 CHECK(CompileRun( | 10091 CHECK(CompileRun( |
10115 "(function() {" | 10092 "(function() {" |
10116 " descriptor = Object.getOwnPropertyDescriptor(func2, 'prototype');" | 10093 " descriptor = Object.getOwnPropertyDescriptor(func2, 'prototype');" |
10117 " return (descriptor['writable'] == true);" | 10094 " return (descriptor['writable'] == true);" |
10118 "})()")->BooleanValue()); | 10095 "})()")->BooleanValue()); |
10119 CHECK_EQ(42, CompileRun("func2.prototype.x")->Int32Value()); | 10096 CHECK_EQ(42, CompileRun("func2.prototype.x")->Int32Value()); |
10120 } | 10097 } |
10121 | 10098 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10158 CHECK(try_catch.HasCaught()); | 10135 CHECK(try_catch.HasCaught()); |
10159 | 10136 |
10160 try_catch.Reset(); | 10137 try_catch.Reset(); |
10161 fun->NewInstance(); | 10138 fun->NewInstance(); |
10162 CHECK(try_catch.HasCaught()); | 10139 CHECK(try_catch.HasCaught()); |
10163 } | 10140 } |
10164 | 10141 |
10165 | 10142 |
10166 THREADED_TEST(GetterSetterExceptions) { | 10143 THREADED_TEST(GetterSetterExceptions) { |
10167 LocalContext context; | 10144 LocalContext context; |
10168 v8::Isolate* isolate = context->GetIsolate(); | 10145 v8::HandleScope handle_scope(context->GetIsolate()); |
10169 v8::HandleScope handle_scope(isolate); | |
10170 CompileRun( | 10146 CompileRun( |
10171 "function Foo() { };" | 10147 "function Foo() { };" |
10172 "function Throw() { throw 5; };" | 10148 "function Throw() { throw 5; };" |
10173 "var x = { };" | 10149 "var x = { };" |
10174 "x.__defineSetter__('set', Throw);" | 10150 "x.__defineSetter__('set', Throw);" |
10175 "x.__defineGetter__('get', Throw);"); | 10151 "x.__defineGetter__('get', Throw);"); |
10176 Local<v8::Object> x = | 10152 Local<v8::Object> x = |
10177 Local<v8::Object>::Cast(context->Global()->Get(v8_str("x"))); | 10153 Local<v8::Object>::Cast(context->Global()->Get(v8_str("x"))); |
10178 v8::TryCatch try_catch; | 10154 v8::TryCatch try_catch; |
10179 x->Set(v8_str("set"), v8::Integer::New(isolate, 8)); | 10155 x->Set(v8_str("set"), v8::Integer::New(8)); |
10180 x->Get(v8_str("get")); | 10156 x->Get(v8_str("get")); |
10181 x->Set(v8_str("set"), v8::Integer::New(isolate, 8)); | 10157 x->Set(v8_str("set"), v8::Integer::New(8)); |
10182 x->Get(v8_str("get")); | 10158 x->Get(v8_str("get")); |
10183 x->Set(v8_str("set"), v8::Integer::New(isolate, 8)); | 10159 x->Set(v8_str("set"), v8::Integer::New(8)); |
10184 x->Get(v8_str("get")); | 10160 x->Get(v8_str("get")); |
10185 x->Set(v8_str("set"), v8::Integer::New(isolate, 8)); | 10161 x->Set(v8_str("set"), v8::Integer::New(8)); |
10186 x->Get(v8_str("get")); | 10162 x->Get(v8_str("get")); |
10187 } | 10163 } |
10188 | 10164 |
10189 | 10165 |
10190 THREADED_TEST(Constructor) { | 10166 THREADED_TEST(Constructor) { |
10191 LocalContext context; | 10167 LocalContext context; |
10192 v8::Isolate* isolate = context->GetIsolate(); | 10168 v8::Isolate* isolate = context->GetIsolate(); |
10193 v8::HandleScope handle_scope(isolate); | 10169 v8::HandleScope handle_scope(isolate); |
10194 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); | 10170 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); |
10195 templ->SetClassName(v8_str("Fun")); | 10171 templ->SetClassName(v8_str("Fun")); |
10196 Local<Function> cons = templ->GetFunction(); | 10172 Local<Function> cons = templ->GetFunction(); |
10197 context->Global()->Set(v8_str("Fun"), cons); | 10173 context->Global()->Set(v8_str("Fun"), cons); |
10198 Local<v8::Object> inst = cons->NewInstance(); | 10174 Local<v8::Object> inst = cons->NewInstance(); |
10199 i::Handle<i::JSObject> obj(v8::Utils::OpenHandle(*inst)); | 10175 i::Handle<i::JSObject> obj(v8::Utils::OpenHandle(*inst)); |
10200 CHECK(obj->IsJSObject()); | 10176 CHECK(obj->IsJSObject()); |
10201 Local<Value> value = CompileRun("(new Fun()).constructor === Fun"); | 10177 Local<Value> value = CompileRun("(new Fun()).constructor === Fun"); |
10202 CHECK(value->BooleanValue()); | 10178 CHECK(value->BooleanValue()); |
10203 } | 10179 } |
10204 | 10180 |
10205 | 10181 |
10206 static void ConstructorCallback( | 10182 static void ConstructorCallback( |
10207 const v8::FunctionCallbackInfo<v8::Value>& args) { | 10183 const v8::FunctionCallbackInfo<v8::Value>& args) { |
10208 ApiTestFuzzer::Fuzz(); | 10184 ApiTestFuzzer::Fuzz(); |
10209 Local<Object> This; | 10185 Local<Object> This; |
10210 | 10186 |
10211 if (args.IsConstructCall()) { | 10187 if (args.IsConstructCall()) { |
10212 Local<Object> Holder = args.Holder(); | 10188 Local<Object> Holder = args.Holder(); |
10213 This = Object::New(args.GetIsolate()); | 10189 This = Object::New(); |
10214 Local<Value> proto = Holder->GetPrototype(); | 10190 Local<Value> proto = Holder->GetPrototype(); |
10215 if (proto->IsObject()) { | 10191 if (proto->IsObject()) { |
10216 This->SetPrototype(proto); | 10192 This->SetPrototype(proto); |
10217 } | 10193 } |
10218 } else { | 10194 } else { |
10219 This = args.This(); | 10195 This = args.This(); |
10220 } | 10196 } |
10221 | 10197 |
10222 This->Set(v8_str("a"), args[0]); | 10198 This->Set(v8_str("a"), args[0]); |
10223 args.GetReturnValue().Set(This); | 10199 args.GetReturnValue().Set(This); |
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10850 | 10826 |
10851 static int CountHandles() { | 10827 static int CountHandles() { |
10852 return v8::HandleScope::NumberOfHandles(); | 10828 return v8::HandleScope::NumberOfHandles(); |
10853 } | 10829 } |
10854 | 10830 |
10855 | 10831 |
10856 static int Recurse(int depth, int iterations) { | 10832 static int Recurse(int depth, int iterations) { |
10857 v8::HandleScope scope(CcTest::isolate()); | 10833 v8::HandleScope scope(CcTest::isolate()); |
10858 if (depth == 0) return CountHandles(); | 10834 if (depth == 0) return CountHandles(); |
10859 for (int i = 0; i < iterations; i++) { | 10835 for (int i = 0; i < iterations; i++) { |
10860 Local<v8::Number> n(v8::Integer::New(CcTest::isolate(), 42)); | 10836 Local<v8::Number> n(v8::Integer::New(42)); |
10861 } | 10837 } |
10862 return Recurse(depth - 1, iterations); | 10838 return Recurse(depth - 1, iterations); |
10863 } | 10839 } |
10864 | 10840 |
10865 | 10841 |
10866 THREADED_TEST(HandleIteration) { | 10842 THREADED_TEST(HandleIteration) { |
10867 static const int kIterations = 500; | 10843 static const int kIterations = 500; |
10868 static const int kNesting = 200; | 10844 static const int kNesting = 200; |
10869 CHECK_EQ(0, CountHandles()); | 10845 CHECK_EQ(0, CountHandles()); |
10870 { | 10846 { |
10871 v8::HandleScope scope1(CcTest::isolate()); | 10847 v8::HandleScope scope1(CcTest::isolate()); |
10872 CHECK_EQ(0, CountHandles()); | 10848 CHECK_EQ(0, CountHandles()); |
10873 for (int i = 0; i < kIterations; i++) { | 10849 for (int i = 0; i < kIterations; i++) { |
10874 Local<v8::Number> n(v8::Integer::New(CcTest::isolate(), 42)); | 10850 Local<v8::Number> n(v8::Integer::New(42)); |
10875 CHECK_EQ(i + 1, CountHandles()); | 10851 CHECK_EQ(i + 1, CountHandles()); |
10876 } | 10852 } |
10877 | 10853 |
10878 CHECK_EQ(kIterations, CountHandles()); | 10854 CHECK_EQ(kIterations, CountHandles()); |
10879 { | 10855 { |
10880 v8::HandleScope scope2(CcTest::isolate()); | 10856 v8::HandleScope scope2(CcTest::isolate()); |
10881 for (int j = 0; j < kIterations; j++) { | 10857 for (int j = 0; j < kIterations; j++) { |
10882 Local<v8::Number> n(v8::Integer::New(CcTest::isolate(), 42)); | 10858 Local<v8::Number> n(v8::Integer::New(42)); |
10883 CHECK_EQ(j + 1 + kIterations, CountHandles()); | 10859 CHECK_EQ(j + 1 + kIterations, CountHandles()); |
10884 } | 10860 } |
10885 } | 10861 } |
10886 CHECK_EQ(kIterations, CountHandles()); | 10862 CHECK_EQ(kIterations, CountHandles()); |
10887 } | 10863 } |
10888 CHECK_EQ(0, CountHandles()); | 10864 CHECK_EQ(0, CountHandles()); |
10889 CHECK_EQ(kNesting * kIterations, Recurse(kNesting, kIterations)); | 10865 CHECK_EQ(kNesting * kIterations, Recurse(kNesting, kIterations)); |
10890 } | 10866 } |
10891 | 10867 |
10892 | 10868 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10978 | 10954 |
10979 | 10955 |
10980 static void InterceptorLoadICGetter( | 10956 static void InterceptorLoadICGetter( |
10981 Local<String> name, | 10957 Local<String> name, |
10982 const v8::PropertyCallbackInfo<v8::Value>& info) { | 10958 const v8::PropertyCallbackInfo<v8::Value>& info) { |
10983 ApiTestFuzzer::Fuzz(); | 10959 ApiTestFuzzer::Fuzz(); |
10984 v8::Isolate* isolate = CcTest::isolate(); | 10960 v8::Isolate* isolate = CcTest::isolate(); |
10985 CHECK_EQ(isolate, info.GetIsolate()); | 10961 CHECK_EQ(isolate, info.GetIsolate()); |
10986 CHECK_EQ(v8_str("data"), info.Data()); | 10962 CHECK_EQ(v8_str("data"), info.Data()); |
10987 CHECK_EQ(v8_str("x"), name); | 10963 CHECK_EQ(v8_str("x"), name); |
10988 info.GetReturnValue().Set(v8::Integer::New(isolate, 42)); | 10964 info.GetReturnValue().Set(v8::Integer::New(42)); |
10989 } | 10965 } |
10990 | 10966 |
10991 | 10967 |
10992 // This test should hit the load IC for the interceptor case. | 10968 // This test should hit the load IC for the interceptor case. |
10993 THREADED_TEST(InterceptorLoadIC) { | 10969 THREADED_TEST(InterceptorLoadIC) { |
10994 CheckInterceptorLoadIC(InterceptorLoadICGetter, | 10970 CheckInterceptorLoadIC(InterceptorLoadICGetter, |
10995 "var result = 0;" | 10971 "var result = 0;" |
10996 "for (var i = 0; i < 1000; i++) {" | 10972 "for (var i = 0; i < 1000; i++) {" |
10997 " result = o.x;" | 10973 " result = o.x;" |
10998 "}", | 10974 "}", |
10999 42); | 10975 42); |
11000 } | 10976 } |
11001 | 10977 |
11002 | 10978 |
11003 // Below go several tests which verify that JITing for various | 10979 // Below go several tests which verify that JITing for various |
11004 // configurations of interceptor and explicit fields works fine | 10980 // configurations of interceptor and explicit fields works fine |
11005 // (those cases are special cased to get better performance). | 10981 // (those cases are special cased to get better performance). |
11006 | 10982 |
11007 static void InterceptorLoadXICGetter( | 10983 static void InterceptorLoadXICGetter( |
11008 Local<String> name, | 10984 Local<String> name, |
11009 const v8::PropertyCallbackInfo<v8::Value>& info) { | 10985 const v8::PropertyCallbackInfo<v8::Value>& info) { |
11010 ApiTestFuzzer::Fuzz(); | 10986 ApiTestFuzzer::Fuzz(); |
11011 info.GetReturnValue().Set( | 10987 info.GetReturnValue().Set( |
11012 v8_str("x")->Equals(name) ? | 10988 v8_str("x")->Equals(name) ? |
11013 v8::Handle<v8::Value>(v8::Integer::New(info.GetIsolate(), 42)) : | 10989 v8::Handle<v8::Value>(v8::Integer::New(42)) : |
11014 v8::Handle<v8::Value>()); | 10990 v8::Handle<v8::Value>()); |
11015 } | 10991 } |
11016 | 10992 |
11017 | 10993 |
11018 THREADED_TEST(InterceptorLoadICWithFieldOnHolder) { | 10994 THREADED_TEST(InterceptorLoadICWithFieldOnHolder) { |
11019 CheckInterceptorLoadIC(InterceptorLoadXICGetter, | 10995 CheckInterceptorLoadIC(InterceptorLoadXICGetter, |
11020 "var result = 0;" | 10996 "var result = 0;" |
11021 "o.y = 239;" | 10997 "o.y = 239;" |
11022 "for (var i = 0; i < 1000; i++) {" | 10998 "for (var i = 0; i < 1000; i++) {" |
11023 " result = o.y;" | 10999 " result = o.y;" |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11355 "result"); | 11331 "result"); |
11356 CHECK_EQ(42 * 10, value->Int32Value()); | 11332 CHECK_EQ(42 * 10, value->Int32Value()); |
11357 } | 11333 } |
11358 | 11334 |
11359 | 11335 |
11360 static void InterceptorLoadICGetter0( | 11336 static void InterceptorLoadICGetter0( |
11361 Local<String> name, | 11337 Local<String> name, |
11362 const v8::PropertyCallbackInfo<v8::Value>& info) { | 11338 const v8::PropertyCallbackInfo<v8::Value>& info) { |
11363 ApiTestFuzzer::Fuzz(); | 11339 ApiTestFuzzer::Fuzz(); |
11364 CHECK(v8_str("x")->Equals(name)); | 11340 CHECK(v8_str("x")->Equals(name)); |
11365 info.GetReturnValue().Set(v8::Integer::New(info.GetIsolate(), 0)); | 11341 info.GetReturnValue().Set(v8::Integer::New(0)); |
11366 } | 11342 } |
11367 | 11343 |
11368 | 11344 |
11369 THREADED_TEST(InterceptorReturningZero) { | 11345 THREADED_TEST(InterceptorReturningZero) { |
11370 CheckInterceptorLoadIC(InterceptorLoadICGetter0, | 11346 CheckInterceptorLoadIC(InterceptorLoadICGetter0, |
11371 "o.x == undefined ? 1 : 0", | 11347 "o.x == undefined ? 1 : 0", |
11372 0); | 11348 0); |
11373 } | 11349 } |
11374 | 11350 |
11375 | 11351 |
(...skipping 1225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12601 ApiTestFuzzer::Fuzz(); | 12577 ApiTestFuzzer::Fuzz(); |
12602 info.GetIsolate()->ThrowException(Handle<Value>()); | 12578 info.GetIsolate()->ThrowException(Handle<Value>()); |
12603 info.GetReturnValue().SetUndefined(); | 12579 info.GetReturnValue().SetUndefined(); |
12604 } | 12580 } |
12605 | 12581 |
12606 | 12582 |
12607 THREADED_TEST(VariousGetPropertiesAndThrowingCallbacks) { | 12583 THREADED_TEST(VariousGetPropertiesAndThrowingCallbacks) { |
12608 LocalContext context; | 12584 LocalContext context; |
12609 HandleScope scope(context->GetIsolate()); | 12585 HandleScope scope(context->GetIsolate()); |
12610 | 12586 |
12611 Local<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate()); | 12587 Local<FunctionTemplate> templ = FunctionTemplate::New(CcTest::isolate()); |
12612 Local<ObjectTemplate> instance_templ = templ->InstanceTemplate(); | 12588 Local<ObjectTemplate> instance_templ = templ->InstanceTemplate(); |
12613 instance_templ->SetAccessor(v8_str("f"), ThrowingGetter); | 12589 instance_templ->SetAccessor(v8_str("f"), ThrowingGetter); |
12614 | 12590 |
12615 Local<Object> instance = templ->GetFunction()->NewInstance(); | 12591 Local<Object> instance = templ->GetFunction()->NewInstance(); |
12616 | 12592 |
12617 Local<Object> another = Object::New(context->GetIsolate()); | 12593 Local<Object> another = Object::New(); |
12618 another->SetPrototype(instance); | 12594 another->SetPrototype(instance); |
12619 | 12595 |
12620 Local<Object> with_js_getter = CompileRun( | 12596 Local<Object> with_js_getter = CompileRun( |
12621 "o = {};\n" | 12597 "o = {};\n" |
12622 "o.__defineGetter__('f', function() { throw undefined; });\n" | 12598 "o.__defineGetter__('f', function() { throw undefined; });\n" |
12623 "o\n").As<Object>(); | 12599 "o\n").As<Object>(); |
12624 CHECK(!with_js_getter.IsEmpty()); | 12600 CHECK(!with_js_getter.IsEmpty()); |
12625 | 12601 |
12626 TryCatch try_catch; | 12602 TryCatch try_catch; |
12627 | 12603 |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13248 v8::Isolate* isolate = context->GetIsolate(); | 13224 v8::Isolate* isolate = context->GetIsolate(); |
13249 i::GlobalHandles* globals = | 13225 i::GlobalHandles* globals = |
13250 reinterpret_cast<i::Isolate*>(isolate)->global_handles(); | 13226 reinterpret_cast<i::Isolate*>(isolate)->global_handles(); |
13251 int initial_handles = globals->global_handles_count(); | 13227 int initial_handles = globals->global_handles_count(); |
13252 typedef v8::Persistent<v8::Object, v8::CopyablePersistentTraits<v8::Object> > | 13228 typedef v8::Persistent<v8::Object, v8::CopyablePersistentTraits<v8::Object> > |
13253 CopyableObject; | 13229 CopyableObject; |
13254 { | 13230 { |
13255 CopyableObject handle1; | 13231 CopyableObject handle1; |
13256 { | 13232 { |
13257 v8::HandleScope scope(isolate); | 13233 v8::HandleScope scope(isolate); |
13258 handle1.Reset(isolate, v8::Object::New(isolate)); | 13234 handle1.Reset(isolate, v8::Object::New()); |
13259 } | 13235 } |
13260 CHECK_EQ(initial_handles + 1, globals->global_handles_count()); | 13236 CHECK_EQ(initial_handles + 1, globals->global_handles_count()); |
13261 CopyableObject handle2; | 13237 CopyableObject handle2; |
13262 handle2 = handle1; | 13238 handle2 = handle1; |
13263 CHECK(handle1 == handle2); | 13239 CHECK(handle1 == handle2); |
13264 CHECK_EQ(initial_handles + 2, globals->global_handles_count()); | 13240 CHECK_EQ(initial_handles + 2, globals->global_handles_count()); |
13265 CopyableObject handle3(handle2); | 13241 CopyableObject handle3(handle2); |
13266 CHECK(handle1 == handle3); | 13242 CHECK(handle1 == handle3); |
13267 CHECK_EQ(initial_handles + 3, globals->global_handles_count()); | 13243 CHECK_EQ(initial_handles + 3, globals->global_handles_count()); |
13268 } | 13244 } |
(...skipping 12 matching lines...) Expand all Loading... |
13281 | 13257 |
13282 | 13258 |
13283 TEST(WeakCallbackApi) { | 13259 TEST(WeakCallbackApi) { |
13284 LocalContext context; | 13260 LocalContext context; |
13285 v8::Isolate* isolate = context->GetIsolate(); | 13261 v8::Isolate* isolate = context->GetIsolate(); |
13286 i::GlobalHandles* globals = | 13262 i::GlobalHandles* globals = |
13287 reinterpret_cast<i::Isolate*>(isolate)->global_handles(); | 13263 reinterpret_cast<i::Isolate*>(isolate)->global_handles(); |
13288 int initial_handles = globals->global_handles_count(); | 13264 int initial_handles = globals->global_handles_count(); |
13289 { | 13265 { |
13290 v8::HandleScope scope(isolate); | 13266 v8::HandleScope scope(isolate); |
13291 v8::Local<v8::Object> obj = v8::Object::New(isolate); | 13267 v8::Local<v8::Object> obj = v8::Object::New(); |
13292 obj->Set(v8_str("key"), v8::Integer::New(isolate, 231)); | 13268 obj->Set(v8_str("key"), v8::Integer::New(231, isolate)); |
13293 v8::Persistent<v8::Object>* handle = | 13269 v8::Persistent<v8::Object>* handle = |
13294 new v8::Persistent<v8::Object>(isolate, obj); | 13270 new v8::Persistent<v8::Object>(isolate, obj); |
13295 handle->SetWeak<v8::Object, v8::Persistent<v8::Object> >(handle, | 13271 handle->SetWeak<v8::Object, v8::Persistent<v8::Object> >(handle, |
13296 WeakApiCallback); | 13272 WeakApiCallback); |
13297 } | 13273 } |
13298 reinterpret_cast<i::Isolate*>(isolate)->heap()-> | 13274 reinterpret_cast<i::Isolate*>(isolate)->heap()-> |
13299 CollectAllGarbage(i::Heap::kNoGCFlags); | 13275 CollectAllGarbage(i::Heap::kNoGCFlags); |
13300 // Verify disposed. | 13276 // Verify disposed. |
13301 CHECK_EQ(initial_handles, globals->global_handles_count()); | 13277 CHECK_EQ(initial_handles, globals->global_handles_count()); |
13302 } | 13278 } |
(...skipping 10 matching lines...) Expand all Loading... |
13313 } | 13289 } |
13314 | 13290 |
13315 | 13291 |
13316 THREADED_TEST(NewPersistentHandleFromWeakCallback) { | 13292 THREADED_TEST(NewPersistentHandleFromWeakCallback) { |
13317 LocalContext context; | 13293 LocalContext context; |
13318 v8::Isolate* isolate = context->GetIsolate(); | 13294 v8::Isolate* isolate = context->GetIsolate(); |
13319 | 13295 |
13320 v8::Persistent<v8::Object> handle1, handle2; | 13296 v8::Persistent<v8::Object> handle1, handle2; |
13321 { | 13297 { |
13322 v8::HandleScope scope(isolate); | 13298 v8::HandleScope scope(isolate); |
13323 some_object.Reset(isolate, v8::Object::New(isolate)); | 13299 some_object.Reset(isolate, v8::Object::New()); |
13324 handle1.Reset(isolate, v8::Object::New(isolate)); | 13300 handle1.Reset(isolate, v8::Object::New()); |
13325 handle2.Reset(isolate, v8::Object::New(isolate)); | 13301 handle2.Reset(isolate, v8::Object::New()); |
13326 } | 13302 } |
13327 // Note: order is implementation dependent alas: currently | 13303 // Note: order is implementation dependent alas: currently |
13328 // global handle nodes are processed by PostGarbageCollectionProcessing | 13304 // global handle nodes are processed by PostGarbageCollectionProcessing |
13329 // in reverse allocation order, so if second allocated handle is deleted, | 13305 // in reverse allocation order, so if second allocated handle is deleted, |
13330 // weak callback of the first handle would be able to 'reallocate' it. | 13306 // weak callback of the first handle would be able to 'reallocate' it. |
13331 handle1.SetWeak(&handle1, NewPersistentHandleCallback); | 13307 handle1.SetWeak(&handle1, NewPersistentHandleCallback); |
13332 handle2.Reset(); | 13308 handle2.Reset(); |
13333 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 13309 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); |
13334 } | 13310 } |
13335 | 13311 |
13336 | 13312 |
13337 v8::Persistent<v8::Object> to_be_disposed; | 13313 v8::Persistent<v8::Object> to_be_disposed; |
13338 | 13314 |
13339 void DisposeAndForceGcCallback( | 13315 void DisposeAndForceGcCallback( |
13340 const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) { | 13316 const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) { |
13341 to_be_disposed.Reset(); | 13317 to_be_disposed.Reset(); |
13342 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 13318 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
13343 data.GetParameter()->Reset(); | 13319 data.GetParameter()->Reset(); |
13344 } | 13320 } |
13345 | 13321 |
13346 | 13322 |
13347 THREADED_TEST(DoNotUseDeletedNodesInSecondLevelGc) { | 13323 THREADED_TEST(DoNotUseDeletedNodesInSecondLevelGc) { |
13348 LocalContext context; | 13324 LocalContext context; |
13349 v8::Isolate* isolate = context->GetIsolate(); | 13325 v8::Isolate* isolate = context->GetIsolate(); |
13350 | 13326 |
13351 v8::Persistent<v8::Object> handle1, handle2; | 13327 v8::Persistent<v8::Object> handle1, handle2; |
13352 { | 13328 { |
13353 v8::HandleScope scope(isolate); | 13329 v8::HandleScope scope(isolate); |
13354 handle1.Reset(isolate, v8::Object::New(isolate)); | 13330 handle1.Reset(isolate, v8::Object::New()); |
13355 handle2.Reset(isolate, v8::Object::New(isolate)); | 13331 handle2.Reset(isolate, v8::Object::New()); |
13356 } | 13332 } |
13357 handle1.SetWeak(&handle1, DisposeAndForceGcCallback); | 13333 handle1.SetWeak(&handle1, DisposeAndForceGcCallback); |
13358 to_be_disposed.Reset(isolate, handle2); | 13334 to_be_disposed.Reset(isolate, handle2); |
13359 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 13335 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); |
13360 } | 13336 } |
13361 | 13337 |
13362 void DisposingCallback( | 13338 void DisposingCallback( |
13363 const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) { | 13339 const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) { |
13364 data.GetParameter()->Reset(); | 13340 data.GetParameter()->Reset(); |
13365 } | 13341 } |
13366 | 13342 |
13367 void HandleCreatingCallback( | 13343 void HandleCreatingCallback( |
13368 const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) { | 13344 const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) { |
13369 v8::HandleScope scope(data.GetIsolate()); | 13345 v8::HandleScope scope(data.GetIsolate()); |
13370 v8::Persistent<v8::Object>(data.GetIsolate(), | 13346 v8::Persistent<v8::Object>(data.GetIsolate(), v8::Object::New()); |
13371 v8::Object::New(data.GetIsolate())); | |
13372 data.GetParameter()->Reset(); | 13347 data.GetParameter()->Reset(); |
13373 } | 13348 } |
13374 | 13349 |
13375 | 13350 |
13376 THREADED_TEST(NoGlobalHandlesOrphaningDueToWeakCallback) { | 13351 THREADED_TEST(NoGlobalHandlesOrphaningDueToWeakCallback) { |
13377 LocalContext context; | 13352 LocalContext context; |
13378 v8::Isolate* isolate = context->GetIsolate(); | 13353 v8::Isolate* isolate = context->GetIsolate(); |
13379 | 13354 |
13380 v8::Persistent<v8::Object> handle1, handle2, handle3; | 13355 v8::Persistent<v8::Object> handle1, handle2, handle3; |
13381 { | 13356 { |
13382 v8::HandleScope scope(isolate); | 13357 v8::HandleScope scope(isolate); |
13383 handle3.Reset(isolate, v8::Object::New(isolate)); | 13358 handle3.Reset(isolate, v8::Object::New()); |
13384 handle2.Reset(isolate, v8::Object::New(isolate)); | 13359 handle2.Reset(isolate, v8::Object::New()); |
13385 handle1.Reset(isolate, v8::Object::New(isolate)); | 13360 handle1.Reset(isolate, v8::Object::New()); |
13386 } | 13361 } |
13387 handle2.SetWeak(&handle2, DisposingCallback); | 13362 handle2.SetWeak(&handle2, DisposingCallback); |
13388 handle3.SetWeak(&handle3, HandleCreatingCallback); | 13363 handle3.SetWeak(&handle3, HandleCreatingCallback); |
13389 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 13364 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); |
13390 } | 13365 } |
13391 | 13366 |
13392 | 13367 |
13393 THREADED_TEST(CheckForCrossContextObjectLiterals) { | 13368 THREADED_TEST(CheckForCrossContextObjectLiterals) { |
13394 v8::V8::Initialize(); | 13369 v8::V8::Initialize(); |
13395 | 13370 |
(...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14122 | 14097 |
14123 resource_name = "test1.js"; | 14098 resource_name = "test1.js"; |
14124 v8::ScriptOrigin origin1( | 14099 v8::ScriptOrigin origin1( |
14125 v8::String::NewFromUtf8(context->GetIsolate(), resource_name)); | 14100 v8::String::NewFromUtf8(context->GetIsolate(), resource_name)); |
14126 script = v8::Script::Compile(source, &origin1); | 14101 script = v8::Script::Compile(source, &origin1); |
14127 CheckTryCatchSourceInfo(script, resource_name, 0); | 14102 CheckTryCatchSourceInfo(script, resource_name, 0); |
14128 | 14103 |
14129 resource_name = "test2.js"; | 14104 resource_name = "test2.js"; |
14130 v8::ScriptOrigin origin2( | 14105 v8::ScriptOrigin origin2( |
14131 v8::String::NewFromUtf8(context->GetIsolate(), resource_name), | 14106 v8::String::NewFromUtf8(context->GetIsolate(), resource_name), |
14132 v8::Integer::New(context->GetIsolate(), 7)); | 14107 v8::Integer::New(7)); |
14133 script = v8::Script::Compile(source, &origin2); | 14108 script = v8::Script::Compile(source, &origin2); |
14134 CheckTryCatchSourceInfo(script, resource_name, 7); | 14109 CheckTryCatchSourceInfo(script, resource_name, 7); |
14135 } | 14110 } |
14136 | 14111 |
14137 | 14112 |
14138 THREADED_TEST(CompilationCache) { | 14113 THREADED_TEST(CompilationCache) { |
14139 LocalContext context; | 14114 LocalContext context; |
14140 v8::HandleScope scope(context->GetIsolate()); | 14115 v8::HandleScope scope(context->GetIsolate()); |
14141 v8::Handle<v8::String> source0 = | 14116 v8::Handle<v8::String> source0 = |
14142 v8::String::NewFromUtf8(context->GetIsolate(), "1234"); | 14117 v8::String::NewFromUtf8(context->GetIsolate(), "1234"); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14179 THREADED_TEST(DateAccess) { | 14154 THREADED_TEST(DateAccess) { |
14180 LocalContext context; | 14155 LocalContext context; |
14181 v8::HandleScope scope(context->GetIsolate()); | 14156 v8::HandleScope scope(context->GetIsolate()); |
14182 v8::Handle<v8::Value> date = | 14157 v8::Handle<v8::Value> date = |
14183 v8::Date::New(context->GetIsolate(), 1224744689038.0); | 14158 v8::Date::New(context->GetIsolate(), 1224744689038.0); |
14184 CHECK(date->IsDate()); | 14159 CHECK(date->IsDate()); |
14185 CHECK_EQ(1224744689038.0, date.As<v8::Date>()->ValueOf()); | 14160 CHECK_EQ(1224744689038.0, date.As<v8::Date>()->ValueOf()); |
14186 } | 14161 } |
14187 | 14162 |
14188 | 14163 |
14189 void CheckProperties(v8::Isolate* isolate, | 14164 void CheckProperties(v8::Handle<v8::Value> val, int elmc, const char* elmv[]) { |
14190 v8::Handle<v8::Value> val, | |
14191 int elmc, | |
14192 const char* elmv[]) { | |
14193 v8::Handle<v8::Object> obj = val.As<v8::Object>(); | 14165 v8::Handle<v8::Object> obj = val.As<v8::Object>(); |
14194 v8::Handle<v8::Array> props = obj->GetPropertyNames(); | 14166 v8::Handle<v8::Array> props = obj->GetPropertyNames(); |
14195 CHECK_EQ(elmc, props->Length()); | 14167 CHECK_EQ(elmc, props->Length()); |
14196 for (int i = 0; i < elmc; i++) { | 14168 for (int i = 0; i < elmc; i++) { |
14197 v8::String::Utf8Value elm(props->Get(v8::Integer::New(isolate, i))); | 14169 v8::String::Utf8Value elm(props->Get(v8::Integer::New(i))); |
14198 CHECK_EQ(elmv[i], *elm); | 14170 CHECK_EQ(elmv[i], *elm); |
14199 } | 14171 } |
14200 } | 14172 } |
14201 | 14173 |
14202 | 14174 |
14203 void CheckOwnProperties(v8::Isolate* isolate, | 14175 void CheckOwnProperties(v8::Handle<v8::Value> val, |
14204 v8::Handle<v8::Value> val, | |
14205 int elmc, | 14176 int elmc, |
14206 const char* elmv[]) { | 14177 const char* elmv[]) { |
14207 v8::Handle<v8::Object> obj = val.As<v8::Object>(); | 14178 v8::Handle<v8::Object> obj = val.As<v8::Object>(); |
14208 v8::Handle<v8::Array> props = obj->GetOwnPropertyNames(); | 14179 v8::Handle<v8::Array> props = obj->GetOwnPropertyNames(); |
14209 CHECK_EQ(elmc, props->Length()); | 14180 CHECK_EQ(elmc, props->Length()); |
14210 for (int i = 0; i < elmc; i++) { | 14181 for (int i = 0; i < elmc; i++) { |
14211 v8::String::Utf8Value elm(props->Get(v8::Integer::New(isolate, i))); | 14182 v8::String::Utf8Value elm(props->Get(v8::Integer::New(i))); |
14212 CHECK_EQ(elmv[i], *elm); | 14183 CHECK_EQ(elmv[i], *elm); |
14213 } | 14184 } |
14214 } | 14185 } |
14215 | 14186 |
14216 | 14187 |
14217 THREADED_TEST(PropertyEnumeration) { | 14188 THREADED_TEST(PropertyEnumeration) { |
14218 LocalContext context; | 14189 LocalContext context; |
14219 v8::Isolate* isolate = context->GetIsolate(); | 14190 v8::HandleScope scope(context->GetIsolate()); |
14220 v8::HandleScope scope(isolate); | |
14221 v8::Handle<v8::Value> obj = v8::Script::Compile(v8::String::NewFromUtf8( | 14191 v8::Handle<v8::Value> obj = v8::Script::Compile(v8::String::NewFromUtf8( |
14222 context->GetIsolate(), | 14192 context->GetIsolate(), |
14223 "var result = [];" | 14193 "var result = [];" |
14224 "result[0] = {};" | 14194 "result[0] = {};" |
14225 "result[1] = {a: 1, b: 2};" | 14195 "result[1] = {a: 1, b: 2};" |
14226 "result[2] = [1, 2, 3];" | 14196 "result[2] = [1, 2, 3];" |
14227 "var proto = {x: 1, y: 2, z: 3};" | 14197 "var proto = {x: 1, y: 2, z: 3};" |
14228 "var x = { __proto__: proto, w: 0, z: 1 };" | 14198 "var x = { __proto__: proto, w: 0, z: 1 };" |
14229 "result[3] = x;" | 14199 "result[3] = x;" |
14230 "result;"))->Run(); | 14200 "result;"))->Run(); |
14231 v8::Handle<v8::Array> elms = obj.As<v8::Array>(); | 14201 v8::Handle<v8::Array> elms = obj.As<v8::Array>(); |
14232 CHECK_EQ(4, elms->Length()); | 14202 CHECK_EQ(4, elms->Length()); |
14233 int elmc0 = 0; | 14203 int elmc0 = 0; |
14234 const char** elmv0 = NULL; | 14204 const char** elmv0 = NULL; |
14235 CheckProperties( | 14205 CheckProperties(elms->Get(v8::Integer::New(0)), elmc0, elmv0); |
14236 isolate, elms->Get(v8::Integer::New(isolate, 0)), elmc0, elmv0); | 14206 CheckOwnProperties(elms->Get(v8::Integer::New(0)), elmc0, elmv0); |
14237 CheckOwnProperties( | |
14238 isolate, elms->Get(v8::Integer::New(isolate, 0)), elmc0, elmv0); | |
14239 int elmc1 = 2; | 14207 int elmc1 = 2; |
14240 const char* elmv1[] = {"a", "b"}; | 14208 const char* elmv1[] = {"a", "b"}; |
14241 CheckProperties( | 14209 CheckProperties(elms->Get(v8::Integer::New(1)), elmc1, elmv1); |
14242 isolate, elms->Get(v8::Integer::New(isolate, 1)), elmc1, elmv1); | 14210 CheckOwnProperties(elms->Get(v8::Integer::New(1)), elmc1, elmv1); |
14243 CheckOwnProperties( | |
14244 isolate, elms->Get(v8::Integer::New(isolate, 1)), elmc1, elmv1); | |
14245 int elmc2 = 3; | 14211 int elmc2 = 3; |
14246 const char* elmv2[] = {"0", "1", "2"}; | 14212 const char* elmv2[] = {"0", "1", "2"}; |
14247 CheckProperties( | 14213 CheckProperties(elms->Get(v8::Integer::New(2)), elmc2, elmv2); |
14248 isolate, elms->Get(v8::Integer::New(isolate, 2)), elmc2, elmv2); | 14214 CheckOwnProperties(elms->Get(v8::Integer::New(2)), elmc2, elmv2); |
14249 CheckOwnProperties( | |
14250 isolate, elms->Get(v8::Integer::New(isolate, 2)), elmc2, elmv2); | |
14251 int elmc3 = 4; | 14215 int elmc3 = 4; |
14252 const char* elmv3[] = {"w", "z", "x", "y"}; | 14216 const char* elmv3[] = {"w", "z", "x", "y"}; |
14253 CheckProperties( | 14217 CheckProperties(elms->Get(v8::Integer::New(3)), elmc3, elmv3); |
14254 isolate, elms->Get(v8::Integer::New(isolate, 3)), elmc3, elmv3); | |
14255 int elmc4 = 2; | 14218 int elmc4 = 2; |
14256 const char* elmv4[] = {"w", "z"}; | 14219 const char* elmv4[] = {"w", "z"}; |
14257 CheckOwnProperties( | 14220 CheckOwnProperties(elms->Get(v8::Integer::New(3)), elmc4, elmv4); |
14258 isolate, elms->Get(v8::Integer::New(isolate, 3)), elmc4, elmv4); | |
14259 } | 14221 } |
14260 | 14222 |
14261 | 14223 |
14262 THREADED_TEST(PropertyEnumeration2) { | 14224 THREADED_TEST(PropertyEnumeration2) { |
14263 LocalContext context; | 14225 LocalContext context; |
14264 v8::Isolate* isolate = context->GetIsolate(); | 14226 v8::HandleScope scope(context->GetIsolate()); |
14265 v8::HandleScope scope(isolate); | |
14266 v8::Handle<v8::Value> obj = v8::Script::Compile(v8::String::NewFromUtf8( | 14227 v8::Handle<v8::Value> obj = v8::Script::Compile(v8::String::NewFromUtf8( |
14267 context->GetIsolate(), | 14228 context->GetIsolate(), |
14268 "var result = [];" | 14229 "var result = [];" |
14269 "result[0] = {};" | 14230 "result[0] = {};" |
14270 "result[1] = {a: 1, b: 2};" | 14231 "result[1] = {a: 1, b: 2};" |
14271 "result[2] = [1, 2, 3];" | 14232 "result[2] = [1, 2, 3];" |
14272 "var proto = {x: 1, y: 2, z: 3};" | 14233 "var proto = {x: 1, y: 2, z: 3};" |
14273 "var x = { __proto__: proto, w: 0, z: 1 };" | 14234 "var x = { __proto__: proto, w: 0, z: 1 };" |
14274 "result[3] = x;" | 14235 "result[3] = x;" |
14275 "result;"))->Run(); | 14236 "result;"))->Run(); |
14276 v8::Handle<v8::Array> elms = obj.As<v8::Array>(); | 14237 v8::Handle<v8::Array> elms = obj.As<v8::Array>(); |
14277 CHECK_EQ(4, elms->Length()); | 14238 CHECK_EQ(4, elms->Length()); |
14278 int elmc0 = 0; | 14239 int elmc0 = 0; |
14279 const char** elmv0 = NULL; | 14240 const char** elmv0 = NULL; |
14280 CheckProperties(isolate, | 14241 CheckProperties(elms->Get(v8::Integer::New(0)), elmc0, elmv0); |
14281 elms->Get(v8::Integer::New(isolate, 0)), elmc0, elmv0); | |
14282 | 14242 |
14283 v8::Handle<v8::Value> val = elms->Get(v8::Integer::New(isolate, 0)); | 14243 v8::Handle<v8::Value> val = elms->Get(v8::Integer::New(0)); |
14284 v8::Handle<v8::Array> props = val.As<v8::Object>()->GetPropertyNames(); | 14244 v8::Handle<v8::Array> props = val.As<v8::Object>()->GetPropertyNames(); |
14285 CHECK_EQ(0, props->Length()); | 14245 CHECK_EQ(0, props->Length()); |
14286 for (uint32_t i = 0; i < props->Length(); i++) { | 14246 for (uint32_t i = 0; i < props->Length(); i++) { |
14287 printf("p[%d]\n", i); | 14247 printf("p[%d]\n", i); |
14288 } | 14248 } |
14289 } | 14249 } |
14290 | 14250 |
14291 static bool NamedSetAccessBlocker(Local<v8::Object> obj, | 14251 static bool NamedSetAccessBlocker(Local<v8::Object> obj, |
14292 Local<Value> name, | 14252 Local<Value> name, |
14293 v8::AccessType type, | 14253 v8::AccessType type, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14347 // so that the constructor will force copying map. | 14307 // so that the constructor will force copying map. |
14348 // Cannot sprintf, gcc complains unsafety. | 14308 // Cannot sprintf, gcc complains unsafety. |
14349 char buf[4]; | 14309 char buf[4]; |
14350 for (char i = '0'; i <= '9' ; i++) { | 14310 for (char i = '0'; i <= '9' ; i++) { |
14351 buf[0] = i; | 14311 buf[0] = i; |
14352 for (char j = '0'; j <= '9'; j++) { | 14312 for (char j = '0'; j <= '9'; j++) { |
14353 buf[1] = j; | 14313 buf[1] = j; |
14354 for (char k = '0'; k <= '9'; k++) { | 14314 for (char k = '0'; k <= '9'; k++) { |
14355 buf[2] = k; | 14315 buf[2] = k; |
14356 buf[3] = 0; | 14316 buf[3] = 0; |
14357 templ->Set(v8_str(buf), v8::Number::New(context->GetIsolate(), k)); | 14317 templ->Set(v8_str(buf), v8::Number::New(k)); |
14358 } | 14318 } |
14359 } | 14319 } |
14360 } | 14320 } |
14361 | 14321 |
14362 Local<v8::Object> instance_1 = templ->NewInstance(); | 14322 Local<v8::Object> instance_1 = templ->NewInstance(); |
14363 context->Global()->Set(v8_str("obj_1"), instance_1); | 14323 context->Global()->Set(v8_str("obj_1"), instance_1); |
14364 | 14324 |
14365 Local<Value> value_1 = CompileRun("obj_1.a"); | 14325 Local<Value> value_1 = CompileRun("obj_1.a"); |
14366 CHECK(value_1->IsUndefined()); | 14326 CHECK(value_1->IsUndefined()); |
14367 | 14327 |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14778 Local<Value> value = CompileRun("var instance = new other.C(); instance.x"); | 14738 Local<Value> value = CompileRun("var instance = new other.C(); instance.x"); |
14779 CHECK(value->IsInt32()); | 14739 CHECK(value->IsInt32()); |
14780 CHECK_EQ(42, value->Int32Value()); | 14740 CHECK_EQ(42, value->Int32Value()); |
14781 context1->Exit(); | 14741 context1->Exit(); |
14782 } | 14742 } |
14783 | 14743 |
14784 | 14744 |
14785 // Verify that we can clone an object | 14745 // Verify that we can clone an object |
14786 TEST(ObjectClone) { | 14746 TEST(ObjectClone) { |
14787 LocalContext env; | 14747 LocalContext env; |
14788 v8::Isolate* isolate = env->GetIsolate(); | 14748 v8::HandleScope scope(env->GetIsolate()); |
14789 v8::HandleScope scope(isolate); | |
14790 | 14749 |
14791 const char* sample = | 14750 const char* sample = |
14792 "var rv = {};" \ | 14751 "var rv = {};" \ |
14793 "rv.alpha = 'hello';" \ | 14752 "rv.alpha = 'hello';" \ |
14794 "rv.beta = 123;" \ | 14753 "rv.beta = 123;" \ |
14795 "rv;"; | 14754 "rv;"; |
14796 | 14755 |
14797 // Create an object, verify basics. | 14756 // Create an object, verify basics. |
14798 Local<Value> val = CompileRun(sample); | 14757 Local<Value> val = CompileRun(sample); |
14799 CHECK(val->IsObject()); | 14758 CHECK(val->IsObject()); |
14800 Local<v8::Object> obj = val.As<v8::Object>(); | 14759 Local<v8::Object> obj = val.As<v8::Object>(); |
14801 obj->Set(v8_str("gamma"), v8_str("cloneme")); | 14760 obj->Set(v8_str("gamma"), v8_str("cloneme")); |
14802 | 14761 |
14803 CHECK_EQ(v8_str("hello"), obj->Get(v8_str("alpha"))); | 14762 CHECK_EQ(v8_str("hello"), obj->Get(v8_str("alpha"))); |
14804 CHECK_EQ(v8::Integer::New(isolate, 123), obj->Get(v8_str("beta"))); | 14763 CHECK_EQ(v8::Integer::New(123), obj->Get(v8_str("beta"))); |
14805 CHECK_EQ(v8_str("cloneme"), obj->Get(v8_str("gamma"))); | 14764 CHECK_EQ(v8_str("cloneme"), obj->Get(v8_str("gamma"))); |
14806 | 14765 |
14807 // Clone it. | 14766 // Clone it. |
14808 Local<v8::Object> clone = obj->Clone(); | 14767 Local<v8::Object> clone = obj->Clone(); |
14809 CHECK_EQ(v8_str("hello"), clone->Get(v8_str("alpha"))); | 14768 CHECK_EQ(v8_str("hello"), clone->Get(v8_str("alpha"))); |
14810 CHECK_EQ(v8::Integer::New(isolate, 123), clone->Get(v8_str("beta"))); | 14769 CHECK_EQ(v8::Integer::New(123), clone->Get(v8_str("beta"))); |
14811 CHECK_EQ(v8_str("cloneme"), clone->Get(v8_str("gamma"))); | 14770 CHECK_EQ(v8_str("cloneme"), clone->Get(v8_str("gamma"))); |
14812 | 14771 |
14813 // Set a property on the clone, verify each object. | 14772 // Set a property on the clone, verify each object. |
14814 clone->Set(v8_str("beta"), v8::Integer::New(isolate, 456)); | 14773 clone->Set(v8_str("beta"), v8::Integer::New(456)); |
14815 CHECK_EQ(v8::Integer::New(isolate, 123), obj->Get(v8_str("beta"))); | 14774 CHECK_EQ(v8::Integer::New(123), obj->Get(v8_str("beta"))); |
14816 CHECK_EQ(v8::Integer::New(isolate, 456), clone->Get(v8_str("beta"))); | 14775 CHECK_EQ(v8::Integer::New(456), clone->Get(v8_str("beta"))); |
14817 } | 14776 } |
14818 | 14777 |
14819 | 14778 |
14820 class AsciiVectorResource : public v8::String::ExternalAsciiStringResource { | 14779 class AsciiVectorResource : public v8::String::ExternalAsciiStringResource { |
14821 public: | 14780 public: |
14822 explicit AsciiVectorResource(i::Vector<const char> vector) | 14781 explicit AsciiVectorResource(i::Vector<const char> vector) |
14823 : data_(vector) {} | 14782 : data_(vector) {} |
14824 virtual ~AsciiVectorResource() {} | 14783 virtual ~AsciiVectorResource() {} |
14825 virtual size_t length() const { return data_.length(); } | 14784 virtual size_t length() const { return data_.length(); } |
14826 virtual const char* data() const { return data_.start(); } | 14785 virtual const char* data() const { return data_.start(); } |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15034 regexp_interruption_data.string.Reset(); | 14993 regexp_interruption_data.string.Reset(); |
15035 } | 14994 } |
15036 | 14995 |
15037 #endif // V8_INTERPRETED_REGEXP | 14996 #endif // V8_INTERPRETED_REGEXP |
15038 | 14997 |
15039 | 14998 |
15040 // Test that we cannot set a property on the global object if there | 14999 // Test that we cannot set a property on the global object if there |
15041 // is a read-only property in the prototype chain. | 15000 // is a read-only property in the prototype chain. |
15042 TEST(ReadOnlyPropertyInGlobalProto) { | 15001 TEST(ReadOnlyPropertyInGlobalProto) { |
15043 i::FLAG_es5_readonly = true; | 15002 i::FLAG_es5_readonly = true; |
15044 v8::Isolate* isolate = CcTest::isolate(); | 15003 v8::HandleScope scope(CcTest::isolate()); |
15045 v8::HandleScope scope(isolate); | |
15046 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); | 15004 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); |
15047 LocalContext context(0, templ); | 15005 LocalContext context(0, templ); |
15048 v8::Handle<v8::Object> global = context->Global(); | 15006 v8::Handle<v8::Object> global = context->Global(); |
15049 v8::Handle<v8::Object> global_proto = | 15007 v8::Handle<v8::Object> global_proto = |
15050 v8::Handle<v8::Object>::Cast(global->Get(v8_str("__proto__"))); | 15008 v8::Handle<v8::Object>::Cast(global->Get(v8_str("__proto__"))); |
15051 global_proto->Set(v8_str("x"), v8::Integer::New(isolate, 0), v8::ReadOnly); | 15009 global_proto->Set(v8_str("x"), v8::Integer::New(0), v8::ReadOnly); |
15052 global_proto->Set(v8_str("y"), v8::Integer::New(isolate, 0), v8::ReadOnly); | 15010 global_proto->Set(v8_str("y"), v8::Integer::New(0), v8::ReadOnly); |
15053 // Check without 'eval' or 'with'. | 15011 // Check without 'eval' or 'with'. |
15054 v8::Handle<v8::Value> res = | 15012 v8::Handle<v8::Value> res = |
15055 CompileRun("function f() { x = 42; return x; }; f()"); | 15013 CompileRun("function f() { x = 42; return x; }; f()"); |
15056 CHECK_EQ(v8::Integer::New(isolate, 0), res); | 15014 CHECK_EQ(v8::Integer::New(0), res); |
15057 // Check with 'eval'. | 15015 // Check with 'eval'. |
15058 res = CompileRun("function f() { eval('1'); y = 43; return y; }; f()"); | 15016 res = CompileRun("function f() { eval('1'); y = 43; return y; }; f()"); |
15059 CHECK_EQ(v8::Integer::New(isolate, 0), res); | 15017 CHECK_EQ(v8::Integer::New(0), res); |
15060 // Check with 'with'. | 15018 // Check with 'with'. |
15061 res = CompileRun("function f() { with (this) { y = 44 }; return y; }; f()"); | 15019 res = CompileRun("function f() { with (this) { y = 44 }; return y; }; f()"); |
15062 CHECK_EQ(v8::Integer::New(isolate, 0), res); | 15020 CHECK_EQ(v8::Integer::New(0), res); |
15063 } | 15021 } |
15064 | 15022 |
15065 static int force_set_set_count = 0; | 15023 static int force_set_set_count = 0; |
15066 static int force_set_get_count = 0; | 15024 static int force_set_get_count = 0; |
15067 bool pass_on_get = false; | 15025 bool pass_on_get = false; |
15068 | 15026 |
15069 static void ForceSetGetter(v8::Local<v8::String> name, | 15027 static void ForceSetGetter(v8::Local<v8::String> name, |
15070 const v8::PropertyCallbackInfo<v8::Value>& info) { | 15028 const v8::PropertyCallbackInfo<v8::Value>& info) { |
15071 force_set_get_count++; | 15029 force_set_get_count++; |
15072 if (pass_on_get) { | 15030 if (pass_on_get) { |
(...skipping 15 matching lines...) Expand all Loading... |
15088 force_set_set_count++; | 15046 force_set_set_count++; |
15089 info.GetReturnValue().SetUndefined(); | 15047 info.GetReturnValue().SetUndefined(); |
15090 } | 15048 } |
15091 | 15049 |
15092 | 15050 |
15093 TEST(ForceSet) { | 15051 TEST(ForceSet) { |
15094 force_set_get_count = 0; | 15052 force_set_get_count = 0; |
15095 force_set_set_count = 0; | 15053 force_set_set_count = 0; |
15096 pass_on_get = false; | 15054 pass_on_get = false; |
15097 | 15055 |
15098 v8::Isolate* isolate = CcTest::isolate(); | 15056 v8::HandleScope scope(CcTest::isolate()); |
15099 v8::HandleScope scope(isolate); | |
15100 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); | 15057 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); |
15101 v8::Handle<v8::String> access_property = | 15058 v8::Handle<v8::String> access_property = |
15102 v8::String::NewFromUtf8(isolate, "a"); | 15059 v8::String::NewFromUtf8(CcTest::isolate(), "a"); |
15103 templ->SetAccessor(access_property, ForceSetGetter, ForceSetSetter); | 15060 templ->SetAccessor(access_property, ForceSetGetter, ForceSetSetter); |
15104 LocalContext context(NULL, templ); | 15061 LocalContext context(NULL, templ); |
15105 v8::Handle<v8::Object> global = context->Global(); | 15062 v8::Handle<v8::Object> global = context->Global(); |
15106 | 15063 |
15107 // Ordinary properties | 15064 // Ordinary properties |
15108 v8::Handle<v8::String> simple_property = | 15065 v8::Handle<v8::String> simple_property = |
15109 v8::String::NewFromUtf8(isolate, "p"); | 15066 v8::String::NewFromUtf8(CcTest::isolate(), "p"); |
15110 global->Set(simple_property, v8::Int32::New(isolate, 4), v8::ReadOnly); | 15067 global->Set(simple_property, v8::Int32::New(4), v8::ReadOnly); |
15111 CHECK_EQ(4, global->Get(simple_property)->Int32Value()); | 15068 CHECK_EQ(4, global->Get(simple_property)->Int32Value()); |
15112 // This should fail because the property is read-only | 15069 // This should fail because the property is read-only |
15113 global->Set(simple_property, v8::Int32::New(isolate, 5)); | 15070 global->Set(simple_property, v8::Int32::New(5)); |
15114 CHECK_EQ(4, global->Get(simple_property)->Int32Value()); | 15071 CHECK_EQ(4, global->Get(simple_property)->Int32Value()); |
15115 // This should succeed even though the property is read-only | 15072 // This should succeed even though the property is read-only |
15116 global->ForceSet(simple_property, v8::Int32::New(isolate, 6)); | 15073 global->ForceSet(simple_property, v8::Int32::New(6)); |
15117 CHECK_EQ(6, global->Get(simple_property)->Int32Value()); | 15074 CHECK_EQ(6, global->Get(simple_property)->Int32Value()); |
15118 | 15075 |
15119 // Accessors | 15076 // Accessors |
15120 CHECK_EQ(0, force_set_set_count); | 15077 CHECK_EQ(0, force_set_set_count); |
15121 CHECK_EQ(0, force_set_get_count); | 15078 CHECK_EQ(0, force_set_get_count); |
15122 CHECK_EQ(3, global->Get(access_property)->Int32Value()); | 15079 CHECK_EQ(3, global->Get(access_property)->Int32Value()); |
15123 // CHECK_EQ the property shouldn't override it, just call the setter | 15080 // CHECK_EQ the property shouldn't override it, just call the setter |
15124 // which in this case does nothing. | 15081 // which in this case does nothing. |
15125 global->Set(access_property, v8::Int32::New(isolate, 7)); | 15082 global->Set(access_property, v8::Int32::New(7)); |
15126 CHECK_EQ(3, global->Get(access_property)->Int32Value()); | 15083 CHECK_EQ(3, global->Get(access_property)->Int32Value()); |
15127 CHECK_EQ(1, force_set_set_count); | 15084 CHECK_EQ(1, force_set_set_count); |
15128 CHECK_EQ(2, force_set_get_count); | 15085 CHECK_EQ(2, force_set_get_count); |
15129 // Forcing the property to be set should override the accessor without | 15086 // Forcing the property to be set should override the accessor without |
15130 // calling it | 15087 // calling it |
15131 global->ForceSet(access_property, v8::Int32::New(isolate, 8)); | 15088 global->ForceSet(access_property, v8::Int32::New(8)); |
15132 CHECK_EQ(8, global->Get(access_property)->Int32Value()); | 15089 CHECK_EQ(8, global->Get(access_property)->Int32Value()); |
15133 CHECK_EQ(1, force_set_set_count); | 15090 CHECK_EQ(1, force_set_set_count); |
15134 CHECK_EQ(2, force_set_get_count); | 15091 CHECK_EQ(2, force_set_get_count); |
15135 } | 15092 } |
15136 | 15093 |
15137 | 15094 |
15138 TEST(ForceSetWithInterceptor) { | 15095 TEST(ForceSetWithInterceptor) { |
15139 force_set_get_count = 0; | 15096 force_set_get_count = 0; |
15140 force_set_set_count = 0; | 15097 force_set_set_count = 0; |
15141 pass_on_get = false; | 15098 pass_on_get = false; |
15142 | 15099 |
15143 v8::Isolate* isolate = CcTest::isolate(); | 15100 v8::HandleScope scope(CcTest::isolate()); |
15144 v8::HandleScope scope(isolate); | |
15145 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); | 15101 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); |
15146 templ->SetNamedPropertyHandler(ForceSetGetter, ForceSetInterceptSetter); | 15102 templ->SetNamedPropertyHandler(ForceSetGetter, ForceSetInterceptSetter); |
15147 LocalContext context(NULL, templ); | 15103 LocalContext context(NULL, templ); |
15148 v8::Handle<v8::Object> global = context->Global(); | 15104 v8::Handle<v8::Object> global = context->Global(); |
15149 | 15105 |
15150 v8::Handle<v8::String> some_property = | 15106 v8::Handle<v8::String> some_property = |
15151 v8::String::NewFromUtf8(isolate, "a"); | 15107 v8::String::NewFromUtf8(CcTest::isolate(), "a"); |
15152 CHECK_EQ(0, force_set_set_count); | 15108 CHECK_EQ(0, force_set_set_count); |
15153 CHECK_EQ(0, force_set_get_count); | 15109 CHECK_EQ(0, force_set_get_count); |
15154 CHECK_EQ(3, global->Get(some_property)->Int32Value()); | 15110 CHECK_EQ(3, global->Get(some_property)->Int32Value()); |
15155 // Setting the property shouldn't override it, just call the setter | 15111 // Setting the property shouldn't override it, just call the setter |
15156 // which in this case does nothing. | 15112 // which in this case does nothing. |
15157 global->Set(some_property, v8::Int32::New(isolate, 7)); | 15113 global->Set(some_property, v8::Int32::New(7)); |
15158 CHECK_EQ(3, global->Get(some_property)->Int32Value()); | 15114 CHECK_EQ(3, global->Get(some_property)->Int32Value()); |
15159 CHECK_EQ(1, force_set_set_count); | 15115 CHECK_EQ(1, force_set_set_count); |
15160 CHECK_EQ(2, force_set_get_count); | 15116 CHECK_EQ(2, force_set_get_count); |
15161 // Getting the property when the interceptor returns an empty handle | 15117 // Getting the property when the interceptor returns an empty handle |
15162 // should yield undefined, since the property isn't present on the | 15118 // should yield undefined, since the property isn't present on the |
15163 // object itself yet. | 15119 // object itself yet. |
15164 pass_on_get = true; | 15120 pass_on_get = true; |
15165 CHECK(global->Get(some_property)->IsUndefined()); | 15121 CHECK(global->Get(some_property)->IsUndefined()); |
15166 CHECK_EQ(1, force_set_set_count); | 15122 CHECK_EQ(1, force_set_set_count); |
15167 CHECK_EQ(3, force_set_get_count); | 15123 CHECK_EQ(3, force_set_get_count); |
15168 // Forcing the property to be set should cause the value to be | 15124 // Forcing the property to be set should cause the value to be |
15169 // set locally without calling the interceptor. | 15125 // set locally without calling the interceptor. |
15170 global->ForceSet(some_property, v8::Int32::New(isolate, 8)); | 15126 global->ForceSet(some_property, v8::Int32::New(8)); |
15171 CHECK_EQ(8, global->Get(some_property)->Int32Value()); | 15127 CHECK_EQ(8, global->Get(some_property)->Int32Value()); |
15172 CHECK_EQ(1, force_set_set_count); | 15128 CHECK_EQ(1, force_set_set_count); |
15173 CHECK_EQ(4, force_set_get_count); | 15129 CHECK_EQ(4, force_set_get_count); |
15174 // Reenabling the interceptor should cause it to take precedence over | 15130 // Reenabling the interceptor should cause it to take precedence over |
15175 // the property | 15131 // the property |
15176 pass_on_get = false; | 15132 pass_on_get = false; |
15177 CHECK_EQ(3, global->Get(some_property)->Int32Value()); | 15133 CHECK_EQ(3, global->Get(some_property)->Int32Value()); |
15178 CHECK_EQ(1, force_set_set_count); | 15134 CHECK_EQ(1, force_set_set_count); |
15179 CHECK_EQ(5, force_set_get_count); | 15135 CHECK_EQ(5, force_set_get_count); |
15180 // The interceptor should also work for other properties | 15136 // The interceptor should also work for other properties |
15181 CHECK_EQ(3, global->Get(v8::String::NewFromUtf8(isolate, "b")) | 15137 CHECK_EQ(3, global->Get(v8::String::NewFromUtf8(CcTest::isolate(), "b")) |
15182 ->Int32Value()); | 15138 ->Int32Value()); |
15183 CHECK_EQ(1, force_set_set_count); | 15139 CHECK_EQ(1, force_set_set_count); |
15184 CHECK_EQ(6, force_set_get_count); | 15140 CHECK_EQ(6, force_set_get_count); |
15185 } | 15141 } |
15186 | 15142 |
15187 | 15143 |
15188 THREADED_TEST(ForceDelete) { | 15144 THREADED_TEST(ForceDelete) { |
15189 v8::Isolate* isolate = CcTest::isolate(); | 15145 v8::HandleScope scope(CcTest::isolate()); |
15190 v8::HandleScope scope(isolate); | |
15191 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); | 15146 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); |
15192 LocalContext context(NULL, templ); | 15147 LocalContext context(NULL, templ); |
15193 v8::Handle<v8::Object> global = context->Global(); | 15148 v8::Handle<v8::Object> global = context->Global(); |
15194 | 15149 |
15195 // Ordinary properties | 15150 // Ordinary properties |
15196 v8::Handle<v8::String> simple_property = | 15151 v8::Handle<v8::String> simple_property = |
15197 v8::String::NewFromUtf8(isolate, "p"); | 15152 v8::String::NewFromUtf8(CcTest::isolate(), "p"); |
15198 global->Set(simple_property, v8::Int32::New(isolate, 4), v8::DontDelete); | 15153 global->Set(simple_property, v8::Int32::New(4), v8::DontDelete); |
15199 CHECK_EQ(4, global->Get(simple_property)->Int32Value()); | 15154 CHECK_EQ(4, global->Get(simple_property)->Int32Value()); |
15200 // This should fail because the property is dont-delete. | 15155 // This should fail because the property is dont-delete. |
15201 CHECK(!global->Delete(simple_property)); | 15156 CHECK(!global->Delete(simple_property)); |
15202 CHECK_EQ(4, global->Get(simple_property)->Int32Value()); | 15157 CHECK_EQ(4, global->Get(simple_property)->Int32Value()); |
15203 // This should succeed even though the property is dont-delete. | 15158 // This should succeed even though the property is dont-delete. |
15204 CHECK(global->ForceDelete(simple_property)); | 15159 CHECK(global->ForceDelete(simple_property)); |
15205 CHECK(global->Get(simple_property)->IsUndefined()); | 15160 CHECK(global->Get(simple_property)->IsUndefined()); |
15206 } | 15161 } |
15207 | 15162 |
15208 | 15163 |
15209 static int force_delete_interceptor_count = 0; | 15164 static int force_delete_interceptor_count = 0; |
15210 static bool pass_on_delete = false; | 15165 static bool pass_on_delete = false; |
15211 | 15166 |
15212 | 15167 |
15213 static void ForceDeleteDeleter( | 15168 static void ForceDeleteDeleter( |
15214 v8::Local<v8::String> name, | 15169 v8::Local<v8::String> name, |
15215 const v8::PropertyCallbackInfo<v8::Boolean>& info) { | 15170 const v8::PropertyCallbackInfo<v8::Boolean>& info) { |
15216 force_delete_interceptor_count++; | 15171 force_delete_interceptor_count++; |
15217 if (pass_on_delete) return; | 15172 if (pass_on_delete) return; |
15218 info.GetReturnValue().Set(true); | 15173 info.GetReturnValue().Set(true); |
15219 } | 15174 } |
15220 | 15175 |
15221 | 15176 |
15222 THREADED_TEST(ForceDeleteWithInterceptor) { | 15177 THREADED_TEST(ForceDeleteWithInterceptor) { |
15223 force_delete_interceptor_count = 0; | 15178 force_delete_interceptor_count = 0; |
15224 pass_on_delete = false; | 15179 pass_on_delete = false; |
15225 | 15180 |
15226 v8::Isolate* isolate = CcTest::isolate(); | 15181 v8::HandleScope scope(CcTest::isolate()); |
15227 v8::HandleScope scope(isolate); | |
15228 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); | 15182 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); |
15229 templ->SetNamedPropertyHandler(0, 0, 0, ForceDeleteDeleter); | 15183 templ->SetNamedPropertyHandler(0, 0, 0, ForceDeleteDeleter); |
15230 LocalContext context(NULL, templ); | 15184 LocalContext context(NULL, templ); |
15231 v8::Handle<v8::Object> global = context->Global(); | 15185 v8::Handle<v8::Object> global = context->Global(); |
15232 | 15186 |
15233 v8::Handle<v8::String> some_property = | 15187 v8::Handle<v8::String> some_property = |
15234 v8::String::NewFromUtf8(isolate, "a"); | 15188 v8::String::NewFromUtf8(CcTest::isolate(), "a"); |
15235 global->Set(some_property, v8::Integer::New(isolate, 42), v8::DontDelete); | 15189 global->Set(some_property, v8::Integer::New(42), v8::DontDelete); |
15236 | 15190 |
15237 // Deleting a property should get intercepted and nothing should | 15191 // Deleting a property should get intercepted and nothing should |
15238 // happen. | 15192 // happen. |
15239 CHECK_EQ(0, force_delete_interceptor_count); | 15193 CHECK_EQ(0, force_delete_interceptor_count); |
15240 CHECK(global->Delete(some_property)); | 15194 CHECK(global->Delete(some_property)); |
15241 CHECK_EQ(1, force_delete_interceptor_count); | 15195 CHECK_EQ(1, force_delete_interceptor_count); |
15242 CHECK_EQ(42, global->Get(some_property)->Int32Value()); | 15196 CHECK_EQ(42, global->Get(some_property)->Int32Value()); |
15243 // Deleting the property when the interceptor returns an empty | 15197 // Deleting the property when the interceptor returns an empty |
15244 // handle should not delete the property since it is DontDelete. | 15198 // handle should not delete the property since it is DontDelete. |
15245 pass_on_delete = true; | 15199 pass_on_delete = true; |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15408 | 15362 |
15409 // Regression test for issue 398. | 15363 // Regression test for issue 398. |
15410 // If a function is added to an object, creating a constant function | 15364 // If a function is added to an object, creating a constant function |
15411 // field, and the result is cloned, replacing the constant function on the | 15365 // field, and the result is cloned, replacing the constant function on the |
15412 // original should not affect the clone. | 15366 // original should not affect the clone. |
15413 // See http://code.google.com/p/v8/issues/detail?id=398 | 15367 // See http://code.google.com/p/v8/issues/detail?id=398 |
15414 THREADED_TEST(ReplaceConstantFunction) { | 15368 THREADED_TEST(ReplaceConstantFunction) { |
15415 LocalContext context; | 15369 LocalContext context; |
15416 v8::Isolate* isolate = context->GetIsolate(); | 15370 v8::Isolate* isolate = context->GetIsolate(); |
15417 v8::HandleScope scope(isolate); | 15371 v8::HandleScope scope(isolate); |
15418 v8::Handle<v8::Object> obj = v8::Object::New(isolate); | 15372 v8::Handle<v8::Object> obj = v8::Object::New(); |
15419 v8::Handle<v8::FunctionTemplate> func_templ = | 15373 v8::Handle<v8::FunctionTemplate> func_templ = |
15420 v8::FunctionTemplate::New(isolate); | 15374 v8::FunctionTemplate::New(isolate); |
15421 v8::Handle<v8::String> foo_string = | 15375 v8::Handle<v8::String> foo_string = |
15422 v8::String::NewFromUtf8(isolate, "foo"); | 15376 v8::String::NewFromUtf8(isolate, "foo"); |
15423 obj->Set(foo_string, func_templ->GetFunction()); | 15377 obj->Set(foo_string, func_templ->GetFunction()); |
15424 v8::Handle<v8::Object> obj_clone = obj->Clone(); | 15378 v8::Handle<v8::Object> obj_clone = obj->Clone(); |
15425 obj_clone->Set(foo_string, | 15379 obj_clone->Set(foo_string, |
15426 v8::String::NewFromUtf8(isolate, "Hello")); | 15380 v8::String::NewFromUtf8(isolate, "Hello")); |
15427 CHECK(!obj->Get(foo_string)->IsUndefined()); | 15381 CHECK(!obj->Get(foo_string)->IsUndefined()); |
15428 } | 15382 } |
(...skipping 25 matching lines...) Expand all Loading... |
15454 for (int i = 0; i < kElementCount; i++) { | 15408 for (int i = 0; i < kElementCount; i++) { |
15455 pixels->set(i, i % 256); | 15409 pixels->set(i, i % 256); |
15456 } | 15410 } |
15457 // Force GC to trigger verification. | 15411 // Force GC to trigger verification. |
15458 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 15412 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
15459 for (int i = 0; i < kElementCount; i++) { | 15413 for (int i = 0; i < kElementCount; i++) { |
15460 CHECK_EQ(i % 256, pixels->get_scalar(i)); | 15414 CHECK_EQ(i % 256, pixels->get_scalar(i)); |
15461 CHECK_EQ(i % 256, pixel_data[i]); | 15415 CHECK_EQ(i % 256, pixel_data[i]); |
15462 } | 15416 } |
15463 | 15417 |
15464 v8::Handle<v8::Object> obj = v8::Object::New(context->GetIsolate()); | 15418 v8::Handle<v8::Object> obj = v8::Object::New(); |
15465 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); | 15419 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); |
15466 // Set the elements to be the pixels. | 15420 // Set the elements to be the pixels. |
15467 // jsobj->set_elements(*pixels); | 15421 // jsobj->set_elements(*pixels); |
15468 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount); | 15422 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount); |
15469 CheckElementValue(isolate, 1, jsobj, 1); | 15423 CheckElementValue(isolate, 1, jsobj, 1); |
15470 obj->Set(v8_str("field"), v8::Int32::New(CcTest::isolate(), 1503)); | 15424 obj->Set(v8_str("field"), v8::Int32::New(1503)); |
15471 context->Global()->Set(v8_str("pixels"), obj); | 15425 context->Global()->Set(v8_str("pixels"), obj); |
15472 v8::Handle<v8::Value> result = CompileRun("pixels.field"); | 15426 v8::Handle<v8::Value> result = CompileRun("pixels.field"); |
15473 CHECK_EQ(1503, result->Int32Value()); | 15427 CHECK_EQ(1503, result->Int32Value()); |
15474 result = CompileRun("pixels[1]"); | 15428 result = CompileRun("pixels[1]"); |
15475 CHECK_EQ(1, result->Int32Value()); | 15429 CHECK_EQ(1, result->Int32Value()); |
15476 | 15430 |
15477 result = CompileRun("var sum = 0;" | 15431 result = CompileRun("var sum = 0;" |
15478 "for (var i = 0; i < 8; i++) {" | 15432 "for (var i = 0; i < 8; i++) {" |
15479 " sum += pixels[i] = pixels[i] = -i;" | 15433 " sum += pixels[i] = pixels[i] = -i;" |
15480 "}" | 15434 "}" |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15819 | 15773 |
15820 free(pixel_data); | 15774 free(pixel_data); |
15821 } | 15775 } |
15822 | 15776 |
15823 | 15777 |
15824 THREADED_TEST(PixelArrayInfo) { | 15778 THREADED_TEST(PixelArrayInfo) { |
15825 LocalContext context; | 15779 LocalContext context; |
15826 v8::HandleScope scope(context->GetIsolate()); | 15780 v8::HandleScope scope(context->GetIsolate()); |
15827 for (int size = 0; size < 100; size += 10) { | 15781 for (int size = 0; size < 100; size += 10) { |
15828 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(size)); | 15782 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(size)); |
15829 v8::Handle<v8::Object> obj = v8::Object::New(context->GetIsolate()); | 15783 v8::Handle<v8::Object> obj = v8::Object::New(); |
15830 obj->SetIndexedPropertiesToPixelData(pixel_data, size); | 15784 obj->SetIndexedPropertiesToPixelData(pixel_data, size); |
15831 CHECK(obj->HasIndexedPropertiesInPixelData()); | 15785 CHECK(obj->HasIndexedPropertiesInPixelData()); |
15832 CHECK_EQ(pixel_data, obj->GetIndexedPropertiesPixelData()); | 15786 CHECK_EQ(pixel_data, obj->GetIndexedPropertiesPixelData()); |
15833 CHECK_EQ(size, obj->GetIndexedPropertiesPixelDataLength()); | 15787 CHECK_EQ(size, obj->GetIndexedPropertiesPixelDataLength()); |
15834 free(pixel_data); | 15788 free(pixel_data); |
15835 } | 15789 } |
15836 } | 15790 } |
15837 | 15791 |
15838 | 15792 |
15839 static void NotHandledIndexedPropertyGetter( | 15793 static void NotHandledIndexedPropertyGetter( |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15915 | 15869 |
15916 template <class ExternalArrayClass, class ElementType> | 15870 template <class ExternalArrayClass, class ElementType> |
15917 static void ObjectWithExternalArrayTestHelper( | 15871 static void ObjectWithExternalArrayTestHelper( |
15918 Handle<Context> context, | 15872 Handle<Context> context, |
15919 v8::Handle<Object> obj, | 15873 v8::Handle<Object> obj, |
15920 int element_count, | 15874 int element_count, |
15921 v8::ExternalArrayType array_type, | 15875 v8::ExternalArrayType array_type, |
15922 int64_t low, int64_t high) { | 15876 int64_t low, int64_t high) { |
15923 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); | 15877 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); |
15924 i::Isolate* isolate = jsobj->GetIsolate(); | 15878 i::Isolate* isolate = jsobj->GetIsolate(); |
15925 obj->Set(v8_str("field"), | 15879 obj->Set(v8_str("field"), v8::Int32::New(1503)); |
15926 v8::Int32::New(reinterpret_cast<v8::Isolate*>(isolate), 1503)); | |
15927 context->Global()->Set(v8_str("ext_array"), obj); | 15880 context->Global()->Set(v8_str("ext_array"), obj); |
15928 v8::Handle<v8::Value> result = CompileRun("ext_array.field"); | 15881 v8::Handle<v8::Value> result = CompileRun("ext_array.field"); |
15929 CHECK_EQ(1503, result->Int32Value()); | 15882 CHECK_EQ(1503, result->Int32Value()); |
15930 result = CompileRun("ext_array[1]"); | 15883 result = CompileRun("ext_array[1]"); |
15931 CHECK_EQ(1, result->Int32Value()); | 15884 CHECK_EQ(1, result->Int32Value()); |
15932 | 15885 |
15933 // Check pass through of assigned smis | 15886 // Check pass through of assigned smis |
15934 result = CompileRun("var sum = 0;" | 15887 result = CompileRun("var sum = 0;" |
15935 "for (var i = 0; i < 8; i++) {" | 15888 "for (var i = 0; i < 8; i++) {" |
15936 " sum += ext_array[i] = ext_array[i] = -i;" | 15889 " sum += ext_array[i] = ext_array[i] = -i;" |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16236 array->set(i, static_cast<ElementType>(i)); | 16189 array->set(i, static_cast<ElementType>(i)); |
16237 } | 16190 } |
16238 // Force GC to trigger verification. | 16191 // Force GC to trigger verification. |
16239 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 16192 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
16240 for (int i = 0; i < kElementCount; i++) { | 16193 for (int i = 0; i < kElementCount; i++) { |
16241 CHECK_EQ(static_cast<int64_t>(i), | 16194 CHECK_EQ(static_cast<int64_t>(i), |
16242 static_cast<int64_t>(array->get_scalar(i))); | 16195 static_cast<int64_t>(array->get_scalar(i))); |
16243 CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(array_data[i])); | 16196 CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(array_data[i])); |
16244 } | 16197 } |
16245 | 16198 |
16246 v8::Handle<v8::Object> obj = v8::Object::New(context->GetIsolate()); | 16199 v8::Handle<v8::Object> obj = v8::Object::New(); |
16247 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); | 16200 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); |
16248 // Set the elements to be the external array. | 16201 // Set the elements to be the external array. |
16249 obj->SetIndexedPropertiesToExternalArrayData(array_data, | 16202 obj->SetIndexedPropertiesToExternalArrayData(array_data, |
16250 array_type, | 16203 array_type, |
16251 kElementCount); | 16204 kElementCount); |
16252 CHECK_EQ(1, | 16205 CHECK_EQ(1, |
16253 static_cast<int>( | 16206 static_cast<int>( |
16254 jsobj->GetElement(isolate, 1)->ToObjectChecked()->Number())); | 16207 jsobj->GetElement(isolate, 1)->ToObjectChecked()->Number())); |
16255 | 16208 |
16256 ObjectWithExternalArrayTestHelper<ExternalArrayClass, ElementType>( | 16209 ObjectWithExternalArrayTestHelper<ExternalArrayClass, ElementType>( |
16257 context.local(), obj, kElementCount, array_type, low, high); | 16210 context.local(), obj, kElementCount, array_type, low, high); |
16258 | 16211 |
16259 v8::Handle<v8::Value> result; | 16212 v8::Handle<v8::Value> result; |
16260 | 16213 |
16261 // Test more complex manipulations which cause eax to contain values | 16214 // Test more complex manipulations which cause eax to contain values |
16262 // that won't be completely overwritten by loads from the arrays. | 16215 // that won't be completely overwritten by loads from the arrays. |
16263 // This catches bugs in the instructions used for the KeyedLoadIC | 16216 // This catches bugs in the instructions used for the KeyedLoadIC |
16264 // for byte and word types. | 16217 // for byte and word types. |
16265 { | 16218 { |
16266 const int kXSize = 300; | 16219 const int kXSize = 300; |
16267 const int kYSize = 300; | 16220 const int kYSize = 300; |
16268 const int kLargeElementCount = kXSize * kYSize * 4; | 16221 const int kLargeElementCount = kXSize * kYSize * 4; |
16269 ElementType* large_array_data = | 16222 ElementType* large_array_data = |
16270 static_cast<ElementType*>(malloc(kLargeElementCount * element_size)); | 16223 static_cast<ElementType*>(malloc(kLargeElementCount * element_size)); |
16271 v8::Handle<v8::Object> large_obj = v8::Object::New(context->GetIsolate()); | 16224 v8::Handle<v8::Object> large_obj = v8::Object::New(); |
16272 // Set the elements to be the external array. | 16225 // Set the elements to be the external array. |
16273 large_obj->SetIndexedPropertiesToExternalArrayData(large_array_data, | 16226 large_obj->SetIndexedPropertiesToExternalArrayData(large_array_data, |
16274 array_type, | 16227 array_type, |
16275 kLargeElementCount); | 16228 kLargeElementCount); |
16276 context->Global()->Set(v8_str("large_array"), large_obj); | 16229 context->Global()->Set(v8_str("large_array"), large_obj); |
16277 // Initialize contents of a few rows. | 16230 // Initialize contents of a few rows. |
16278 for (int x = 0; x < 300; x++) { | 16231 for (int x = 0; x < 300; x++) { |
16279 int row = 0; | 16232 int row = 0; |
16280 int offset = row * 300 * 4; | 16233 int offset = row * 300 * 4; |
16281 large_array_data[offset + 4 * x + 0] = (ElementType) 127; | 16234 large_array_data[offset + 4 * x + 0] = (ElementType) 127; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16334 | 16287 |
16335 // The "" property descriptor is overloaded to store information about | 16288 // The "" property descriptor is overloaded to store information about |
16336 // the external array. Ensure that setting and accessing the "" property | 16289 // the external array. Ensure that setting and accessing the "" property |
16337 // works (it should overwrite the information cached about the external | 16290 // works (it should overwrite the information cached about the external |
16338 // array in the DescriptorArray) in various situations. | 16291 // array in the DescriptorArray) in various situations. |
16339 result = CompileRun("ext_array[''] = 23; ext_array['']"); | 16292 result = CompileRun("ext_array[''] = 23; ext_array['']"); |
16340 CHECK_EQ(23, result->Int32Value()); | 16293 CHECK_EQ(23, result->Int32Value()); |
16341 | 16294 |
16342 // Property "" set after the external array is associated with the object. | 16295 // Property "" set after the external array is associated with the object. |
16343 { | 16296 { |
16344 v8::Handle<v8::Object> obj2 = v8::Object::New(context->GetIsolate()); | 16297 v8::Handle<v8::Object> obj2 = v8::Object::New(); |
16345 obj2->Set(v8_str("ee_test_field"), | 16298 obj2->Set(v8_str("ee_test_field"), v8::Int32::New(256)); |
16346 v8::Int32::New(context->GetIsolate(), 256)); | 16299 obj2->Set(v8_str(""), v8::Int32::New(1503)); |
16347 obj2->Set(v8_str(""), v8::Int32::New(context->GetIsolate(), 1503)); | |
16348 // Set the elements to be the external array. | 16300 // Set the elements to be the external array. |
16349 obj2->SetIndexedPropertiesToExternalArrayData(array_data, | 16301 obj2->SetIndexedPropertiesToExternalArrayData(array_data, |
16350 array_type, | 16302 array_type, |
16351 kElementCount); | 16303 kElementCount); |
16352 context->Global()->Set(v8_str("ext_array"), obj2); | 16304 context->Global()->Set(v8_str("ext_array"), obj2); |
16353 result = CompileRun("ext_array['']"); | 16305 result = CompileRun("ext_array['']"); |
16354 CHECK_EQ(1503, result->Int32Value()); | 16306 CHECK_EQ(1503, result->Int32Value()); |
16355 } | 16307 } |
16356 | 16308 |
16357 // Property "" set after the external array is associated with the object. | 16309 // Property "" set after the external array is associated with the object. |
16358 { | 16310 { |
16359 v8::Handle<v8::Object> obj2 = v8::Object::New(context->GetIsolate()); | 16311 v8::Handle<v8::Object> obj2 = v8::Object::New(); |
16360 obj2->Set(v8_str("ee_test_field_2"), | 16312 obj2->Set(v8_str("ee_test_field_2"), v8::Int32::New(256)); |
16361 v8::Int32::New(context->GetIsolate(), 256)); | |
16362 // Set the elements to be the external array. | 16313 // Set the elements to be the external array. |
16363 obj2->SetIndexedPropertiesToExternalArrayData(array_data, | 16314 obj2->SetIndexedPropertiesToExternalArrayData(array_data, |
16364 array_type, | 16315 array_type, |
16365 kElementCount); | 16316 kElementCount); |
16366 obj2->Set(v8_str(""), v8::Int32::New(context->GetIsolate(), 1503)); | 16317 obj2->Set(v8_str(""), v8::Int32::New(1503)); |
16367 context->Global()->Set(v8_str("ext_array"), obj2); | 16318 context->Global()->Set(v8_str("ext_array"), obj2); |
16368 result = CompileRun("ext_array['']"); | 16319 result = CompileRun("ext_array['']"); |
16369 CHECK_EQ(1503, result->Int32Value()); | 16320 CHECK_EQ(1503, result->Int32Value()); |
16370 } | 16321 } |
16371 | 16322 |
16372 // Should reuse the map from previous test. | 16323 // Should reuse the map from previous test. |
16373 { | 16324 { |
16374 v8::Handle<v8::Object> obj2 = v8::Object::New(context->GetIsolate()); | 16325 v8::Handle<v8::Object> obj2 = v8::Object::New(); |
16375 obj2->Set(v8_str("ee_test_field_2"), | 16326 obj2->Set(v8_str("ee_test_field_2"), v8::Int32::New(256)); |
16376 v8::Int32::New(context->GetIsolate(), 256)); | |
16377 // Set the elements to be the external array. Should re-use the map | 16327 // Set the elements to be the external array. Should re-use the map |
16378 // from previous test. | 16328 // from previous test. |
16379 obj2->SetIndexedPropertiesToExternalArrayData(array_data, | 16329 obj2->SetIndexedPropertiesToExternalArrayData(array_data, |
16380 array_type, | 16330 array_type, |
16381 kElementCount); | 16331 kElementCount); |
16382 context->Global()->Set(v8_str("ext_array"), obj2); | 16332 context->Global()->Set(v8_str("ext_array"), obj2); |
16383 result = CompileRun("ext_array['']"); | 16333 result = CompileRun("ext_array['']"); |
16384 } | 16334 } |
16385 | 16335 |
16386 // Property "" is a constant function that shouldn't not be interfered with | 16336 // Property "" is a constant function that shouldn't not be interfered with |
16387 // when an external array is set. | 16337 // when an external array is set. |
16388 { | 16338 { |
16389 v8::Handle<v8::Object> obj2 = v8::Object::New(context->GetIsolate()); | 16339 v8::Handle<v8::Object> obj2 = v8::Object::New(); |
16390 // Start | 16340 // Start |
16391 obj2->Set(v8_str("ee_test_field3"), | 16341 obj2->Set(v8_str("ee_test_field3"), v8::Int32::New(256)); |
16392 v8::Int32::New(context->GetIsolate(), 256)); | |
16393 | 16342 |
16394 // Add a constant function to an object. | 16343 // Add a constant function to an object. |
16395 context->Global()->Set(v8_str("ext_array"), obj2); | 16344 context->Global()->Set(v8_str("ext_array"), obj2); |
16396 result = CompileRun("ext_array[''] = function() {return 1503;};" | 16345 result = CompileRun("ext_array[''] = function() {return 1503;};" |
16397 "ext_array['']();"); | 16346 "ext_array['']();"); |
16398 | 16347 |
16399 // Add an external array transition to the same map that | 16348 // Add an external array transition to the same map that |
16400 // has the constant transition. | 16349 // has the constant transition. |
16401 v8::Handle<v8::Object> obj3 = v8::Object::New(context->GetIsolate()); | 16350 v8::Handle<v8::Object> obj3 = v8::Object::New(); |
16402 obj3->Set(v8_str("ee_test_field3"), | 16351 obj3->Set(v8_str("ee_test_field3"), v8::Int32::New(256)); |
16403 v8::Int32::New(context->GetIsolate(), 256)); | |
16404 obj3->SetIndexedPropertiesToExternalArrayData(array_data, | 16352 obj3->SetIndexedPropertiesToExternalArrayData(array_data, |
16405 array_type, | 16353 array_type, |
16406 kElementCount); | 16354 kElementCount); |
16407 context->Global()->Set(v8_str("ext_array"), obj3); | 16355 context->Global()->Set(v8_str("ext_array"), obj3); |
16408 } | 16356 } |
16409 | 16357 |
16410 // If a external array transition is in the map, it should get clobbered | 16358 // If a external array transition is in the map, it should get clobbered |
16411 // by a constant function. | 16359 // by a constant function. |
16412 { | 16360 { |
16413 // Add an external array transition. | 16361 // Add an external array transition. |
16414 v8::Handle<v8::Object> obj3 = v8::Object::New(context->GetIsolate()); | 16362 v8::Handle<v8::Object> obj3 = v8::Object::New(); |
16415 obj3->Set(v8_str("ee_test_field4"), | 16363 obj3->Set(v8_str("ee_test_field4"), v8::Int32::New(256)); |
16416 v8::Int32::New(context->GetIsolate(), 256)); | |
16417 obj3->SetIndexedPropertiesToExternalArrayData(array_data, | 16364 obj3->SetIndexedPropertiesToExternalArrayData(array_data, |
16418 array_type, | 16365 array_type, |
16419 kElementCount); | 16366 kElementCount); |
16420 | 16367 |
16421 // Add a constant function to the same map that just got an external array | 16368 // Add a constant function to the same map that just got an external array |
16422 // transition. | 16369 // transition. |
16423 v8::Handle<v8::Object> obj2 = v8::Object::New(context->GetIsolate()); | 16370 v8::Handle<v8::Object> obj2 = v8::Object::New(); |
16424 obj2->Set(v8_str("ee_test_field4"), | 16371 obj2->Set(v8_str("ee_test_field4"), v8::Int32::New(256)); |
16425 v8::Int32::New(context->GetIsolate(), 256)); | |
16426 context->Global()->Set(v8_str("ext_array"), obj2); | 16372 context->Global()->Set(v8_str("ext_array"), obj2); |
16427 result = CompileRun("ext_array[''] = function() {return 1503;};" | 16373 result = CompileRun("ext_array[''] = function() {return 1503;};" |
16428 "ext_array['']();"); | 16374 "ext_array['']();"); |
16429 } | 16375 } |
16430 | 16376 |
16431 free(array_data); | 16377 free(array_data); |
16432 } | 16378 } |
16433 | 16379 |
16434 | 16380 |
16435 THREADED_TEST(ExternalByteArray) { | 16381 THREADED_TEST(ExternalByteArray) { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16514 TestExternalFloatArray(); | 16460 TestExternalFloatArray(); |
16515 } | 16461 } |
16516 | 16462 |
16517 | 16463 |
16518 void ExternalArrayInfoTestHelper(v8::ExternalArrayType array_type) { | 16464 void ExternalArrayInfoTestHelper(v8::ExternalArrayType array_type) { |
16519 LocalContext context; | 16465 LocalContext context; |
16520 v8::HandleScope scope(context->GetIsolate()); | 16466 v8::HandleScope scope(context->GetIsolate()); |
16521 for (int size = 0; size < 100; size += 10) { | 16467 for (int size = 0; size < 100; size += 10) { |
16522 int element_size = ExternalArrayElementSize(array_type); | 16468 int element_size = ExternalArrayElementSize(array_type); |
16523 void* external_data = malloc(size * element_size); | 16469 void* external_data = malloc(size * element_size); |
16524 v8::Handle<v8::Object> obj = v8::Object::New(context->GetIsolate()); | 16470 v8::Handle<v8::Object> obj = v8::Object::New(); |
16525 obj->SetIndexedPropertiesToExternalArrayData( | 16471 obj->SetIndexedPropertiesToExternalArrayData( |
16526 external_data, array_type, size); | 16472 external_data, array_type, size); |
16527 CHECK(obj->HasIndexedPropertiesInExternalArrayData()); | 16473 CHECK(obj->HasIndexedPropertiesInExternalArrayData()); |
16528 CHECK_EQ(external_data, obj->GetIndexedPropertiesExternalArrayData()); | 16474 CHECK_EQ(external_data, obj->GetIndexedPropertiesExternalArrayData()); |
16529 CHECK_EQ(array_type, obj->GetIndexedPropertiesExternalArrayDataType()); | 16475 CHECK_EQ(array_type, obj->GetIndexedPropertiesExternalArrayDataType()); |
16530 CHECK_EQ(size, obj->GetIndexedPropertiesExternalArrayDataLength()); | 16476 CHECK_EQ(size, obj->GetIndexedPropertiesExternalArrayDataLength()); |
16531 free(external_data); | 16477 free(external_data); |
16532 } | 16478 } |
16533 } | 16479 } |
16534 | 16480 |
16535 | 16481 |
16536 THREADED_TEST(ExternalArrayInfo) { | 16482 THREADED_TEST(ExternalArrayInfo) { |
16537 ExternalArrayInfoTestHelper(v8::kExternalByteArray); | 16483 ExternalArrayInfoTestHelper(v8::kExternalByteArray); |
16538 ExternalArrayInfoTestHelper(v8::kExternalUnsignedByteArray); | 16484 ExternalArrayInfoTestHelper(v8::kExternalUnsignedByteArray); |
16539 ExternalArrayInfoTestHelper(v8::kExternalShortArray); | 16485 ExternalArrayInfoTestHelper(v8::kExternalShortArray); |
16540 ExternalArrayInfoTestHelper(v8::kExternalUnsignedShortArray); | 16486 ExternalArrayInfoTestHelper(v8::kExternalUnsignedShortArray); |
16541 ExternalArrayInfoTestHelper(v8::kExternalIntArray); | 16487 ExternalArrayInfoTestHelper(v8::kExternalIntArray); |
16542 ExternalArrayInfoTestHelper(v8::kExternalUnsignedIntArray); | 16488 ExternalArrayInfoTestHelper(v8::kExternalUnsignedIntArray); |
16543 ExternalArrayInfoTestHelper(v8::kExternalFloatArray); | 16489 ExternalArrayInfoTestHelper(v8::kExternalFloatArray); |
16544 ExternalArrayInfoTestHelper(v8::kExternalDoubleArray); | 16490 ExternalArrayInfoTestHelper(v8::kExternalDoubleArray); |
16545 ExternalArrayInfoTestHelper(v8::kExternalPixelArray); | 16491 ExternalArrayInfoTestHelper(v8::kExternalPixelArray); |
16546 } | 16492 } |
16547 | 16493 |
16548 | 16494 |
16549 void ExtArrayLimitsHelper(v8::Isolate* isolate, | 16495 void ExternalArrayLimitTestHelper(v8::ExternalArrayType array_type, int size) { |
16550 v8::ExternalArrayType array_type, | 16496 v8::Handle<v8::Object> obj = v8::Object::New(); |
16551 int size) { | |
16552 v8::Handle<v8::Object> obj = v8::Object::New(isolate); | |
16553 v8::V8::SetFatalErrorHandler(StoringErrorCallback); | 16497 v8::V8::SetFatalErrorHandler(StoringErrorCallback); |
16554 last_location = last_message = NULL; | 16498 last_location = last_message = NULL; |
16555 obj->SetIndexedPropertiesToExternalArrayData(NULL, array_type, size); | 16499 obj->SetIndexedPropertiesToExternalArrayData(NULL, array_type, size); |
16556 CHECK(!obj->HasIndexedPropertiesInExternalArrayData()); | 16500 CHECK(!obj->HasIndexedPropertiesInExternalArrayData()); |
16557 CHECK_NE(NULL, last_location); | 16501 CHECK_NE(NULL, last_location); |
16558 CHECK_NE(NULL, last_message); | 16502 CHECK_NE(NULL, last_message); |
16559 } | 16503 } |
16560 | 16504 |
16561 | 16505 |
16562 TEST(ExternalArrayLimits) { | 16506 TEST(ExternalArrayLimits) { |
16563 LocalContext context; | 16507 LocalContext context; |
16564 v8::Isolate* isolate = context->GetIsolate(); | 16508 v8::HandleScope scope(context->GetIsolate()); |
16565 v8::HandleScope scope(isolate); | 16509 ExternalArrayLimitTestHelper(v8::kExternalByteArray, 0x40000000); |
16566 ExtArrayLimitsHelper(isolate, v8::kExternalByteArray, 0x40000000); | 16510 ExternalArrayLimitTestHelper(v8::kExternalByteArray, 0xffffffff); |
16567 ExtArrayLimitsHelper(isolate, v8::kExternalByteArray, 0xffffffff); | 16511 ExternalArrayLimitTestHelper(v8::kExternalUnsignedByteArray, 0x40000000); |
16568 ExtArrayLimitsHelper(isolate, v8::kExternalUnsignedByteArray, 0x40000000); | 16512 ExternalArrayLimitTestHelper(v8::kExternalUnsignedByteArray, 0xffffffff); |
16569 ExtArrayLimitsHelper(isolate, v8::kExternalUnsignedByteArray, 0xffffffff); | 16513 ExternalArrayLimitTestHelper(v8::kExternalShortArray, 0x40000000); |
16570 ExtArrayLimitsHelper(isolate, v8::kExternalShortArray, 0x40000000); | 16514 ExternalArrayLimitTestHelper(v8::kExternalShortArray, 0xffffffff); |
16571 ExtArrayLimitsHelper(isolate, v8::kExternalShortArray, 0xffffffff); | 16515 ExternalArrayLimitTestHelper(v8::kExternalUnsignedShortArray, 0x40000000); |
16572 ExtArrayLimitsHelper(isolate, v8::kExternalUnsignedShortArray, 0x40000000); | 16516 ExternalArrayLimitTestHelper(v8::kExternalUnsignedShortArray, 0xffffffff); |
16573 ExtArrayLimitsHelper(isolate, v8::kExternalUnsignedShortArray, 0xffffffff); | 16517 ExternalArrayLimitTestHelper(v8::kExternalIntArray, 0x40000000); |
16574 ExtArrayLimitsHelper(isolate, v8::kExternalIntArray, 0x40000000); | 16518 ExternalArrayLimitTestHelper(v8::kExternalIntArray, 0xffffffff); |
16575 ExtArrayLimitsHelper(isolate, v8::kExternalIntArray, 0xffffffff); | 16519 ExternalArrayLimitTestHelper(v8::kExternalUnsignedIntArray, 0x40000000); |
16576 ExtArrayLimitsHelper(isolate, v8::kExternalUnsignedIntArray, 0x40000000); | 16520 ExternalArrayLimitTestHelper(v8::kExternalUnsignedIntArray, 0xffffffff); |
16577 ExtArrayLimitsHelper(isolate, v8::kExternalUnsignedIntArray, 0xffffffff); | 16521 ExternalArrayLimitTestHelper(v8::kExternalFloatArray, 0x40000000); |
16578 ExtArrayLimitsHelper(isolate, v8::kExternalFloatArray, 0x40000000); | 16522 ExternalArrayLimitTestHelper(v8::kExternalFloatArray, 0xffffffff); |
16579 ExtArrayLimitsHelper(isolate, v8::kExternalFloatArray, 0xffffffff); | 16523 ExternalArrayLimitTestHelper(v8::kExternalDoubleArray, 0x40000000); |
16580 ExtArrayLimitsHelper(isolate, v8::kExternalDoubleArray, 0x40000000); | 16524 ExternalArrayLimitTestHelper(v8::kExternalDoubleArray, 0xffffffff); |
16581 ExtArrayLimitsHelper(isolate, v8::kExternalDoubleArray, 0xffffffff); | 16525 ExternalArrayLimitTestHelper(v8::kExternalPixelArray, 0x40000000); |
16582 ExtArrayLimitsHelper(isolate, v8::kExternalPixelArray, 0x40000000); | 16526 ExternalArrayLimitTestHelper(v8::kExternalPixelArray, 0xffffffff); |
16583 ExtArrayLimitsHelper(isolate, v8::kExternalPixelArray, 0xffffffff); | |
16584 } | 16527 } |
16585 | 16528 |
16586 | 16529 |
16587 template <typename ElementType, typename TypedArray, | 16530 template <typename ElementType, typename TypedArray, |
16588 class ExternalArrayClass> | 16531 class ExternalArrayClass> |
16589 void TypedArrayTestHelper(v8::ExternalArrayType array_type, | 16532 void TypedArrayTestHelper(v8::ExternalArrayType array_type, |
16590 int64_t low, int64_t high) { | 16533 int64_t low, int64_t high) { |
16591 const int kElementCount = 50; | 16534 const int kElementCount = 50; |
16592 | 16535 |
16593 i::ScopedVector<ElementType> backing_store(kElementCount+2); | 16536 i::ScopedVector<ElementType> backing_store(kElementCount+2); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16725 | 16668 |
16726 THREADED_TEST(ScriptContextDependence) { | 16669 THREADED_TEST(ScriptContextDependence) { |
16727 LocalContext c1; | 16670 LocalContext c1; |
16728 v8::HandleScope scope(c1->GetIsolate()); | 16671 v8::HandleScope scope(c1->GetIsolate()); |
16729 const char *source = "foo"; | 16672 const char *source = "foo"; |
16730 v8::Handle<v8::Script> dep = | 16673 v8::Handle<v8::Script> dep = |
16731 v8::Script::Compile(v8::String::NewFromUtf8(c1->GetIsolate(), source)); | 16674 v8::Script::Compile(v8::String::NewFromUtf8(c1->GetIsolate(), source)); |
16732 v8::Handle<v8::Script> indep = | 16675 v8::Handle<v8::Script> indep = |
16733 v8::Script::New(v8::String::NewFromUtf8(c1->GetIsolate(), source)); | 16676 v8::Script::New(v8::String::NewFromUtf8(c1->GetIsolate(), source)); |
16734 c1->Global()->Set(v8::String::NewFromUtf8(c1->GetIsolate(), "foo"), | 16677 c1->Global()->Set(v8::String::NewFromUtf8(c1->GetIsolate(), "foo"), |
16735 v8::Integer::New(c1->GetIsolate(), 100)); | 16678 v8::Integer::New(100)); |
16736 CHECK_EQ(dep->Run()->Int32Value(), 100); | 16679 CHECK_EQ(dep->Run()->Int32Value(), 100); |
16737 CHECK_EQ(indep->Run()->Int32Value(), 100); | 16680 CHECK_EQ(indep->Run()->Int32Value(), 100); |
16738 LocalContext c2; | 16681 LocalContext c2; |
16739 c2->Global()->Set(v8::String::NewFromUtf8(c2->GetIsolate(), "foo"), | 16682 c2->Global()->Set(v8::String::NewFromUtf8(c2->GetIsolate(), "foo"), |
16740 v8::Integer::New(c2->GetIsolate(), 101)); | 16683 v8::Integer::New(101)); |
16741 CHECK_EQ(dep->Run()->Int32Value(), 100); | 16684 CHECK_EQ(dep->Run()->Int32Value(), 100); |
16742 CHECK_EQ(indep->Run()->Int32Value(), 101); | 16685 CHECK_EQ(indep->Run()->Int32Value(), 101); |
16743 } | 16686 } |
16744 | 16687 |
16745 | 16688 |
16746 THREADED_TEST(StackTrace) { | 16689 THREADED_TEST(StackTrace) { |
16747 LocalContext context; | 16690 LocalContext context; |
16748 v8::HandleScope scope(context->GetIsolate()); | 16691 v8::HandleScope scope(context->GetIsolate()); |
16749 v8::TryCatch try_catch; | 16692 v8::TryCatch try_catch; |
16750 const char *source = "function foo() { FAIL.FAIL; }; foo();"; | 16693 const char *source = "function foo() { FAIL.FAIL; }; foo();"; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16868 "function bat() {AnalyzeStackInNativeCode(2);\n" | 16811 "function bat() {AnalyzeStackInNativeCode(2);\n" |
16869 "}\n" | 16812 "}\n" |
16870 "\n" | 16813 "\n" |
16871 "function baz() {\n" | 16814 "function baz() {\n" |
16872 " bat();\n" | 16815 " bat();\n" |
16873 "}\n" | 16816 "}\n" |
16874 "eval('new baz();');"; | 16817 "eval('new baz();');"; |
16875 v8::Handle<v8::String> detailed_src = | 16818 v8::Handle<v8::String> detailed_src = |
16876 v8::String::NewFromUtf8(isolate, detailed_source); | 16819 v8::String::NewFromUtf8(isolate, detailed_source); |
16877 // Make the script using a non-zero line and column offset. | 16820 // Make the script using a non-zero line and column offset. |
16878 v8::Handle<v8::Integer> line_offset = v8::Integer::New(isolate, 3); | 16821 v8::Handle<v8::Integer> line_offset = v8::Integer::New(3); |
16879 v8::Handle<v8::Integer> column_offset = v8::Integer::New(isolate, 5); | 16822 v8::Handle<v8::Integer> column_offset = v8::Integer::New(5); |
16880 v8::ScriptOrigin detailed_origin(origin, line_offset, column_offset); | 16823 v8::ScriptOrigin detailed_origin(origin, line_offset, column_offset); |
16881 v8::Handle<v8::Script> detailed_script( | 16824 v8::Handle<v8::Script> detailed_script( |
16882 v8::Script::New(detailed_src, &detailed_origin)); | 16825 v8::Script::New(detailed_src, &detailed_origin)); |
16883 v8::Handle<Value> detailed_result(detailed_script->Run()); | 16826 v8::Handle<Value> detailed_result(detailed_script->Run()); |
16884 CHECK(!detailed_result.IsEmpty()); | 16827 CHECK(!detailed_result.IsEmpty()); |
16885 CHECK(detailed_result->IsObject()); | 16828 CHECK(detailed_result->IsObject()); |
16886 } | 16829 } |
16887 | 16830 |
16888 | 16831 |
16889 static void StackTraceForUncaughtExceptionListener( | 16832 static void StackTraceForUncaughtExceptionListener( |
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17618 | 17561 |
17619 // We don't have a consistent way to write 64-bit constants syntactically, so we | 17562 // We don't have a consistent way to write 64-bit constants syntactically, so we |
17620 // split them into two 32-bit constants and combine them programmatically. | 17563 // split them into two 32-bit constants and combine them programmatically. |
17621 static double DoubleFromBits(uint32_t high_bits, uint32_t low_bits) { | 17564 static double DoubleFromBits(uint32_t high_bits, uint32_t low_bits) { |
17622 return DoubleFromBits((static_cast<uint64_t>(high_bits) << 32) | low_bits); | 17565 return DoubleFromBits((static_cast<uint64_t>(high_bits) << 32) | low_bits); |
17623 } | 17566 } |
17624 | 17567 |
17625 | 17568 |
17626 THREADED_TEST(QuietSignalingNaNs) { | 17569 THREADED_TEST(QuietSignalingNaNs) { |
17627 LocalContext context; | 17570 LocalContext context; |
17628 v8::Isolate* isolate = context->GetIsolate(); | 17571 v8::HandleScope scope(context->GetIsolate()); |
17629 v8::HandleScope scope(isolate); | |
17630 v8::TryCatch try_catch; | 17572 v8::TryCatch try_catch; |
17631 | 17573 |
17632 // Special double values. | 17574 // Special double values. |
17633 double snan = DoubleFromBits(0x7ff00000, 0x00000001); | 17575 double snan = DoubleFromBits(0x7ff00000, 0x00000001); |
17634 double qnan = DoubleFromBits(0x7ff80000, 0x00000000); | 17576 double qnan = DoubleFromBits(0x7ff80000, 0x00000000); |
17635 double infinity = DoubleFromBits(0x7ff00000, 0x00000000); | 17577 double infinity = DoubleFromBits(0x7ff00000, 0x00000000); |
17636 double max_normal = DoubleFromBits(0x7fefffff, 0xffffffffu); | 17578 double max_normal = DoubleFromBits(0x7fefffff, 0xffffffffu); |
17637 double min_normal = DoubleFromBits(0x00100000, 0x00000000); | 17579 double min_normal = DoubleFromBits(0x00100000, 0x00000000); |
17638 double max_denormal = DoubleFromBits(0x000fffff, 0xffffffffu); | 17580 double max_denormal = DoubleFromBits(0x000fffff, 0xffffffffu); |
17639 double min_denormal = DoubleFromBits(0x00000000, 0x00000001); | 17581 double min_denormal = DoubleFromBits(0x00000000, 0x00000001); |
(...skipping 23 matching lines...) Expand all Loading... |
17663 -infinity, | 17605 -infinity, |
17664 -qnan, | 17606 -qnan, |
17665 -snan | 17607 -snan |
17666 }; | 17608 }; |
17667 int num_test_values = 20; | 17609 int num_test_values = 20; |
17668 | 17610 |
17669 for (int i = 0; i < num_test_values; i++) { | 17611 for (int i = 0; i < num_test_values; i++) { |
17670 double test_value = test_values[i]; | 17612 double test_value = test_values[i]; |
17671 | 17613 |
17672 // Check that Number::New preserves non-NaNs and quiets SNaNs. | 17614 // Check that Number::New preserves non-NaNs and quiets SNaNs. |
17673 v8::Handle<v8::Value> number = v8::Number::New(isolate, test_value); | 17615 v8::Handle<v8::Value> number = v8::Number::New(test_value); |
17674 double stored_number = number->NumberValue(); | 17616 double stored_number = number->NumberValue(); |
17675 if (!std::isnan(test_value)) { | 17617 if (!std::isnan(test_value)) { |
17676 CHECK_EQ(test_value, stored_number); | 17618 CHECK_EQ(test_value, stored_number); |
17677 } else { | 17619 } else { |
17678 uint64_t stored_bits = DoubleToBits(stored_number); | 17620 uint64_t stored_bits = DoubleToBits(stored_number); |
17679 // Check if quiet nan (bits 51..62 all set). | 17621 // Check if quiet nan (bits 51..62 all set). |
17680 #if defined(V8_TARGET_ARCH_MIPS) && !defined(USE_SIMULATOR) | 17622 #if defined(V8_TARGET_ARCH_MIPS) && !defined(USE_SIMULATOR) |
17681 // Most significant fraction bit for quiet nan is set to 0 | 17623 // Most significant fraction bit for quiet nan is set to 0 |
17682 // on MIPS architecture. Allowed by IEEE-754. | 17624 // on MIPS architecture. Allowed by IEEE-754. |
17683 CHECK_EQ(0xffe, static_cast<int>((stored_bits >> 51) & 0xfff)); | 17625 CHECK_EQ(0xffe, static_cast<int>((stored_bits >> 51) & 0xfff)); |
17684 #else | 17626 #else |
17685 CHECK_EQ(0xfff, static_cast<int>((stored_bits >> 51) & 0xfff)); | 17627 CHECK_EQ(0xfff, static_cast<int>((stored_bits >> 51) & 0xfff)); |
17686 #endif | 17628 #endif |
17687 } | 17629 } |
17688 | 17630 |
17689 // Check that Date::New preserves non-NaNs in the date range and | 17631 // Check that Date::New preserves non-NaNs in the date range and |
17690 // quiets SNaNs. | 17632 // quiets SNaNs. |
17691 v8::Handle<v8::Value> date = | 17633 v8::Handle<v8::Value> date = |
17692 v8::Date::New(isolate, test_value); | 17634 v8::Date::New(context->GetIsolate(), test_value); |
17693 double expected_stored_date = DoubleToDateTime(test_value); | 17635 double expected_stored_date = DoubleToDateTime(test_value); |
17694 double stored_date = date->NumberValue(); | 17636 double stored_date = date->NumberValue(); |
17695 if (!std::isnan(expected_stored_date)) { | 17637 if (!std::isnan(expected_stored_date)) { |
17696 CHECK_EQ(expected_stored_date, stored_date); | 17638 CHECK_EQ(expected_stored_date, stored_date); |
17697 } else { | 17639 } else { |
17698 uint64_t stored_bits = DoubleToBits(stored_date); | 17640 uint64_t stored_bits = DoubleToBits(stored_date); |
17699 // Check if quiet nan (bits 51..62 all set). | 17641 // Check if quiet nan (bits 51..62 all set). |
17700 #if defined(V8_TARGET_ARCH_MIPS) && !defined(USE_SIMULATOR) | 17642 #if defined(V8_TARGET_ARCH_MIPS) && !defined(USE_SIMULATOR) |
17701 // Most significant fraction bit for quiet nan is set to 0 | 17643 // Most significant fraction bit for quiet nan is set to 0 |
17702 // on MIPS architecture. Allowed by IEEE-754. | 17644 // on MIPS architecture. Allowed by IEEE-754. |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17954 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); | 17896 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); |
17955 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast( | 17897 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast( |
17956 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "g"))); | 17898 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "g"))); |
17957 CHECK_EQ(0, f->GetScriptLineNumber()); | 17899 CHECK_EQ(0, f->GetScriptLineNumber()); |
17958 CHECK_EQ(2, g->GetScriptLineNumber()); | 17900 CHECK_EQ(2, g->GetScriptLineNumber()); |
17959 } | 17901 } |
17960 | 17902 |
17961 | 17903 |
17962 THREADED_TEST(ScriptColumnNumber) { | 17904 THREADED_TEST(ScriptColumnNumber) { |
17963 LocalContext env; | 17905 LocalContext env; |
17964 v8::Isolate* isolate = env->GetIsolate(); | 17906 v8::HandleScope scope(env->GetIsolate()); |
17965 v8::HandleScope scope(isolate); | |
17966 v8::ScriptOrigin origin = | 17907 v8::ScriptOrigin origin = |
17967 v8::ScriptOrigin(v8::String::NewFromUtf8(isolate, "test"), | 17908 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "test"), |
17968 v8::Integer::New(isolate, 3), | 17909 v8::Integer::New(3), v8::Integer::New(2)); |
17969 v8::Integer::New(isolate, 2)); | |
17970 v8::Handle<v8::String> script = v8::String::NewFromUtf8( | 17910 v8::Handle<v8::String> script = v8::String::NewFromUtf8( |
17971 isolate, "function foo() {}\n\n function bar() {}"); | 17911 env->GetIsolate(), "function foo() {}\n\n function bar() {}"); |
17972 v8::Script::Compile(script, &origin)->Run(); | 17912 v8::Script::Compile(script, &origin)->Run(); |
17973 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( | 17913 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( |
17974 env->Global()->Get(v8::String::NewFromUtf8(isolate, "foo"))); | 17914 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo"))); |
17975 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast( | 17915 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast( |
17976 env->Global()->Get(v8::String::NewFromUtf8(isolate, "bar"))); | 17916 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "bar"))); |
17977 CHECK_EQ(14, foo->GetScriptColumnNumber()); | 17917 CHECK_EQ(14, foo->GetScriptColumnNumber()); |
17978 CHECK_EQ(17, bar->GetScriptColumnNumber()); | 17918 CHECK_EQ(17, bar->GetScriptColumnNumber()); |
17979 } | 17919 } |
17980 | 17920 |
17981 | 17921 |
17982 THREADED_TEST(FunctionIsBuiltin) { | 17922 THREADED_TEST(FunctionIsBuiltin) { |
17983 LocalContext env; | 17923 LocalContext env; |
17984 v8::Isolate* isolate = env->GetIsolate(); | 17924 v8::HandleScope scope(env->GetIsolate()); |
17985 v8::HandleScope scope(isolate); | |
17986 v8::Local<v8::Function> f; | 17925 v8::Local<v8::Function> f; |
17987 f = v8::Local<v8::Function>::Cast(CompileRun("Math.floor")); | 17926 f = v8::Local<v8::Function>::Cast(CompileRun("Math.floor")); |
17988 CHECK(f->IsBuiltin()); | 17927 CHECK(f->IsBuiltin()); |
17989 f = v8::Local<v8::Function>::Cast(CompileRun("Object")); | 17928 f = v8::Local<v8::Function>::Cast(CompileRun("Object")); |
17990 CHECK(f->IsBuiltin()); | 17929 CHECK(f->IsBuiltin()); |
17991 f = v8::Local<v8::Function>::Cast(CompileRun("Object.__defineSetter__")); | 17930 f = v8::Local<v8::Function>::Cast(CompileRun("Object.__defineSetter__")); |
17992 CHECK(f->IsBuiltin()); | 17931 CHECK(f->IsBuiltin()); |
17993 f = v8::Local<v8::Function>::Cast(CompileRun("Array.prototype.toString")); | 17932 f = v8::Local<v8::Function>::Cast(CompileRun("Array.prototype.toString")); |
17994 CHECK(f->IsBuiltin()); | 17933 CHECK(f->IsBuiltin()); |
17995 f = v8::Local<v8::Function>::Cast(CompileRun("function a() {}; a;")); | 17934 f = v8::Local<v8::Function>::Cast(CompileRun("function a() {}; a;")); |
17996 CHECK(!f->IsBuiltin()); | 17935 CHECK(!f->IsBuiltin()); |
17997 } | 17936 } |
17998 | 17937 |
17999 | 17938 |
18000 THREADED_TEST(FunctionGetScriptId) { | 17939 THREADED_TEST(FunctionGetScriptId) { |
18001 LocalContext env; | 17940 LocalContext env; |
18002 v8::Isolate* isolate = env->GetIsolate(); | 17941 v8::HandleScope scope(env->GetIsolate()); |
18003 v8::HandleScope scope(isolate); | |
18004 v8::ScriptOrigin origin = | 17942 v8::ScriptOrigin origin = |
18005 v8::ScriptOrigin(v8::String::NewFromUtf8(isolate, "test"), | 17943 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "test"), |
18006 v8::Integer::New(isolate, 3), | 17944 v8::Integer::New(3), v8::Integer::New(2)); |
18007 v8::Integer::New(isolate, 2)); | |
18008 v8::Handle<v8::String> scriptSource = v8::String::NewFromUtf8( | 17945 v8::Handle<v8::String> scriptSource = v8::String::NewFromUtf8( |
18009 isolate, "function foo() {}\n\n function bar() {}"); | 17946 env->GetIsolate(), "function foo() {}\n\n function bar() {}"); |
18010 v8::Local<v8::Script> script(v8::Script::Compile(scriptSource, &origin)); | 17947 v8::Local<v8::Script> script(v8::Script::Compile(scriptSource, &origin)); |
18011 script->Run(); | 17948 script->Run(); |
18012 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( | 17949 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( |
18013 env->Global()->Get(v8::String::NewFromUtf8(isolate, "foo"))); | 17950 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo"))); |
18014 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast( | 17951 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast( |
18015 env->Global()->Get(v8::String::NewFromUtf8(isolate, "bar"))); | 17952 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "bar"))); |
18016 CHECK_EQ(script->GetId(), foo->ScriptId()); | 17953 CHECK_EQ(script->GetId(), foo->ScriptId()); |
18017 CHECK_EQ(script->GetId(), bar->ScriptId()); | 17954 CHECK_EQ(script->GetId(), bar->ScriptId()); |
18018 } | 17955 } |
18019 | 17956 |
18020 | 17957 |
18021 static void GetterWhichReturns42( | 17958 static void GetterWhichReturns42( |
18022 Local<String> name, | 17959 Local<String> name, |
18023 const v8::PropertyCallbackInfo<v8::Value>& info) { | 17960 const v8::PropertyCallbackInfo<v8::Value>& info) { |
18024 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); | 17961 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); |
18025 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); | 17962 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18147 const char* source = "function C1() {" | 18084 const char* source = "function C1() {" |
18148 " this.x = 23;" | 18085 " this.x = 23;" |
18149 "};" | 18086 "};" |
18150 "C1.prototype = P;"; | 18087 "C1.prototype = P;"; |
18151 | 18088 |
18152 LocalContext context; | 18089 LocalContext context; |
18153 v8::HandleScope scope(context->GetIsolate()); | 18090 v8::HandleScope scope(context->GetIsolate()); |
18154 v8::Local<v8::Script> script; | 18091 v8::Local<v8::Script> script; |
18155 | 18092 |
18156 // Use a simple object as prototype. | 18093 // Use a simple object as prototype. |
18157 v8::Local<v8::Object> prototype = v8::Object::New(context->GetIsolate()); | 18094 v8::Local<v8::Object> prototype = v8::Object::New(); |
18158 prototype->Set(v8_str("y"), v8_num(42)); | 18095 prototype->Set(v8_str("y"), v8_num(42)); |
18159 context->Global()->Set(v8_str("P"), prototype); | 18096 context->Global()->Set(v8_str("P"), prototype); |
18160 | 18097 |
18161 // This compile will add the code to the compilation cache. | 18098 // This compile will add the code to the compilation cache. |
18162 CompileRun(source); | 18099 CompileRun(source); |
18163 | 18100 |
18164 script = v8::Script::Compile(v8_str("new C1();")); | 18101 script = v8::Script::Compile(v8_str("new C1();")); |
18165 // Allow enough iterations for the inobject slack tracking logic | 18102 // Allow enough iterations for the inobject slack tracking logic |
18166 // to finalize instance size and install the fast construct stub. | 18103 // to finalize instance size and install the fast construct stub. |
18167 for (int i = 0; i < 256; i++) { | 18104 for (int i = 0; i < 256; i++) { |
(...skipping 1043 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19211 | 19148 |
19212 int counter_; | 19149 int counter_; |
19213 v8::Persistent<v8::Object>* object_; | 19150 v8::Persistent<v8::Object>* object_; |
19214 }; | 19151 }; |
19215 | 19152 |
19216 | 19153 |
19217 TEST(PersistentHandleVisitor) { | 19154 TEST(PersistentHandleVisitor) { |
19218 LocalContext context; | 19155 LocalContext context; |
19219 v8::Isolate* isolate = context->GetIsolate(); | 19156 v8::Isolate* isolate = context->GetIsolate(); |
19220 v8::HandleScope scope(isolate); | 19157 v8::HandleScope scope(isolate); |
19221 v8::Persistent<v8::Object> object(isolate, v8::Object::New(isolate)); | 19158 v8::Persistent<v8::Object> object(isolate, v8::Object::New()); |
19222 CHECK_EQ(0, object.WrapperClassId()); | 19159 CHECK_EQ(0, object.WrapperClassId()); |
19223 object.SetWrapperClassId(42); | 19160 object.SetWrapperClassId(42); |
19224 CHECK_EQ(42, object.WrapperClassId()); | 19161 CHECK_EQ(42, object.WrapperClassId()); |
19225 | 19162 |
19226 Visitor42 visitor(&object); | 19163 Visitor42 visitor(&object); |
19227 v8::V8::VisitHandlesWithClassIds(&visitor); | 19164 v8::V8::VisitHandlesWithClassIds(&visitor); |
19228 CHECK_EQ(1, visitor.counter_); | 19165 CHECK_EQ(1, visitor.counter_); |
19229 | 19166 |
19230 object.Reset(); | 19167 object.Reset(); |
19231 } | 19168 } |
19232 | 19169 |
19233 | 19170 |
19234 TEST(WrapperClassId) { | 19171 TEST(WrapperClassId) { |
19235 LocalContext context; | 19172 LocalContext context; |
19236 v8::Isolate* isolate = context->GetIsolate(); | 19173 v8::Isolate* isolate = context->GetIsolate(); |
19237 v8::HandleScope scope(isolate); | 19174 v8::HandleScope scope(isolate); |
19238 v8::Persistent<v8::Object> object(isolate, v8::Object::New(isolate)); | 19175 v8::Persistent<v8::Object> object(isolate, v8::Object::New()); |
19239 CHECK_EQ(0, object.WrapperClassId()); | 19176 CHECK_EQ(0, object.WrapperClassId()); |
19240 object.SetWrapperClassId(65535); | 19177 object.SetWrapperClassId(65535); |
19241 CHECK_EQ(65535, object.WrapperClassId()); | 19178 CHECK_EQ(65535, object.WrapperClassId()); |
19242 object.Reset(); | 19179 object.Reset(); |
19243 } | 19180 } |
19244 | 19181 |
19245 | 19182 |
19246 TEST(PersistentHandleInNewSpaceVisitor) { | 19183 TEST(PersistentHandleInNewSpaceVisitor) { |
19247 LocalContext context; | 19184 LocalContext context; |
19248 v8::Isolate* isolate = context->GetIsolate(); | 19185 v8::Isolate* isolate = context->GetIsolate(); |
19249 v8::HandleScope scope(isolate); | 19186 v8::HandleScope scope(isolate); |
19250 v8::Persistent<v8::Object> object1(isolate, v8::Object::New(isolate)); | 19187 v8::Persistent<v8::Object> object1(isolate, v8::Object::New()); |
19251 CHECK_EQ(0, object1.WrapperClassId()); | 19188 CHECK_EQ(0, object1.WrapperClassId()); |
19252 object1.SetWrapperClassId(42); | 19189 object1.SetWrapperClassId(42); |
19253 CHECK_EQ(42, object1.WrapperClassId()); | 19190 CHECK_EQ(42, object1.WrapperClassId()); |
19254 | 19191 |
19255 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 19192 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
19256 | 19193 |
19257 v8::Persistent<v8::Object> object2(isolate, v8::Object::New(isolate)); | 19194 v8::Persistent<v8::Object> object2(isolate, v8::Object::New()); |
19258 CHECK_EQ(0, object2.WrapperClassId()); | 19195 CHECK_EQ(0, object2.WrapperClassId()); |
19259 object2.SetWrapperClassId(42); | 19196 object2.SetWrapperClassId(42); |
19260 CHECK_EQ(42, object2.WrapperClassId()); | 19197 CHECK_EQ(42, object2.WrapperClassId()); |
19261 | 19198 |
19262 Visitor42 visitor(&object2); | 19199 Visitor42 visitor(&object2); |
19263 v8::V8::VisitHandlesForPartialDependence(isolate, &visitor); | 19200 v8::V8::VisitHandlesForPartialDependence(isolate, &visitor); |
19264 CHECK_EQ(1, visitor.counter_); | 19201 CHECK_EQ(1, visitor.counter_); |
19265 | 19202 |
19266 object1.Reset(); | 19203 object1.Reset(); |
19267 object2.Reset(); | 19204 object2.Reset(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19318 v8::RegExp::kMultiline)); | 19255 v8::RegExp::kMultiline)); |
19319 CHECK(re->IsRegExp()); | 19256 CHECK(re->IsRegExp()); |
19320 CHECK(re->GetSource()->Equals(v8_str("foobarbaz"))); | 19257 CHECK(re->GetSource()->Equals(v8_str("foobarbaz"))); |
19321 CHECK_EQ(v8::RegExp::kIgnoreCase | v8::RegExp::kMultiline, | 19258 CHECK_EQ(v8::RegExp::kIgnoreCase | v8::RegExp::kMultiline, |
19322 static_cast<int>(re->GetFlags())); | 19259 static_cast<int>(re->GetFlags())); |
19323 | 19260 |
19324 context->Global()->Set(v8_str("re"), re); | 19261 context->Global()->Set(v8_str("re"), re); |
19325 ExpectTrue("re.test('FoobarbaZ')"); | 19262 ExpectTrue("re.test('FoobarbaZ')"); |
19326 | 19263 |
19327 // RegExps are objects on which you can set properties. | 19264 // RegExps are objects on which you can set properties. |
19328 re->Set(v8_str("property"), v8::Integer::New(context->GetIsolate(), 32)); | 19265 re->Set(v8_str("property"), v8::Integer::New(32)); |
19329 v8::Handle<v8::Value> value(CompileRun("re.property")); | 19266 v8::Handle<v8::Value> value(CompileRun("re.property")); |
19330 CHECK_EQ(32, value->Int32Value()); | 19267 CHECK_EQ(32, value->Int32Value()); |
19331 | 19268 |
19332 v8::TryCatch try_catch; | 19269 v8::TryCatch try_catch; |
19333 re = v8::RegExp::New(v8_str("foo["), v8::RegExp::kNone); | 19270 re = v8::RegExp::New(v8_str("foo["), v8::RegExp::kNone); |
19334 CHECK(re.IsEmpty()); | 19271 CHECK(re.IsEmpty()); |
19335 CHECK(try_catch.HasCaught()); | 19272 CHECK(try_catch.HasCaught()); |
19336 context->Global()->Set(v8_str("ex"), try_catch.Exception()); | 19273 context->Global()->Set(v8_str("ex"), try_catch.Exception()); |
19337 ExpectTrue("ex instanceof SyntaxError"); | 19274 ExpectTrue("ex instanceof SyntaxError"); |
19338 } | 19275 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19397 " { configurable: true, enumerable: true, value: 3 });" | 19334 " { configurable: true, enumerable: true, value: 3 });" |
19398 "})").As<Function>(); | 19335 "})").As<Function>(); |
19399 context->DetachGlobal(); | 19336 context->DetachGlobal(); |
19400 define_property->Call(proxy, 0, NULL); | 19337 define_property->Call(proxy, 0, NULL); |
19401 } | 19338 } |
19402 | 19339 |
19403 | 19340 |
19404 static void InstallContextId(v8::Handle<Context> context, int id) { | 19341 static void InstallContextId(v8::Handle<Context> context, int id) { |
19405 Context::Scope scope(context); | 19342 Context::Scope scope(context); |
19406 CompileRun("Object.prototype").As<Object>()-> | 19343 CompileRun("Object.prototype").As<Object>()-> |
19407 Set(v8_str("context_id"), v8::Integer::New(context->GetIsolate(), id)); | 19344 Set(v8_str("context_id"), v8::Integer::New(id)); |
19408 } | 19345 } |
19409 | 19346 |
19410 | 19347 |
19411 static void CheckContextId(v8::Handle<Object> object, int expected) { | 19348 static void CheckContextId(v8::Handle<Object> object, int expected) { |
19412 CHECK_EQ(expected, object->Get(v8_str("context_id"))->Int32Value()); | 19349 CHECK_EQ(expected, object->Get(v8_str("context_id"))->Int32Value()); |
19413 } | 19350 } |
19414 | 19351 |
19415 | 19352 |
19416 THREADED_TEST(CreationContext) { | 19353 THREADED_TEST(CreationContext) { |
19417 v8::Isolate* isolate = CcTest::isolate(); | 19354 v8::Isolate* isolate = CcTest::isolate(); |
19418 HandleScope handle_scope(isolate); | 19355 HandleScope handle_scope(isolate); |
19419 Handle<Context> context1 = Context::New(isolate); | 19356 Handle<Context> context1 = Context::New(isolate); |
19420 InstallContextId(context1, 1); | 19357 InstallContextId(context1, 1); |
19421 Handle<Context> context2 = Context::New(isolate); | 19358 Handle<Context> context2 = Context::New(isolate); |
19422 InstallContextId(context2, 2); | 19359 InstallContextId(context2, 2); |
19423 Handle<Context> context3 = Context::New(isolate); | 19360 Handle<Context> context3 = Context::New(isolate); |
19424 InstallContextId(context3, 3); | 19361 InstallContextId(context3, 3); |
19425 | 19362 |
19426 Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(isolate); | 19363 Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(isolate); |
19427 | 19364 |
19428 Local<Object> object1; | 19365 Local<Object> object1; |
19429 Local<Function> func1; | 19366 Local<Function> func1; |
19430 { | 19367 { |
19431 Context::Scope scope(context1); | 19368 Context::Scope scope(context1); |
19432 object1 = Object::New(isolate); | 19369 object1 = Object::New(); |
19433 func1 = tmpl->GetFunction(); | 19370 func1 = tmpl->GetFunction(); |
19434 } | 19371 } |
19435 | 19372 |
19436 Local<Object> object2; | 19373 Local<Object> object2; |
19437 Local<Function> func2; | 19374 Local<Function> func2; |
19438 { | 19375 { |
19439 Context::Scope scope(context2); | 19376 Context::Scope scope(context2); |
19440 object2 = Object::New(isolate); | 19377 object2 = Object::New(); |
19441 func2 = tmpl->GetFunction(); | 19378 func2 = tmpl->GetFunction(); |
19442 } | 19379 } |
19443 | 19380 |
19444 Local<Object> instance1; | 19381 Local<Object> instance1; |
19445 Local<Object> instance2; | 19382 Local<Object> instance2; |
19446 | 19383 |
19447 { | 19384 { |
19448 Context::Scope scope(context3); | 19385 Context::Scope scope(context3); |
19449 instance1 = func1->NewInstance(); | 19386 instance1 = func1->NewInstance(); |
19450 instance2 = func2->NewInstance(); | 19387 instance2 = func2->NewInstance(); |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19841 protected_hidden_proto_template->InstanceTemplate()->SetAccessCheckCallbacks( | 19778 protected_hidden_proto_template->InstanceTemplate()->SetAccessCheckCallbacks( |
19842 BlockProtoNamedSecurityTestCallback, | 19779 BlockProtoNamedSecurityTestCallback, |
19843 IndexedSecurityTestCallback); | 19780 IndexedSecurityTestCallback); |
19844 protected_hidden_proto_template->SetHiddenPrototype(true); | 19781 protected_hidden_proto_template->SetHiddenPrototype(true); |
19845 | 19782 |
19846 // Context for "foreign" objects used in test. | 19783 // Context for "foreign" objects used in test. |
19847 Local<Context> context = v8::Context::New(isolate); | 19784 Local<Context> context = v8::Context::New(isolate); |
19848 context->Enter(); | 19785 context->Enter(); |
19849 | 19786 |
19850 // Plain object, no security check. | 19787 // Plain object, no security check. |
19851 Local<Object> simple_object = Object::New(isolate); | 19788 Local<Object> simple_object = Object::New(); |
19852 | 19789 |
19853 // Object with explicit security check. | 19790 // Object with explicit security check. |
19854 Local<Object> protected_object = | 19791 Local<Object> protected_object = |
19855 no_proto_template->NewInstance(); | 19792 no_proto_template->NewInstance(); |
19856 | 19793 |
19857 // JSGlobalProxy object, always have security check. | 19794 // JSGlobalProxy object, always have security check. |
19858 Local<Object> proxy_object = | 19795 Local<Object> proxy_object = |
19859 context->Global(); | 19796 context->Global(); |
19860 | 19797 |
19861 // Global object, the prototype of proxy_object. No security checks. | 19798 // Global object, the prototype of proxy_object. No security checks. |
19862 Local<Object> global_object = | 19799 Local<Object> global_object = |
19863 proxy_object->GetPrototype()->ToObject(); | 19800 proxy_object->GetPrototype()->ToObject(); |
19864 | 19801 |
19865 // Hidden prototype without security check. | 19802 // Hidden prototype without security check. |
19866 Local<Object> hidden_prototype = | 19803 Local<Object> hidden_prototype = |
19867 hidden_proto_template->GetFunction()->NewInstance(); | 19804 hidden_proto_template->GetFunction()->NewInstance(); |
19868 Local<Object> object_with_hidden = | 19805 Local<Object> object_with_hidden = |
19869 Object::New(isolate); | 19806 Object::New(); |
19870 object_with_hidden->SetPrototype(hidden_prototype); | 19807 object_with_hidden->SetPrototype(hidden_prototype); |
19871 | 19808 |
19872 // Hidden prototype with security check on the hidden prototype. | 19809 // Hidden prototype with security check on the hidden prototype. |
19873 Local<Object> protected_hidden_prototype = | 19810 Local<Object> protected_hidden_prototype = |
19874 protected_hidden_proto_template->GetFunction()->NewInstance(); | 19811 protected_hidden_proto_template->GetFunction()->NewInstance(); |
19875 Local<Object> object_with_protected_hidden = | 19812 Local<Object> object_with_protected_hidden = |
19876 Object::New(isolate); | 19813 Object::New(); |
19877 object_with_protected_hidden->SetPrototype(protected_hidden_prototype); | 19814 object_with_protected_hidden->SetPrototype(protected_hidden_prototype); |
19878 | 19815 |
19879 context->Exit(); | 19816 context->Exit(); |
19880 | 19817 |
19881 // Template for object for second context. Values to test are put on it as | 19818 // Template for object for second context. Values to test are put on it as |
19882 // properties. | 19819 // properties. |
19883 Local<ObjectTemplate> global_template = ObjectTemplate::New(); | 19820 Local<ObjectTemplate> global_template = ObjectTemplate::New(); |
19884 global_template->Set(v8_str("simple"), simple_object); | 19821 global_template->Set(v8_str("simple"), simple_object); |
19885 global_template->Set(v8_str("protected"), protected_object); | 19822 global_template->Set(v8_str("protected"), protected_object); |
19886 global_template->Set(v8_str("global"), global_object); | 19823 global_template->Set(v8_str("global"), global_object); |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20275 isolate->Dispose(); | 20212 isolate->Dispose(); |
20276 } | 20213 } |
20277 | 20214 |
20278 | 20215 |
20279 TEST(StringEmpty) { | 20216 TEST(StringEmpty) { |
20280 LocalContext context; | 20217 LocalContext context; |
20281 i::Factory* factory = CcTest::i_isolate()->factory(); | 20218 i::Factory* factory = CcTest::i_isolate()->factory(); |
20282 v8::Isolate* isolate = CcTest::isolate(); | 20219 v8::Isolate* isolate = CcTest::isolate(); |
20283 v8::HandleScope scope(isolate); | 20220 v8::HandleScope scope(isolate); |
20284 i::Handle<i::Object> empty_string = factory->empty_string(); | 20221 i::Handle<i::Object> empty_string = factory->empty_string(); |
| 20222 CHECK(*v8::Utils::OpenHandle(*v8::String::Empty()) == *empty_string); |
20285 CHECK(*v8::Utils::OpenHandle(*v8::String::Empty(isolate)) == *empty_string); | 20223 CHECK(*v8::Utils::OpenHandle(*v8::String::Empty(isolate)) == *empty_string); |
20286 } | 20224 } |
20287 | 20225 |
20288 | 20226 |
20289 static int instance_checked_getter_count = 0; | 20227 static int instance_checked_getter_count = 0; |
20290 static void InstanceCheckedGetter( | 20228 static void InstanceCheckedGetter( |
20291 Local<String> name, | 20229 Local<String> name, |
20292 const v8::PropertyCallbackInfo<v8::Value>& info) { | 20230 const v8::PropertyCallbackInfo<v8::Value>& info) { |
20293 CHECK_EQ(name, v8_str("foo")); | 20231 CHECK_EQ(name, v8_str("foo")); |
20294 instance_checked_getter_count++; | 20232 instance_checked_getter_count++; |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20688 Local<Value> map_value = CompileRun("new Map();"); | 20626 Local<Value> map_value = CompileRun("new Map();"); |
20689 Local<Object> map_object(Local<Object>::Cast(map_value)); | 20627 Local<Object> map_object(Local<Object>::Cast(map_value)); |
20690 CHECK_EQ(0, map_object->InternalFieldCount()); | 20628 CHECK_EQ(0, map_object->InternalFieldCount()); |
20691 } | 20629 } |
20692 | 20630 |
20693 | 20631 |
20694 THREADED_TEST(Regress2746) { | 20632 THREADED_TEST(Regress2746) { |
20695 LocalContext context; | 20633 LocalContext context; |
20696 v8::Isolate* isolate = context->GetIsolate(); | 20634 v8::Isolate* isolate = context->GetIsolate(); |
20697 v8::HandleScope scope(isolate); | 20635 v8::HandleScope scope(isolate); |
20698 Local<Object> obj = Object::New(isolate); | 20636 Local<Object> obj = Object::New(); |
20699 Local<String> key = String::NewFromUtf8(context->GetIsolate(), "key"); | 20637 Local<String> key = String::NewFromUtf8(context->GetIsolate(), "key"); |
20700 obj->SetHiddenValue(key, v8::Undefined(isolate)); | 20638 obj->SetHiddenValue(key, v8::Undefined(isolate)); |
20701 Local<Value> value = obj->GetHiddenValue(key); | 20639 Local<Value> value = obj->GetHiddenValue(key); |
20702 CHECK(!value.IsEmpty()); | 20640 CHECK(!value.IsEmpty()); |
20703 CHECK(value->IsUndefined()); | 20641 CHECK(value->IsUndefined()); |
20704 } | 20642 } |
20705 | 20643 |
20706 | 20644 |
20707 THREADED_TEST(Regress260106) { | 20645 THREADED_TEST(Regress260106) { |
20708 LocalContext context; | 20646 LocalContext context; |
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21342 static void FunctionNewCallback(const v8::FunctionCallbackInfo<Value>& info) { | 21280 static void FunctionNewCallback(const v8::FunctionCallbackInfo<Value>& info) { |
21343 CHECK_EQ(function_new_expected_env, info.Data()); | 21281 CHECK_EQ(function_new_expected_env, info.Data()); |
21344 info.GetReturnValue().Set(17); | 21282 info.GetReturnValue().Set(17); |
21345 } | 21283 } |
21346 | 21284 |
21347 | 21285 |
21348 THREADED_TEST(FunctionNew) { | 21286 THREADED_TEST(FunctionNew) { |
21349 LocalContext env; | 21287 LocalContext env; |
21350 v8::Isolate* isolate = env->GetIsolate(); | 21288 v8::Isolate* isolate = env->GetIsolate(); |
21351 v8::HandleScope scope(isolate); | 21289 v8::HandleScope scope(isolate); |
21352 Local<Object> data = v8::Object::New(isolate); | 21290 Local<Object> data = v8::Object::New(); |
21353 function_new_expected_env = data; | 21291 function_new_expected_env = data; |
21354 Local<Function> func = Function::New(isolate, FunctionNewCallback, data); | 21292 Local<Function> func = Function::New(isolate, FunctionNewCallback, data); |
21355 env->Global()->Set(v8_str("func"), func); | 21293 env->Global()->Set(v8_str("func"), func); |
21356 Local<Value> result = CompileRun("func();"); | 21294 Local<Value> result = CompileRun("func();"); |
21357 CHECK_EQ(v8::Integer::New(isolate, 17), result); | 21295 CHECK_EQ(v8::Integer::New(17, isolate), result); |
21358 // Verify function not cached | 21296 // Verify function not cached |
21359 int serial_number = | 21297 int serial_number = |
21360 i::Smi::cast(v8::Utils::OpenHandle(*func) | 21298 i::Smi::cast(v8::Utils::OpenHandle(*func) |
21361 ->shared()->get_api_func_data()->serial_number())->value(); | 21299 ->shared()->get_api_func_data()->serial_number())->value(); |
21362 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 21300 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
21363 i::Object* elm = i_isolate->native_context()->function_cache() | 21301 i::Object* elm = i_isolate->native_context()->function_cache() |
21364 ->GetElementNoExceptionThrown(i_isolate, serial_number); | 21302 ->GetElementNoExceptionThrown(i_isolate, serial_number); |
21365 CHECK(elm->IsUndefined()); | 21303 CHECK(elm->IsUndefined()); |
21366 // Verify that each Function::New creates a new function instance | 21304 // Verify that each Function::New creates a new function instance |
21367 Local<Object> data2 = v8::Object::New(isolate); | 21305 Local<Object> data2 = v8::Object::New(); |
21368 function_new_expected_env = data2; | 21306 function_new_expected_env = data2; |
21369 Local<Function> func2 = Function::New(isolate, FunctionNewCallback, data2); | 21307 Local<Function> func2 = Function::New(isolate, FunctionNewCallback, data2); |
21370 CHECK(!func2->IsNull()); | 21308 CHECK(!func2->IsNull()); |
21371 CHECK_NE(func, func2); | 21309 CHECK_NE(func, func2); |
21372 env->Global()->Set(v8_str("func2"), func2); | 21310 env->Global()->Set(v8_str("func2"), func2); |
21373 Local<Value> result2 = CompileRun("func2();"); | 21311 Local<Value> result2 = CompileRun("func2();"); |
21374 CHECK_EQ(v8::Integer::New(isolate, 17), result2); | 21312 CHECK_EQ(v8::Integer::New(17, isolate), result2); |
21375 } | 21313 } |
21376 | 21314 |
21377 | 21315 |
21378 TEST(EscapeableHandleScope) { | 21316 TEST(EscapeableHandleScope) { |
21379 HandleScope outer_scope(CcTest::isolate()); | 21317 HandleScope outer_scope(CcTest::isolate()); |
21380 LocalContext context; | 21318 LocalContext context; |
21381 const int runs = 10; | 21319 const int runs = 10; |
21382 Local<String> values[runs]; | 21320 Local<String> values[runs]; |
21383 for (int i = 0; i < runs; i++) { | 21321 for (int i = 0; i < runs; i++) { |
21384 v8::EscapableHandleScope inner_scope(CcTest::isolate()); | 21322 v8::EscapableHandleScope inner_scope(CcTest::isolate()); |
21385 Local<String> value; | 21323 Local<String> value; |
21386 if (i != 0) value = v8_str("escape value"); | 21324 if (i != 0) value = v8_str("escape value"); |
21387 values[i] = inner_scope.Escape(value); | 21325 values[i] = inner_scope.Escape(value); |
21388 } | 21326 } |
21389 for (int i = 0; i < runs; i++) { | 21327 for (int i = 0; i < runs; i++) { |
21390 Local<String> expected; | 21328 Local<String> expected; |
21391 if (i != 0) { | 21329 if (i != 0) { |
21392 CHECK_EQ(v8_str("escape value"), values[i]); | 21330 CHECK_EQ(v8_str("escape value"), values[i]); |
21393 } else { | 21331 } else { |
21394 CHECK(values[i].IsEmpty()); | 21332 CHECK(values[i].IsEmpty()); |
21395 } | 21333 } |
21396 } | 21334 } |
21397 } | 21335 } |
OLD | NEW |