| OLD | NEW |
| 1 // Copyright 2007-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2009 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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 CHECK(foo_before->IsUndefined()); | 257 CHECK(foo_before->IsUndefined()); |
| 258 Local<String> bar_str = v8_str("bar"); | 258 Local<String> bar_str = v8_str("bar"); |
| 259 obj->Set(v8_str("foo"), bar_str); | 259 obj->Set(v8_str("foo"), bar_str); |
| 260 Local<Value> foo_after = obj->Get(v8_str("foo")); | 260 Local<Value> foo_after = obj->Get(v8_str("foo")); |
| 261 CHECK(!foo_after->IsUndefined()); | 261 CHECK(!foo_after->IsUndefined()); |
| 262 CHECK(foo_after->IsString()); | 262 CHECK(foo_after->IsString()); |
| 263 CHECK_EQ(bar_str, foo_after); | 263 CHECK_EQ(bar_str, foo_after); |
| 264 } | 264 } |
| 265 | 265 |
| 266 | 266 |
| 267 THREADED_TEST(AccessElement) { |
| 268 v8::HandleScope scope; |
| 269 LocalContext env; |
| 270 Local<v8::Object> obj = v8::Object::New(); |
| 271 Local<Value> before = obj->Get(1); |
| 272 CHECK(before->IsUndefined()); |
| 273 Local<String> bar_str = v8_str("bar"); |
| 274 obj->Set(1, bar_str); |
| 275 Local<Value> after = obj->Get(1); |
| 276 CHECK(!after->IsUndefined()); |
| 277 CHECK(after->IsString()); |
| 278 CHECK_EQ(bar_str, after); |
| 279 |
| 280 Local<v8::Array> value = CompileRun("[\"a\", \"b\"]").As<v8::Array>(); |
| 281 CHECK_EQ(v8_str("a"), value->Get(0)); |
| 282 CHECK_EQ(v8_str("b"), value->Get(1)); |
| 283 } |
| 284 |
| 285 |
| 267 THREADED_TEST(Script) { | 286 THREADED_TEST(Script) { |
| 268 v8::HandleScope scope; | 287 v8::HandleScope scope; |
| 269 LocalContext env; | 288 LocalContext env; |
| 270 const char* c_source = "1 + 2 + 3"; | 289 const char* c_source = "1 + 2 + 3"; |
| 271 Local<String> source = String::New(c_source); | 290 Local<String> source = String::New(c_source); |
| 272 Local<Script> script = Script::Compile(source); | 291 Local<Script> script = Script::Compile(source); |
| 273 CHECK_EQ(6, script->Run()->Int32Value()); | 292 CHECK_EQ(6, script->Run()->Int32Value()); |
| 274 } | 293 } |
| 275 | 294 |
| 276 | 295 |
| (...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1247 const v8::Arguments& args) { | 1266 const v8::Arguments& args) { |
| 1248 ApiTestFuzzer::Fuzz(); | 1267 ApiTestFuzzer::Fuzz(); |
| 1249 int depth = args.This()->Get(v8_str("depth"))->Int32Value(); | 1268 int depth = args.This()->Get(v8_str("depth"))->Int32Value(); |
| 1250 if (depth == kTargetRecursionDepth) { | 1269 if (depth == kTargetRecursionDepth) { |
| 1251 printf("[depth = %d]\n", depth); | 1270 printf("[depth = %d]\n", depth); |
| 1252 return v8::Undefined(); | 1271 return v8::Undefined(); |
| 1253 } | 1272 } |
| 1254 args.This()->Set(v8_str("depth"), v8::Integer::New(depth + 1)); | 1273 args.This()->Set(v8_str("depth"), v8::Integer::New(depth + 1)); |
| 1255 v8::Handle<Value> function = | 1274 v8::Handle<Value> function = |
| 1256 args.This()->Get(v8_str("callFunctionRecursively")); | 1275 args.This()->Get(v8_str("callFunctionRecursively")); |
| 1257 return v8::Handle<Function>::Cast(function)->Call(args.This(), 0, NULL); | 1276 return function.As<Function>()->Call(args.This(), 0, NULL); |
| 1258 } | 1277 } |
| 1259 | 1278 |
| 1260 | 1279 |
| 1261 THREADED_TEST(DeepCrossLanguageRecursion) { | 1280 THREADED_TEST(DeepCrossLanguageRecursion) { |
| 1262 v8::HandleScope scope; | 1281 v8::HandleScope scope; |
| 1263 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(); | 1282 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(); |
| 1264 global->Set(v8_str("callScriptRecursively"), | 1283 global->Set(v8_str("callScriptRecursively"), |
| 1265 v8::FunctionTemplate::New(CallScriptRecursivelyCall)); | 1284 v8::FunctionTemplate::New(CallScriptRecursivelyCall)); |
| 1266 global->Set(v8_str("callFunctionRecursively"), | 1285 global->Set(v8_str("callFunctionRecursively"), |
| 1267 v8::FunctionTemplate::New(CallFunctionRecursivelyCall)); | 1286 v8::FunctionTemplate::New(CallFunctionRecursivelyCall)); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1327 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate(); | 1346 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate(); |
| 1328 instance_templ->SetInternalFieldCount(1); | 1347 instance_templ->SetInternalFieldCount(1); |
| 1329 Local<v8::Object> obj = templ->GetFunction()->NewInstance(); | 1348 Local<v8::Object> obj = templ->GetFunction()->NewInstance(); |
| 1330 CHECK_EQ(1, obj->InternalFieldCount()); | 1349 CHECK_EQ(1, obj->InternalFieldCount()); |
| 1331 CHECK(obj->GetInternalField(0)->IsUndefined()); | 1350 CHECK(obj->GetInternalField(0)->IsUndefined()); |
| 1332 obj->SetInternalField(0, v8_num(17)); | 1351 obj->SetInternalField(0, v8_num(17)); |
| 1333 CHECK_EQ(17, obj->GetInternalField(0)->Int32Value()); | 1352 CHECK_EQ(17, obj->GetInternalField(0)->Int32Value()); |
| 1334 } | 1353 } |
| 1335 | 1354 |
| 1336 | 1355 |
| 1356 THREADED_TEST(GlobalObjectInternalFields) { |
| 1357 v8::HandleScope scope; |
| 1358 Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); |
| 1359 global_template->SetInternalFieldCount(1); |
| 1360 LocalContext env(NULL, global_template); |
| 1361 v8::Handle<v8::Object> global_proxy = env->Global(); |
| 1362 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); |
| 1363 CHECK_EQ(1, global->InternalFieldCount()); |
| 1364 CHECK(global->GetInternalField(0)->IsUndefined()); |
| 1365 global->SetInternalField(0, v8_num(17)); |
| 1366 CHECK_EQ(17, global->GetInternalField(0)->Int32Value()); |
| 1367 } |
| 1368 |
| 1369 |
| 1337 THREADED_TEST(InternalFieldsNativePointers) { | 1370 THREADED_TEST(InternalFieldsNativePointers) { |
| 1338 v8::HandleScope scope; | 1371 v8::HandleScope scope; |
| 1339 LocalContext env; | 1372 LocalContext env; |
| 1340 | 1373 |
| 1341 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); | 1374 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); |
| 1342 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate(); | 1375 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate(); |
| 1343 instance_templ->SetInternalFieldCount(1); | 1376 instance_templ->SetInternalFieldCount(1); |
| 1344 Local<v8::Object> obj = templ->GetFunction()->NewInstance(); | 1377 Local<v8::Object> obj = templ->GetFunction()->NewInstance(); |
| 1345 CHECK_EQ(1, obj->InternalFieldCount()); | 1378 CHECK_EQ(1, obj->InternalFieldCount()); |
| 1346 CHECK(obj->GetPointerFromInternalField(0) == NULL); | 1379 CHECK(obj->GetPointerFromInternalField(0) == NULL); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1507 } | 1540 } |
| 1508 | 1541 |
| 1509 | 1542 |
| 1510 THREADED_TEST(External) { | 1543 THREADED_TEST(External) { |
| 1511 v8::HandleScope scope; | 1544 v8::HandleScope scope; |
| 1512 int x = 3; | 1545 int x = 3; |
| 1513 Local<v8::External> ext = v8::External::New(&x); | 1546 Local<v8::External> ext = v8::External::New(&x); |
| 1514 LocalContext env; | 1547 LocalContext env; |
| 1515 env->Global()->Set(v8_str("ext"), ext); | 1548 env->Global()->Set(v8_str("ext"), ext); |
| 1516 Local<Value> reext_obj = Script::Compile(v8_str("this.ext"))->Run(); | 1549 Local<Value> reext_obj = Script::Compile(v8_str("this.ext"))->Run(); |
| 1517 v8::Handle<v8::External> reext = v8::Handle<v8::External>::Cast(reext_obj); | 1550 v8::Handle<v8::External> reext = reext_obj.As<v8::External>(); |
| 1518 int* ptr = static_cast<int*>(reext->Value()); | 1551 int* ptr = static_cast<int*>(reext->Value()); |
| 1519 CHECK_EQ(x, 3); | 1552 CHECK_EQ(x, 3); |
| 1520 *ptr = 10; | 1553 *ptr = 10; |
| 1521 CHECK_EQ(x, 10); | 1554 CHECK_EQ(x, 10); |
| 1522 | 1555 |
| 1523 // Make sure unaligned pointers are wrapped properly. | 1556 // Make sure unaligned pointers are wrapped properly. |
| 1524 char* data = i::StrDup("0123456789"); | 1557 char* data = i::StrDup("0123456789"); |
| 1525 Local<v8::Value> zero = v8::External::Wrap(&data[0]); | 1558 Local<v8::Value> zero = v8::External::Wrap(&data[0]); |
| 1526 Local<v8::Value> one = v8::External::Wrap(&data[1]); | 1559 Local<v8::Value> one = v8::External::Wrap(&data[1]); |
| 1527 Local<v8::Value> two = v8::External::Wrap(&data[2]); | 1560 Local<v8::Value> two = v8::External::Wrap(&data[2]); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1639 Script::Compile(v8_str("delete dont_delete"))->Run(); | 1672 Script::Compile(v8_str("delete dont_delete"))->Run(); |
| 1640 CHECK_EQ(13, context->Global()->Get(prop)->Int32Value()); | 1673 CHECK_EQ(13, context->Global()->Get(prop)->Int32Value()); |
| 1641 } | 1674 } |
| 1642 | 1675 |
| 1643 | 1676 |
| 1644 THREADED_TEST(Array) { | 1677 THREADED_TEST(Array) { |
| 1645 v8::HandleScope scope; | 1678 v8::HandleScope scope; |
| 1646 LocalContext context; | 1679 LocalContext context; |
| 1647 Local<v8::Array> array = v8::Array::New(); | 1680 Local<v8::Array> array = v8::Array::New(); |
| 1648 CHECK_EQ(0, array->Length()); | 1681 CHECK_EQ(0, array->Length()); |
| 1649 CHECK(array->Get(v8::Integer::New(0))->IsUndefined()); | 1682 CHECK(array->Get(0)->IsUndefined()); |
| 1650 CHECK(!array->Has(0)); | 1683 CHECK(!array->Has(0)); |
| 1651 CHECK(array->Get(v8::Integer::New(100))->IsUndefined()); | 1684 CHECK(array->Get(100)->IsUndefined()); |
| 1652 CHECK(!array->Has(100)); | 1685 CHECK(!array->Has(100)); |
| 1653 array->Set(v8::Integer::New(2), v8_num(7)); | 1686 array->Set(2, v8_num(7)); |
| 1654 CHECK_EQ(3, array->Length()); | 1687 CHECK_EQ(3, array->Length()); |
| 1655 CHECK(!array->Has(0)); | 1688 CHECK(!array->Has(0)); |
| 1656 CHECK(!array->Has(1)); | 1689 CHECK(!array->Has(1)); |
| 1657 CHECK(array->Has(2)); | 1690 CHECK(array->Has(2)); |
| 1658 CHECK_EQ(7, array->Get(v8::Integer::New(2))->Int32Value()); | 1691 CHECK_EQ(7, array->Get(2)->Int32Value()); |
| 1659 Local<Value> obj = Script::Compile(v8_str("[1, 2, 3]"))->Run(); | 1692 Local<Value> obj = Script::Compile(v8_str("[1, 2, 3]"))->Run(); |
| 1660 Local<v8::Array> arr = Local<v8::Array>::Cast(obj); | 1693 Local<v8::Array> arr = obj.As<v8::Array>(); |
| 1661 CHECK_EQ(3, arr->Length()); | 1694 CHECK_EQ(3, arr->Length()); |
| 1662 CHECK_EQ(1, arr->Get(v8::Integer::New(0))->Int32Value()); | 1695 CHECK_EQ(1, arr->Get(0)->Int32Value()); |
| 1663 CHECK_EQ(2, arr->Get(v8::Integer::New(1))->Int32Value()); | 1696 CHECK_EQ(2, arr->Get(1)->Int32Value()); |
| 1664 CHECK_EQ(3, arr->Get(v8::Integer::New(2))->Int32Value()); | 1697 CHECK_EQ(3, arr->Get(2)->Int32Value()); |
| 1665 } | 1698 } |
| 1666 | 1699 |
| 1667 | 1700 |
| 1668 v8::Handle<Value> HandleF(const v8::Arguments& args) { | 1701 v8::Handle<Value> HandleF(const v8::Arguments& args) { |
| 1669 v8::HandleScope scope; | 1702 v8::HandleScope scope; |
| 1670 ApiTestFuzzer::Fuzz(); | 1703 ApiTestFuzzer::Fuzz(); |
| 1671 Local<v8::Array> result = v8::Array::New(args.Length()); | 1704 Local<v8::Array> result = v8::Array::New(args.Length()); |
| 1672 for (int i = 0; i < args.Length(); i++) | 1705 for (int i = 0; i < args.Length(); i++) |
| 1673 result->Set(v8::Integer::New(i), args[i]); | 1706 result->Set(i, args[i]); |
| 1674 return scope.Close(result); | 1707 return scope.Close(result); |
| 1675 } | 1708 } |
| 1676 | 1709 |
| 1677 | 1710 |
| 1678 THREADED_TEST(Vector) { | 1711 THREADED_TEST(Vector) { |
| 1679 v8::HandleScope scope; | 1712 v8::HandleScope scope; |
| 1680 Local<ObjectTemplate> global = ObjectTemplate::New(); | 1713 Local<ObjectTemplate> global = ObjectTemplate::New(); |
| 1681 global->Set(v8_str("f"), v8::FunctionTemplate::New(HandleF)); | 1714 global->Set(v8_str("f"), v8::FunctionTemplate::New(HandleF)); |
| 1682 LocalContext context(0, global); | 1715 LocalContext context(0, global); |
| 1683 | 1716 |
| 1684 const char* fun = "f()"; | 1717 const char* fun = "f()"; |
| 1685 Local<v8::Array> a0 = | 1718 Local<v8::Array> a0 = CompileRun(fun).As<v8::Array>(); |
| 1686 Local<v8::Array>::Cast(Script::Compile(String::New(fun))->Run()); | |
| 1687 CHECK_EQ(0, a0->Length()); | 1719 CHECK_EQ(0, a0->Length()); |
| 1688 | 1720 |
| 1689 const char* fun2 = "f(11)"; | 1721 const char* fun2 = "f(11)"; |
| 1690 Local<v8::Array> a1 = | 1722 Local<v8::Array> a1 = CompileRun(fun2).As<v8::Array>(); |
| 1691 Local<v8::Array>::Cast(Script::Compile(String::New(fun2))->Run()); | |
| 1692 CHECK_EQ(1, a1->Length()); | 1723 CHECK_EQ(1, a1->Length()); |
| 1693 CHECK_EQ(11, a1->Get(v8::Integer::New(0))->Int32Value()); | 1724 CHECK_EQ(11, a1->Get(0)->Int32Value()); |
| 1694 | 1725 |
| 1695 const char* fun3 = "f(12, 13)"; | 1726 const char* fun3 = "f(12, 13)"; |
| 1696 Local<v8::Array> a2 = | 1727 Local<v8::Array> a2 = CompileRun(fun3).As<v8::Array>(); |
| 1697 Local<v8::Array>::Cast(Script::Compile(String::New(fun3))->Run()); | |
| 1698 CHECK_EQ(2, a2->Length()); | 1728 CHECK_EQ(2, a2->Length()); |
| 1699 CHECK_EQ(12, a2->Get(v8::Integer::New(0))->Int32Value()); | 1729 CHECK_EQ(12, a2->Get(0)->Int32Value()); |
| 1700 CHECK_EQ(13, a2->Get(v8::Integer::New(1))->Int32Value()); | 1730 CHECK_EQ(13, a2->Get(1)->Int32Value()); |
| 1701 | 1731 |
| 1702 const char* fun4 = "f(14, 15, 16)"; | 1732 const char* fun4 = "f(14, 15, 16)"; |
| 1703 Local<v8::Array> a3 = | 1733 Local<v8::Array> a3 = CompileRun(fun4).As<v8::Array>(); |
| 1704 Local<v8::Array>::Cast(Script::Compile(String::New(fun4))->Run()); | |
| 1705 CHECK_EQ(3, a3->Length()); | 1734 CHECK_EQ(3, a3->Length()); |
| 1706 CHECK_EQ(14, a3->Get(v8::Integer::New(0))->Int32Value()); | 1735 CHECK_EQ(14, a3->Get(0)->Int32Value()); |
| 1707 CHECK_EQ(15, a3->Get(v8::Integer::New(1))->Int32Value()); | 1736 CHECK_EQ(15, a3->Get(1)->Int32Value()); |
| 1708 CHECK_EQ(16, a3->Get(v8::Integer::New(2))->Int32Value()); | 1737 CHECK_EQ(16, a3->Get(2)->Int32Value()); |
| 1709 | 1738 |
| 1710 const char* fun5 = "f(17, 18, 19, 20)"; | 1739 const char* fun5 = "f(17, 18, 19, 20)"; |
| 1711 Local<v8::Array> a4 = | 1740 Local<v8::Array> a4 = CompileRun(fun5).As<v8::Array>(); |
| 1712 Local<v8::Array>::Cast(Script::Compile(String::New(fun5))->Run()); | |
| 1713 CHECK_EQ(4, a4->Length()); | 1741 CHECK_EQ(4, a4->Length()); |
| 1714 CHECK_EQ(17, a4->Get(v8::Integer::New(0))->Int32Value()); | 1742 CHECK_EQ(17, a4->Get(0)->Int32Value()); |
| 1715 CHECK_EQ(18, a4->Get(v8::Integer::New(1))->Int32Value()); | 1743 CHECK_EQ(18, a4->Get(1)->Int32Value()); |
| 1716 CHECK_EQ(19, a4->Get(v8::Integer::New(2))->Int32Value()); | 1744 CHECK_EQ(19, a4->Get(2)->Int32Value()); |
| 1717 CHECK_EQ(20, a4->Get(v8::Integer::New(3))->Int32Value()); | 1745 CHECK_EQ(20, a4->Get(3)->Int32Value()); |
| 1718 } | 1746 } |
| 1719 | 1747 |
| 1720 | 1748 |
| 1721 THREADED_TEST(FunctionCall) { | 1749 THREADED_TEST(FunctionCall) { |
| 1722 v8::HandleScope scope; | 1750 v8::HandleScope scope; |
| 1723 LocalContext context; | 1751 LocalContext context; |
| 1724 CompileRun( | 1752 CompileRun( |
| 1725 "function Foo() {" | 1753 "function Foo() {" |
| 1726 " var result = [];" | 1754 " var result = [];" |
| 1727 " for (var i = 0; i < arguments.length; i++) {" | 1755 " for (var i = 0; i < arguments.length; i++) {" |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1925 | 1953 |
| 1926 | 1954 |
| 1927 static void CheckUncle(v8::TryCatch* try_catch) { | 1955 static void CheckUncle(v8::TryCatch* try_catch) { |
| 1928 CHECK(try_catch->HasCaught()); | 1956 CHECK(try_catch->HasCaught()); |
| 1929 String::AsciiValue str_value(try_catch->Exception()); | 1957 String::AsciiValue str_value(try_catch->Exception()); |
| 1930 CHECK_EQ(*str_value, "uncle?"); | 1958 CHECK_EQ(*str_value, "uncle?"); |
| 1931 try_catch->Reset(); | 1959 try_catch->Reset(); |
| 1932 } | 1960 } |
| 1933 | 1961 |
| 1934 | 1962 |
| 1963 THREADED_TEST(ConversionNumber) { |
| 1964 v8::HandleScope scope; |
| 1965 LocalContext env; |
| 1966 // Very large number. |
| 1967 CompileRun("var obj = Math.pow(2,32) * 1237;"); |
| 1968 Local<Value> obj = env->Global()->Get(v8_str("obj")); |
| 1969 CHECK_EQ(5312874545152.0, obj->ToNumber()->Value()); |
| 1970 CHECK_EQ(0, obj->ToInt32()->Value()); |
| 1971 CHECK(0u == obj->ToUint32()->Value()); // NOLINT - no CHECK_EQ for unsigned. |
| 1972 // Large number. |
| 1973 CompileRun("var obj = -1234567890123;"); |
| 1974 obj = env->Global()->Get(v8_str("obj")); |
| 1975 CHECK_EQ(-1234567890123.0, obj->ToNumber()->Value()); |
| 1976 CHECK_EQ(-1912276171, obj->ToInt32()->Value()); |
| 1977 CHECK(2382691125u == obj->ToUint32()->Value()); // NOLINT |
| 1978 // Small positive integer. |
| 1979 CompileRun("var obj = 42;"); |
| 1980 obj = env->Global()->Get(v8_str("obj")); |
| 1981 CHECK_EQ(42.0, obj->ToNumber()->Value()); |
| 1982 CHECK_EQ(42, obj->ToInt32()->Value()); |
| 1983 CHECK(42u == obj->ToUint32()->Value()); // NOLINT |
| 1984 // Negative integer. |
| 1985 CompileRun("var obj = -37;"); |
| 1986 obj = env->Global()->Get(v8_str("obj")); |
| 1987 CHECK_EQ(-37.0, obj->ToNumber()->Value()); |
| 1988 CHECK_EQ(-37, obj->ToInt32()->Value()); |
| 1989 CHECK(4294967259u == obj->ToUint32()->Value()); // NOLINT |
| 1990 // Positive non-int32 integer. |
| 1991 CompileRun("var obj = 0x81234567;"); |
| 1992 obj = env->Global()->Get(v8_str("obj")); |
| 1993 CHECK_EQ(2166572391.0, obj->ToNumber()->Value()); |
| 1994 CHECK_EQ(-2128394905, obj->ToInt32()->Value()); |
| 1995 CHECK(2166572391u == obj->ToUint32()->Value()); // NOLINT |
| 1996 // Fraction. |
| 1997 CompileRun("var obj = 42.3;"); |
| 1998 obj = env->Global()->Get(v8_str("obj")); |
| 1999 CHECK_EQ(42.3, obj->ToNumber()->Value()); |
| 2000 CHECK_EQ(42, obj->ToInt32()->Value()); |
| 2001 CHECK(42u == obj->ToUint32()->Value()); // NOLINT |
| 2002 // Large negative fraction. |
| 2003 CompileRun("var obj = -5726623061.75;"); |
| 2004 obj = env->Global()->Get(v8_str("obj")); |
| 2005 CHECK_EQ(-5726623061.75, obj->ToNumber()->Value()); |
| 2006 CHECK_EQ(-1431655765, obj->ToInt32()->Value()); |
| 2007 CHECK(2863311531u == obj->ToUint32()->Value()); // NOLINT |
| 2008 } |
| 2009 |
| 2010 |
| 2011 THREADED_TEST(isNumberType) { |
| 2012 v8::HandleScope scope; |
| 2013 LocalContext env; |
| 2014 // Very large number. |
| 2015 CompileRun("var obj = Math.pow(2,32) * 1237;"); |
| 2016 Local<Value> obj = env->Global()->Get(v8_str("obj")); |
| 2017 CHECK(!obj->IsInt32()); |
| 2018 CHECK(!obj->IsUint32()); |
| 2019 // Large negative number. |
| 2020 CompileRun("var obj = -1234567890123;"); |
| 2021 obj = env->Global()->Get(v8_str("obj")); |
| 2022 CHECK(!obj->IsInt32()); |
| 2023 CHECK(!obj->IsUint32()); |
| 2024 // Small positive integer. |
| 2025 CompileRun("var obj = 42;"); |
| 2026 obj = env->Global()->Get(v8_str("obj")); |
| 2027 CHECK(obj->IsInt32()); |
| 2028 CHECK(obj->IsUint32()); |
| 2029 // Negative integer. |
| 2030 CompileRun("var obj = -37;"); |
| 2031 obj = env->Global()->Get(v8_str("obj")); |
| 2032 CHECK(obj->IsInt32()); |
| 2033 CHECK(!obj->IsUint32()); |
| 2034 // Positive non-int32 integer. |
| 2035 CompileRun("var obj = 0x81234567;"); |
| 2036 obj = env->Global()->Get(v8_str("obj")); |
| 2037 CHECK(!obj->IsInt32()); |
| 2038 CHECK(obj->IsUint32()); |
| 2039 // Fraction. |
| 2040 CompileRun("var obj = 42.3;"); |
| 2041 obj = env->Global()->Get(v8_str("obj")); |
| 2042 CHECK(!obj->IsInt32()); |
| 2043 CHECK(!obj->IsUint32()); |
| 2044 // Large negative fraction. |
| 2045 CompileRun("var obj = -5726623061.75;"); |
| 2046 obj = env->Global()->Get(v8_str("obj")); |
| 2047 CHECK(!obj->IsInt32()); |
| 2048 CHECK(!obj->IsUint32()); |
| 2049 } |
| 2050 |
| 2051 |
| 1935 THREADED_TEST(ConversionException) { | 2052 THREADED_TEST(ConversionException) { |
| 1936 v8::HandleScope scope; | 2053 v8::HandleScope scope; |
| 1937 LocalContext env; | 2054 LocalContext env; |
| 1938 CompileRun( | 2055 CompileRun( |
| 1939 "function TestClass() { };" | 2056 "function TestClass() { };" |
| 1940 "TestClass.prototype.toString = function () { throw 'uncle?'; };" | 2057 "TestClass.prototype.toString = function () { throw 'uncle?'; };" |
| 1941 "var obj = new TestClass();"); | 2058 "var obj = new TestClass();"); |
| 1942 Local<Value> obj = env->Global()->Get(v8_str("obj")); | 2059 Local<Value> obj = env->Global()->Get(v8_str("obj")); |
| 1943 | 2060 |
| 1944 v8::TryCatch try_catch; | 2061 v8::TryCatch try_catch; |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2123 return v8::ThrowException(v8_str("FromC")); | 2240 return v8::ThrowException(v8_str("FromC")); |
| 2124 } else { | 2241 } else { |
| 2125 Local<v8::Object> global = Context::GetCurrent()->Global(); | 2242 Local<v8::Object> global = Context::GetCurrent()->Global(); |
| 2126 Local<Value> fun = global->Get(v8_str("JSThrowCountDown")); | 2243 Local<Value> fun = global->Get(v8_str("JSThrowCountDown")); |
| 2127 v8::Handle<Value> argv[] = { v8_num(count - 1), | 2244 v8::Handle<Value> argv[] = { v8_num(count - 1), |
| 2128 args[1], | 2245 args[1], |
| 2129 args[2], | 2246 args[2], |
| 2130 args[3] }; | 2247 args[3] }; |
| 2131 if (count % cInterval == 0) { | 2248 if (count % cInterval == 0) { |
| 2132 v8::TryCatch try_catch; | 2249 v8::TryCatch try_catch; |
| 2133 Local<Value> result = | 2250 Local<Value> result = fun.As<Function>()->Call(global, 4, argv); |
| 2134 v8::Handle<Function>::Cast(fun)->Call(global, 4, argv); | |
| 2135 int expected = args[3]->Int32Value(); | 2251 int expected = args[3]->Int32Value(); |
| 2136 if (try_catch.HasCaught()) { | 2252 if (try_catch.HasCaught()) { |
| 2137 CHECK_EQ(expected, count); | 2253 CHECK_EQ(expected, count); |
| 2138 CHECK(result.IsEmpty()); | 2254 CHECK(result.IsEmpty()); |
| 2139 CHECK(!i::Top::has_scheduled_exception()); | 2255 CHECK(!i::Top::has_scheduled_exception()); |
| 2140 } else { | 2256 } else { |
| 2141 CHECK_NE(expected, count); | 2257 CHECK_NE(expected, count); |
| 2142 } | 2258 } |
| 2143 return result; | 2259 return result; |
| 2144 } else { | 2260 } else { |
| 2145 return v8::Handle<Function>::Cast(fun)->Call(global, 4, argv); | 2261 return fun.As<Function>()->Call(global, 4, argv); |
| 2146 } | 2262 } |
| 2147 } | 2263 } |
| 2148 } | 2264 } |
| 2149 | 2265 |
| 2150 | 2266 |
| 2151 v8::Handle<Value> JSCheck(const v8::Arguments& args) { | 2267 v8::Handle<Value> JSCheck(const v8::Arguments& args) { |
| 2152 ApiTestFuzzer::Fuzz(); | 2268 ApiTestFuzzer::Fuzz(); |
| 2153 CHECK_EQ(3, args.Length()); | 2269 CHECK_EQ(3, args.Length()); |
| 2154 bool equality = args[0]->BooleanValue(); | 2270 bool equality = args[0]->BooleanValue(); |
| 2155 int count = args[1]->Int32Value(); | 2271 int count = args[1]->Int32Value(); |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2525 Local<Value> result = script->Run(); | 2641 Local<Value> result = script->Run(); |
| 2526 CHECK_EQ(result, v8_str("x")); | 2642 CHECK_EQ(result, v8_str("x")); |
| 2527 } | 2643 } |
| 2528 } | 2644 } |
| 2529 | 2645 |
| 2530 | 2646 |
| 2531 static v8::Handle<Value> SetXOnPrototypeGetter(Local<String> property, | 2647 static v8::Handle<Value> SetXOnPrototypeGetter(Local<String> property, |
| 2532 const AccessorInfo& info) { | 2648 const AccessorInfo& info) { |
| 2533 // Set x on the prototype object and do not handle the get request. | 2649 // Set x on the prototype object and do not handle the get request. |
| 2534 v8::Handle<v8::Value> proto = info.Holder()->GetPrototype(); | 2650 v8::Handle<v8::Value> proto = info.Holder()->GetPrototype(); |
| 2535 v8::Handle<v8::Object>::Cast(proto)->Set(v8_str("x"), v8::Integer::New(23)); | 2651 proto.As<v8::Object>()->Set(v8_str("x"), v8::Integer::New(23)); |
| 2536 return v8::Handle<Value>(); | 2652 return v8::Handle<Value>(); |
| 2537 } | 2653 } |
| 2538 | 2654 |
| 2539 | 2655 |
| 2540 // This is a regression test for http://crbug.com/20104. Map | 2656 // This is a regression test for http://crbug.com/20104. Map |
| 2541 // transitions should not interfere with post interceptor lookup. | 2657 // transitions should not interfere with post interceptor lookup. |
| 2542 THREADED_TEST(NamedInterceptorMapTransitionRead) { | 2658 THREADED_TEST(NamedInterceptorMapTransitionRead) { |
| 2543 v8::HandleScope scope; | 2659 v8::HandleScope scope; |
| 2544 Local<v8::FunctionTemplate> function_template = v8::FunctionTemplate::New(); | 2660 Local<v8::FunctionTemplate> function_template = v8::FunctionTemplate::New(); |
| 2545 Local<v8::ObjectTemplate> instance_template | 2661 Local<v8::ObjectTemplate> instance_template |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2861 THREADED_TEST(FunctionPrototypeAcrossContexts) { | 2977 THREADED_TEST(FunctionPrototypeAcrossContexts) { |
| 2862 // Make sure that functions created by cloning boilerplates cannot | 2978 // Make sure that functions created by cloning boilerplates cannot |
| 2863 // communicate through their __proto__ field. | 2979 // communicate through their __proto__ field. |
| 2864 | 2980 |
| 2865 v8::HandleScope scope; | 2981 v8::HandleScope scope; |
| 2866 | 2982 |
| 2867 LocalContext env0; | 2983 LocalContext env0; |
| 2868 v8::Handle<v8::Object> global0 = | 2984 v8::Handle<v8::Object> global0 = |
| 2869 env0->Global(); | 2985 env0->Global(); |
| 2870 v8::Handle<v8::Object> object0 = | 2986 v8::Handle<v8::Object> object0 = |
| 2871 v8::Handle<v8::Object>::Cast(global0->Get(v8_str("Object"))); | 2987 global0->Get(v8_str("Object")).As<v8::Object>(); |
| 2872 v8::Handle<v8::Object> tostring0 = | 2988 v8::Handle<v8::Object> tostring0 = |
| 2873 v8::Handle<v8::Object>::Cast(object0->Get(v8_str("toString"))); | 2989 object0->Get(v8_str("toString")).As<v8::Object>(); |
| 2874 v8::Handle<v8::Object> proto0 = | 2990 v8::Handle<v8::Object> proto0 = |
| 2875 v8::Handle<v8::Object>::Cast(tostring0->Get(v8_str("__proto__"))); | 2991 tostring0->Get(v8_str("__proto__")).As<v8::Object>(); |
| 2876 proto0->Set(v8_str("custom"), v8_num(1234)); | 2992 proto0->Set(v8_str("custom"), v8_num(1234)); |
| 2877 | 2993 |
| 2878 LocalContext env1; | 2994 LocalContext env1; |
| 2879 v8::Handle<v8::Object> global1 = | 2995 v8::Handle<v8::Object> global1 = |
| 2880 env1->Global(); | 2996 env1->Global(); |
| 2881 v8::Handle<v8::Object> object1 = | 2997 v8::Handle<v8::Object> object1 = |
| 2882 v8::Handle<v8::Object>::Cast(global1->Get(v8_str("Object"))); | 2998 global1->Get(v8_str("Object")).As<v8::Object>(); |
| 2883 v8::Handle<v8::Object> tostring1 = | 2999 v8::Handle<v8::Object> tostring1 = |
| 2884 v8::Handle<v8::Object>::Cast(object1->Get(v8_str("toString"))); | 3000 object1->Get(v8_str("toString")).As<v8::Object>(); |
| 2885 v8::Handle<v8::Object> proto1 = | 3001 v8::Handle<v8::Object> proto1 = |
| 2886 v8::Handle<v8::Object>::Cast(tostring1->Get(v8_str("__proto__"))); | 3002 tostring1->Get(v8_str("__proto__")).As<v8::Object>(); |
| 2887 CHECK(!proto1->Has(v8_str("custom"))); | 3003 CHECK(!proto1->Has(v8_str("custom"))); |
| 2888 } | 3004 } |
| 2889 | 3005 |
| 2890 | 3006 |
| 2891 THREADED_TEST(Regress892105) { | 3007 THREADED_TEST(Regress892105) { |
| 2892 // Make sure that object and array literals created by cloning | 3008 // Make sure that object and array literals created by cloning |
| 2893 // boilerplates cannot communicate through their __proto__ | 3009 // boilerplates cannot communicate through their __proto__ |
| 2894 // field. This is rather difficult to check, but we try to add stuff | 3010 // field. This is rather difficult to check, but we try to add stuff |
| 2895 // to Object.prototype and Array.prototype and create a new | 3011 // to Object.prototype and Array.prototype and create a new |
| 2896 // environment. This should succeed. | 3012 // environment. This should succeed. |
| (...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3498 i::Heap::CollectAllGarbage(false); | 3614 i::Heap::CollectAllGarbage(false); |
| 3499 return v8::Undefined(); | 3615 return v8::Undefined(); |
| 3500 } | 3616 } |
| 3501 | 3617 |
| 3502 | 3618 |
| 3503 THREADED_TEST(Arguments) { | 3619 THREADED_TEST(Arguments) { |
| 3504 v8::HandleScope scope; | 3620 v8::HandleScope scope; |
| 3505 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(); | 3621 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(); |
| 3506 global->Set(v8_str("f"), v8::FunctionTemplate::New(ArgumentsTestCallback)); | 3622 global->Set(v8_str("f"), v8::FunctionTemplate::New(ArgumentsTestCallback)); |
| 3507 LocalContext context(NULL, global); | 3623 LocalContext context(NULL, global); |
| 3508 args_fun = v8::Handle<Function>::Cast(context->Global()->Get(v8_str("f"))); | 3624 args_fun = context->Global()->Get(v8_str("f")).As<Function>(); |
| 3509 v8_compile("f(1, 2, 3)")->Run(); | 3625 v8_compile("f(1, 2, 3)")->Run(); |
| 3510 } | 3626 } |
| 3511 | 3627 |
| 3512 | 3628 |
| 3513 static v8::Handle<Value> NoBlockGetterX(Local<String> name, | 3629 static v8::Handle<Value> NoBlockGetterX(Local<String> name, |
| 3514 const AccessorInfo&) { | 3630 const AccessorInfo&) { |
| 3515 return v8::Handle<Value>(); | 3631 return v8::Handle<Value>(); |
| 3516 } | 3632 } |
| 3517 | 3633 |
| 3518 | 3634 |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3836 | 3952 |
| 3837 | 3953 |
| 3838 THREADED_TEST(ErrorConstruction) { | 3954 THREADED_TEST(ErrorConstruction) { |
| 3839 v8::HandleScope scope; | 3955 v8::HandleScope scope; |
| 3840 LocalContext context; | 3956 LocalContext context; |
| 3841 | 3957 |
| 3842 v8::Handle<String> foo = v8_str("foo"); | 3958 v8::Handle<String> foo = v8_str("foo"); |
| 3843 v8::Handle<String> message = v8_str("message"); | 3959 v8::Handle<String> message = v8_str("message"); |
| 3844 v8::Handle<Value> range_error = v8::Exception::RangeError(foo); | 3960 v8::Handle<Value> range_error = v8::Exception::RangeError(foo); |
| 3845 CHECK(range_error->IsObject()); | 3961 CHECK(range_error->IsObject()); |
| 3846 v8::Handle<v8::Object> range_obj(v8::Handle<v8::Object>::Cast(range_error)); | 3962 v8::Handle<v8::Object> range_obj = range_error.As<v8::Object>(); |
| 3847 CHECK(v8::Handle<v8::Object>::Cast(range_error)->Get(message)->Equals(foo)); | 3963 CHECK(range_error.As<v8::Object>()->Get(message)->Equals(foo)); |
| 3848 v8::Handle<Value> reference_error = v8::Exception::ReferenceError(foo); | 3964 v8::Handle<Value> reference_error = v8::Exception::ReferenceError(foo); |
| 3849 CHECK(reference_error->IsObject()); | 3965 CHECK(reference_error->IsObject()); |
| 3850 CHECK( | 3966 CHECK(reference_error.As<v8::Object>()->Get(message)->Equals(foo)); |
| 3851 v8::Handle<v8::Object>::Cast(reference_error)->Get(message)->Equals(foo)); | |
| 3852 v8::Handle<Value> syntax_error = v8::Exception::SyntaxError(foo); | 3967 v8::Handle<Value> syntax_error = v8::Exception::SyntaxError(foo); |
| 3853 CHECK(syntax_error->IsObject()); | 3968 CHECK(syntax_error->IsObject()); |
| 3854 CHECK(v8::Handle<v8::Object>::Cast(syntax_error)->Get(message)->Equals(foo)); | 3969 CHECK(syntax_error.As<v8::Object>()->Get(message)->Equals(foo)); |
| 3855 v8::Handle<Value> type_error = v8::Exception::TypeError(foo); | 3970 v8::Handle<Value> type_error = v8::Exception::TypeError(foo); |
| 3856 CHECK(type_error->IsObject()); | 3971 CHECK(type_error->IsObject()); |
| 3857 CHECK(v8::Handle<v8::Object>::Cast(type_error)->Get(message)->Equals(foo)); | 3972 CHECK(type_error.As<v8::Object>()->Get(message)->Equals(foo)); |
| 3858 v8::Handle<Value> error = v8::Exception::Error(foo); | 3973 v8::Handle<Value> error = v8::Exception::Error(foo); |
| 3859 CHECK(error->IsObject()); | 3974 CHECK(error->IsObject()); |
| 3860 CHECK(v8::Handle<v8::Object>::Cast(error)->Get(message)->Equals(foo)); | 3975 CHECK(error.As<v8::Object>()->Get(message)->Equals(foo)); |
| 3861 } | 3976 } |
| 3862 | 3977 |
| 3863 | 3978 |
| 3864 static v8::Handle<Value> YGetter(Local<String> name, const AccessorInfo& info) { | 3979 static v8::Handle<Value> YGetter(Local<String> name, const AccessorInfo& info) { |
| 3865 ApiTestFuzzer::Fuzz(); | 3980 ApiTestFuzzer::Fuzz(); |
| 3866 return v8_num(10); | 3981 return v8_num(10); |
| 3867 } | 3982 } |
| 3868 | 3983 |
| 3869 | 3984 |
| 3870 static void YSetter(Local<String> name, | 3985 static void YSetter(Local<String> name, |
| (...skipping 903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4774 static bool NamedAccessFlatten(Local<v8::Object> global, | 4889 static bool NamedAccessFlatten(Local<v8::Object> global, |
| 4775 Local<Value> name, | 4890 Local<Value> name, |
| 4776 v8::AccessType type, | 4891 v8::AccessType type, |
| 4777 Local<Value> data) { | 4892 Local<Value> data) { |
| 4778 char buf[100]; | 4893 char buf[100]; |
| 4779 int len; | 4894 int len; |
| 4780 | 4895 |
| 4781 CHECK(name->IsString()); | 4896 CHECK(name->IsString()); |
| 4782 | 4897 |
| 4783 memset(buf, 0x1, sizeof(buf)); | 4898 memset(buf, 0x1, sizeof(buf)); |
| 4784 len = Local<String>::Cast(name)->WriteAscii(buf); | 4899 len = name.As<String>()->WriteAscii(buf); |
| 4785 CHECK_EQ(4, len); | 4900 CHECK_EQ(4, len); |
| 4786 | 4901 |
| 4787 uint16_t buf2[100]; | 4902 uint16_t buf2[100]; |
| 4788 | 4903 |
| 4789 memset(buf, 0x1, sizeof(buf)); | 4904 memset(buf, 0x1, sizeof(buf)); |
| 4790 len = Local<String>::Cast(name)->Write(buf2); | 4905 len = name.As<String>()->Write(buf2); |
| 4791 CHECK_EQ(4, len); | 4906 CHECK_EQ(4, len); |
| 4792 | 4907 |
| 4793 return true; | 4908 return true; |
| 4794 } | 4909 } |
| 4795 | 4910 |
| 4796 | 4911 |
| 4797 static bool IndexedAccessFlatten(Local<v8::Object> global, | 4912 static bool IndexedAccessFlatten(Local<v8::Object> global, |
| 4798 uint32_t key, | 4913 uint32_t key, |
| 4799 v8::AccessType type, | 4914 v8::AccessType type, |
| 4800 Local<Value> data) { | 4915 Local<Value> data) { |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5129 CHECK_EQ(0, o0->Get(v8_str("x"))->Int32Value()); | 5244 CHECK_EQ(0, o0->Get(v8_str("x"))->Int32Value()); |
| 5130 CHECK_EQ(1, o0->Get(v8_str("y"))->Int32Value()); | 5245 CHECK_EQ(1, o0->Get(v8_str("y"))->Int32Value()); |
| 5131 CHECK_EQ(2, o0->Get(v8_str("z"))->Int32Value()); | 5246 CHECK_EQ(2, o0->Get(v8_str("z"))->Int32Value()); |
| 5132 CHECK_EQ(3, o0->Get(v8_str("u"))->Int32Value()); | 5247 CHECK_EQ(3, o0->Get(v8_str("u"))->Int32Value()); |
| 5133 | 5248 |
| 5134 // Getting the prototype of o0 should get the first visible one | 5249 // Getting the prototype of o0 should get the first visible one |
| 5135 // which is o3. Therefore, z should not be defined on the prototype | 5250 // which is o3. Therefore, z should not be defined on the prototype |
| 5136 // object. | 5251 // object. |
| 5137 Local<Value> proto = o0->Get(v8_str("__proto__")); | 5252 Local<Value> proto = o0->Get(v8_str("__proto__")); |
| 5138 CHECK(proto->IsObject()); | 5253 CHECK(proto->IsObject()); |
| 5139 CHECK(Local<v8::Object>::Cast(proto)->Get(v8_str("z"))->IsUndefined()); | 5254 CHECK(proto.As<v8::Object>()->Get(v8_str("z"))->IsUndefined()); |
| 5140 } | 5255 } |
| 5141 | 5256 |
| 5142 | 5257 |
| 5143 THREADED_TEST(SetPrototype) { | 5258 THREADED_TEST(SetPrototype) { |
| 5144 v8::HandleScope handle_scope; | 5259 v8::HandleScope handle_scope; |
| 5145 LocalContext context; | 5260 LocalContext context; |
| 5146 | 5261 |
| 5147 Local<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New(); | 5262 Local<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New(); |
| 5148 t0->InstanceTemplate()->Set(v8_str("x"), v8_num(0)); | 5263 t0->InstanceTemplate()->Set(v8_str("x"), v8_num(0)); |
| 5149 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(); | 5264 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 5173 CHECK_EQ(0, o0->Get(v8_str("x"))->Int32Value()); | 5288 CHECK_EQ(0, o0->Get(v8_str("x"))->Int32Value()); |
| 5174 CHECK_EQ(1, o0->Get(v8_str("y"))->Int32Value()); | 5289 CHECK_EQ(1, o0->Get(v8_str("y"))->Int32Value()); |
| 5175 CHECK_EQ(2, o0->Get(v8_str("z"))->Int32Value()); | 5290 CHECK_EQ(2, o0->Get(v8_str("z"))->Int32Value()); |
| 5176 CHECK_EQ(3, o0->Get(v8_str("u"))->Int32Value()); | 5291 CHECK_EQ(3, o0->Get(v8_str("u"))->Int32Value()); |
| 5177 | 5292 |
| 5178 // Getting the prototype of o0 should get the first visible one | 5293 // Getting the prototype of o0 should get the first visible one |
| 5179 // which is o3. Therefore, z should not be defined on the prototype | 5294 // which is o3. Therefore, z should not be defined on the prototype |
| 5180 // object. | 5295 // object. |
| 5181 Local<Value> proto = o0->Get(v8_str("__proto__")); | 5296 Local<Value> proto = o0->Get(v8_str("__proto__")); |
| 5182 CHECK(proto->IsObject()); | 5297 CHECK(proto->IsObject()); |
| 5183 CHECK_EQ(v8::Handle<v8::Object>::Cast(proto), o3); | 5298 CHECK_EQ(proto.As<v8::Object>(), o3); |
| 5184 | 5299 |
| 5185 // However, Object::GetPrototype ignores hidden prototype. | 5300 // However, Object::GetPrototype ignores hidden prototype. |
| 5186 Local<Value> proto0 = o0->GetPrototype(); | 5301 Local<Value> proto0 = o0->GetPrototype(); |
| 5187 CHECK(proto0->IsObject()); | 5302 CHECK(proto0->IsObject()); |
| 5188 CHECK_EQ(v8::Handle<v8::Object>::Cast(proto0), o1); | 5303 CHECK_EQ(proto0.As<v8::Object>(), o1); |
| 5189 | 5304 |
| 5190 Local<Value> proto1 = o1->GetPrototype(); | 5305 Local<Value> proto1 = o1->GetPrototype(); |
| 5191 CHECK(proto1->IsObject()); | 5306 CHECK(proto1->IsObject()); |
| 5192 CHECK_EQ(v8::Handle<v8::Object>::Cast(proto1), o2); | 5307 CHECK_EQ(proto1.As<v8::Object>(), o2); |
| 5193 | 5308 |
| 5194 Local<Value> proto2 = o2->GetPrototype(); | 5309 Local<Value> proto2 = o2->GetPrototype(); |
| 5195 CHECK(proto2->IsObject()); | 5310 CHECK(proto2->IsObject()); |
| 5196 CHECK_EQ(v8::Handle<v8::Object>::Cast(proto2), o3); | 5311 CHECK_EQ(proto2.As<v8::Object>(), o3); |
| 5197 } | 5312 } |
| 5198 | 5313 |
| 5199 | 5314 |
| 5200 THREADED_TEST(SetPrototypeThrows) { | 5315 THREADED_TEST(SetPrototypeThrows) { |
| 5201 v8::HandleScope handle_scope; | 5316 v8::HandleScope handle_scope; |
| 5202 LocalContext context; | 5317 LocalContext context; |
| 5203 | 5318 |
| 5204 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); | 5319 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); |
| 5205 | 5320 |
| 5206 Local<v8::Object> o0 = t->GetFunction()->NewInstance(); | 5321 Local<v8::Object> o0 = t->GetFunction()->NewInstance(); |
| (...skipping 1220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6427 " if (i == 50) {" | 6542 " if (i == 50) {" |
| 6428 " saved_result = result;" | 6543 " saved_result = result;" |
| 6429 " o.method = function(x) { return x - 1 };" | 6544 " o.method = function(x) { return x - 1 };" |
| 6430 " }" | 6545 " }" |
| 6431 "}"); | 6546 "}"); |
| 6432 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); | 6547 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); |
| 6433 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); | 6548 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); |
| 6434 CHECK_GE(interceptor_call_count, 50); | 6549 CHECK_GE(interceptor_call_count, 50); |
| 6435 } | 6550 } |
| 6436 | 6551 |
| 6552 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss3) { |
| 6553 int interceptor_call_count = 0; |
| 6554 v8::HandleScope scope; |
| 6555 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); |
| 6556 v8::Handle<v8::FunctionTemplate> method_templ = |
| 6557 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, |
| 6558 v8_str("method_data"), |
| 6559 v8::Signature::New(fun_templ)); |
| 6560 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
| 6561 proto_templ->Set(v8_str("method"), method_templ); |
| 6562 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
| 6563 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, |
| 6564 NULL, NULL, NULL, NULL, |
| 6565 v8::External::Wrap(&interceptor_call_count)); |
| 6566 LocalContext context; |
| 6567 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
| 6568 GenerateSomeGarbage(); |
| 6569 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
| 6570 v8::TryCatch try_catch; |
| 6571 v8::Handle<Value> value = CompileRun( |
| 6572 "o.foo = 17;" |
| 6573 "var receiver = {};" |
| 6574 "receiver.__proto__ = o;" |
| 6575 "var result = 0;" |
| 6576 "var saved_result = 0;" |
| 6577 "for (var i = 0; i < 100; i++) {" |
| 6578 " result = receiver.method(41);" |
| 6579 " if (i == 50) {" |
| 6580 " saved_result = result;" |
| 6581 " receiver = 333;" |
| 6582 " }" |
| 6583 "}"); |
| 6584 CHECK(try_catch.HasCaught()); |
| 6585 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"), |
| 6586 try_catch.Exception()->ToString()); |
| 6587 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); |
| 6588 CHECK_GE(interceptor_call_count, 50); |
| 6589 } |
| 6590 |
| 6437 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_TypeError) { | 6591 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_TypeError) { |
| 6438 int interceptor_call_count = 0; | 6592 int interceptor_call_count = 0; |
| 6439 v8::HandleScope scope; | 6593 v8::HandleScope scope; |
| 6440 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 6594 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); |
| 6441 v8::Handle<v8::FunctionTemplate> method_templ = | 6595 v8::Handle<v8::FunctionTemplate> method_templ = |
| 6442 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, | 6596 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, |
| 6443 v8_str("method_data"), | 6597 v8_str("method_data"), |
| 6444 v8::Signature::New(fun_templ)); | 6598 v8::Signature::New(fun_templ)); |
| 6445 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 6599 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
| 6446 proto_templ->Set(v8_str("method"), method_templ); | 6600 proto_templ->Set(v8_str("method"), method_templ); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6515 "var receiver = {};" | 6669 "var receiver = {};" |
| 6516 "receiver.__proto__ = o;" | 6670 "receiver.__proto__ = o;" |
| 6517 "var result = 0;" | 6671 "var result = 0;" |
| 6518 "for (var i = 0; i < 100; i++) {" | 6672 "for (var i = 0; i < 100; i++) {" |
| 6519 " result = receiver.method(41);" | 6673 " result = receiver.method(41);" |
| 6520 "}"); | 6674 "}"); |
| 6521 | 6675 |
| 6522 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); | 6676 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); |
| 6523 } | 6677 } |
| 6524 | 6678 |
| 6525 THREADED_TEST(CallICFastApi_SimpleSignature_Miss) { | 6679 THREADED_TEST(CallICFastApi_SimpleSignature_Miss1) { |
| 6526 v8::HandleScope scope; | 6680 v8::HandleScope scope; |
| 6527 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 6681 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); |
| 6528 v8::Handle<v8::FunctionTemplate> method_templ = | 6682 v8::Handle<v8::FunctionTemplate> method_templ = |
| 6529 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, | 6683 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, |
| 6530 v8_str("method_data"), | 6684 v8_str("method_data"), |
| 6531 v8::Signature::New(fun_templ)); | 6685 v8::Signature::New(fun_templ)); |
| 6532 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 6686 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
| 6533 proto_templ->Set(v8_str("method"), method_templ); | 6687 proto_templ->Set(v8_str("method"), method_templ); |
| 6534 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); | 6688 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
| 6535 LocalContext context; | 6689 LocalContext context; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 6546 " result = receiver.method(41);" | 6700 " result = receiver.method(41);" |
| 6547 " if (i == 50) {" | 6701 " if (i == 50) {" |
| 6548 " saved_result = result;" | 6702 " saved_result = result;" |
| 6549 " receiver = {method: function(x) { return x - 1 }};" | 6703 " receiver = {method: function(x) { return x - 1 }};" |
| 6550 " }" | 6704 " }" |
| 6551 "}"); | 6705 "}"); |
| 6552 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); | 6706 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); |
| 6553 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); | 6707 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); |
| 6554 } | 6708 } |
| 6555 | 6709 |
| 6710 THREADED_TEST(CallICFastApi_SimpleSignature_Miss2) { |
| 6711 v8::HandleScope scope; |
| 6712 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); |
| 6713 v8::Handle<v8::FunctionTemplate> method_templ = |
| 6714 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, |
| 6715 v8_str("method_data"), |
| 6716 v8::Signature::New(fun_templ)); |
| 6717 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
| 6718 proto_templ->Set(v8_str("method"), method_templ); |
| 6719 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
| 6720 LocalContext context; |
| 6721 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
| 6722 GenerateSomeGarbage(); |
| 6723 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
| 6724 v8::TryCatch try_catch; |
| 6725 v8::Handle<Value> value = CompileRun( |
| 6726 "o.foo = 17;" |
| 6727 "var receiver = {};" |
| 6728 "receiver.__proto__ = o;" |
| 6729 "var result = 0;" |
| 6730 "var saved_result = 0;" |
| 6731 "for (var i = 0; i < 100; i++) {" |
| 6732 " result = receiver.method(41);" |
| 6733 " if (i == 50) {" |
| 6734 " saved_result = result;" |
| 6735 " receiver = 333;" |
| 6736 " }" |
| 6737 "}"); |
| 6738 CHECK(try_catch.HasCaught()); |
| 6739 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"), |
| 6740 try_catch.Exception()->ToString()); |
| 6741 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); |
| 6742 } |
| 6743 |
| 6556 | 6744 |
| 6557 static int interceptor_call_count = 0; | 6745 static int interceptor_call_count = 0; |
| 6558 | 6746 |
| 6559 static v8::Handle<Value> InterceptorICRefErrorGetter(Local<String> name, | 6747 static v8::Handle<Value> InterceptorICRefErrorGetter(Local<String> name, |
| 6560 const AccessorInfo& info) { | 6748 const AccessorInfo& info) { |
| 6561 ApiTestFuzzer::Fuzz(); | 6749 ApiTestFuzzer::Fuzz(); |
| 6562 if (v8_str("x")->Equals(name) && interceptor_call_count++ < 20) { | 6750 if (v8_str("x")->Equals(name) && interceptor_call_count++ < 20) { |
| 6563 return call_ic_function2; | 6751 return call_ic_function2; |
| 6564 } | 6752 } |
| 6565 return v8::Handle<Value>(); | 6753 return v8::Handle<Value>(); |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6825 // ObjectProtoToString should not call replace toString function. | 7013 // ObjectProtoToString should not call replace toString function. |
| 6826 value = instance->ObjectProtoToString(); | 7014 value = instance->ObjectProtoToString(); |
| 6827 CHECK(value->IsString() && value->Equals(v8_str("[object MyClass]"))); | 7015 CHECK(value->IsString() && value->Equals(v8_str("[object MyClass]"))); |
| 6828 | 7016 |
| 6829 // Check global | 7017 // Check global |
| 6830 value = context->Global()->ObjectProtoToString(); | 7018 value = context->Global()->ObjectProtoToString(); |
| 6831 CHECK(value->IsString() && value->Equals(v8_str("[object global]"))); | 7019 CHECK(value->IsString() && value->Equals(v8_str("[object global]"))); |
| 6832 | 7020 |
| 6833 // Check ordinary object | 7021 // Check ordinary object |
| 6834 Local<Value> object = v8_compile("new Object()")->Run(); | 7022 Local<Value> object = v8_compile("new Object()")->Run(); |
| 6835 value = Local<v8::Object>::Cast(object)->ObjectProtoToString(); | 7023 value = object.As<v8::Object>()->ObjectProtoToString(); |
| 6836 CHECK(value->IsString() && value->Equals(v8_str("[object Object]"))); | 7024 CHECK(value->IsString() && value->Equals(v8_str("[object Object]"))); |
| 6837 } | 7025 } |
| 6838 | 7026 |
| 6839 | 7027 |
| 6840 bool ApiTestFuzzer::fuzzing_ = false; | 7028 bool ApiTestFuzzer::fuzzing_ = false; |
| 6841 v8::internal::Semaphore* ApiTestFuzzer::all_tests_done_= | 7029 v8::internal::Semaphore* ApiTestFuzzer::all_tests_done_= |
| 6842 v8::internal::OS::CreateSemaphore(0); | 7030 v8::internal::OS::CreateSemaphore(0); |
| 6843 int ApiTestFuzzer::active_tests_; | 7031 int ApiTestFuzzer::active_tests_; |
| 6844 int ApiTestFuzzer::tests_being_run_; | 7032 int ApiTestFuzzer::tests_being_run_; |
| 6845 int ApiTestFuzzer::current_; | 7033 int ApiTestFuzzer::current_; |
| (...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7445 v8::String::AsciiValue name(value); | 7633 v8::String::AsciiValue name(value); |
| 7446 CHECK_EQ("asdf", *name); | 7634 CHECK_EQ("asdf", *name); |
| 7447 } | 7635 } |
| 7448 | 7636 |
| 7449 | 7637 |
| 7450 THREADED_TEST(DateAccess) { | 7638 THREADED_TEST(DateAccess) { |
| 7451 v8::HandleScope scope; | 7639 v8::HandleScope scope; |
| 7452 LocalContext context; | 7640 LocalContext context; |
| 7453 v8::Handle<v8::Value> date = v8::Date::New(1224744689038.0); | 7641 v8::Handle<v8::Value> date = v8::Date::New(1224744689038.0); |
| 7454 CHECK(date->IsDate()); | 7642 CHECK(date->IsDate()); |
| 7455 CHECK_EQ(1224744689038.0, v8::Handle<v8::Date>::Cast(date)->NumberValue()); | 7643 CHECK_EQ(1224744689038.0, date.As<v8::Date>()->NumberValue()); |
| 7456 } | 7644 } |
| 7457 | 7645 |
| 7458 | 7646 |
| 7459 void CheckProperties(v8::Handle<v8::Value> val, int elmc, const char* elmv[]) { | 7647 void CheckProperties(v8::Handle<v8::Value> val, int elmc, const char* elmv[]) { |
| 7460 v8::Handle<v8::Object> obj = v8::Handle<v8::Object>::Cast(val); | 7648 v8::Handle<v8::Object> obj = val.As<v8::Object>(); |
| 7461 v8::Handle<v8::Array> props = obj->GetPropertyNames(); | 7649 v8::Handle<v8::Array> props = obj->GetPropertyNames(); |
| 7462 CHECK_EQ(elmc, props->Length()); | 7650 CHECK_EQ(elmc, props->Length()); |
| 7463 for (int i = 0; i < elmc; i++) { | 7651 for (int i = 0; i < elmc; i++) { |
| 7464 v8::String::Utf8Value elm(props->Get(v8::Integer::New(i))); | 7652 v8::String::Utf8Value elm(props->Get(v8::Integer::New(i))); |
| 7465 CHECK_EQ(elmv[i], *elm); | 7653 CHECK_EQ(elmv[i], *elm); |
| 7466 } | 7654 } |
| 7467 } | 7655 } |
| 7468 | 7656 |
| 7469 | 7657 |
| 7470 THREADED_TEST(PropertyEnumeration) { | 7658 THREADED_TEST(PropertyEnumeration) { |
| 7471 v8::HandleScope scope; | 7659 v8::HandleScope scope; |
| 7472 LocalContext context; | 7660 LocalContext context; |
| 7473 v8::Handle<v8::Value> obj = v8::Script::Compile(v8::String::New( | 7661 v8::Handle<v8::Value> obj = v8::Script::Compile(v8::String::New( |
| 7474 "var result = [];" | 7662 "var result = [];" |
| 7475 "result[0] = {};" | 7663 "result[0] = {};" |
| 7476 "result[1] = {a: 1, b: 2};" | 7664 "result[1] = {a: 1, b: 2};" |
| 7477 "result[2] = [1, 2, 3];" | 7665 "result[2] = [1, 2, 3];" |
| 7478 "var proto = {x: 1, y: 2, z: 3};" | 7666 "var proto = {x: 1, y: 2, z: 3};" |
| 7479 "var x = { __proto__: proto, w: 0, z: 1 };" | 7667 "var x = { __proto__: proto, w: 0, z: 1 };" |
| 7480 "result[3] = x;" | 7668 "result[3] = x;" |
| 7481 "result;"))->Run(); | 7669 "result;"))->Run(); |
| 7482 v8::Handle<v8::Array> elms = v8::Handle<v8::Array>::Cast(obj); | 7670 v8::Handle<v8::Array> elms = obj.As<v8::Array>(); |
| 7483 CHECK_EQ(4, elms->Length()); | 7671 CHECK_EQ(4, elms->Length()); |
| 7484 int elmc0 = 0; | 7672 int elmc0 = 0; |
| 7485 const char** elmv0 = NULL; | 7673 const char** elmv0 = NULL; |
| 7486 CheckProperties(elms->Get(v8::Integer::New(0)), elmc0, elmv0); | 7674 CheckProperties(elms->Get(v8::Integer::New(0)), elmc0, elmv0); |
| 7487 int elmc1 = 2; | 7675 int elmc1 = 2; |
| 7488 const char* elmv1[] = {"a", "b"}; | 7676 const char* elmv1[] = {"a", "b"}; |
| 7489 CheckProperties(elms->Get(v8::Integer::New(1)), elmc1, elmv1); | 7677 CheckProperties(elms->Get(v8::Integer::New(1)), elmc1, elmv1); |
| 7490 int elmc2 = 3; | 7678 int elmc2 = 3; |
| 7491 const char* elmv2[] = {"0", "1", "2"}; | 7679 const char* elmv2[] = {"0", "1", "2"}; |
| 7492 CheckProperties(elms->Get(v8::Integer::New(2)), elmc2, elmv2); | 7680 CheckProperties(elms->Get(v8::Integer::New(2)), elmc2, elmv2); |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7994 | 8182 |
| 7995 const char* sample = | 8183 const char* sample = |
| 7996 "var rv = {};" \ | 8184 "var rv = {};" \ |
| 7997 "rv.alpha = 'hello';" \ | 8185 "rv.alpha = 'hello';" \ |
| 7998 "rv.beta = 123;" \ | 8186 "rv.beta = 123;" \ |
| 7999 "rv;"; | 8187 "rv;"; |
| 8000 | 8188 |
| 8001 // Create an object, verify basics. | 8189 // Create an object, verify basics. |
| 8002 Local<Value> val = CompileRun(sample); | 8190 Local<Value> val = CompileRun(sample); |
| 8003 CHECK(val->IsObject()); | 8191 CHECK(val->IsObject()); |
| 8004 Local<v8::Object> obj = Local<v8::Object>::Cast(val); | 8192 Local<v8::Object> obj = val.As<v8::Object>(); |
| 8005 obj->Set(v8_str("gamma"), v8_str("cloneme")); | 8193 obj->Set(v8_str("gamma"), v8_str("cloneme")); |
| 8006 | 8194 |
| 8007 CHECK_EQ(v8_str("hello"), obj->Get(v8_str("alpha"))); | 8195 CHECK_EQ(v8_str("hello"), obj->Get(v8_str("alpha"))); |
| 8008 CHECK_EQ(v8::Integer::New(123), obj->Get(v8_str("beta"))); | 8196 CHECK_EQ(v8::Integer::New(123), obj->Get(v8_str("beta"))); |
| 8009 CHECK_EQ(v8_str("cloneme"), obj->Get(v8_str("gamma"))); | 8197 CHECK_EQ(v8_str("cloneme"), obj->Get(v8_str("gamma"))); |
| 8010 | 8198 |
| 8011 // Clone it. | 8199 // Clone it. |
| 8012 Local<v8::Object> clone = obj->Clone(); | 8200 Local<v8::Object> clone = obj->Clone(); |
| 8013 CHECK_EQ(v8_str("hello"), clone->Get(v8_str("alpha"))); | 8201 CHECK_EQ(v8_str("hello"), clone->Get(v8_str("alpha"))); |
| 8014 CHECK_EQ(v8::Integer::New(123), clone->Get(v8_str("beta"))); | 8202 CHECK_EQ(v8::Integer::New(123), clone->Get(v8_str("beta"))); |
| (...skipping 1620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9635 } | 9823 } |
| 9636 | 9824 |
| 9637 | 9825 |
| 9638 static void SetterWhichSetsYOnThisTo23(Local<String> name, | 9826 static void SetterWhichSetsYOnThisTo23(Local<String> name, |
| 9639 Local<Value> value, | 9827 Local<Value> value, |
| 9640 const AccessorInfo& info) { | 9828 const AccessorInfo& info) { |
| 9641 info.This()->Set(v8_str("y"), v8_num(23)); | 9829 info.This()->Set(v8_str("y"), v8_num(23)); |
| 9642 } | 9830 } |
| 9643 | 9831 |
| 9644 | 9832 |
| 9645 THREADED_TEST(SetterOnConstructorPrototype) { | 9833 TEST(SetterOnConstructorPrototype) { |
| 9646 v8::HandleScope scope; | 9834 v8::HandleScope scope; |
| 9647 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 9835 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 9648 templ->SetAccessor(v8_str("x"), | 9836 templ->SetAccessor(v8_str("x"), |
| 9649 GetterWhichReturns42, | 9837 GetterWhichReturns42, |
| 9650 SetterWhichSetsYOnThisTo23); | 9838 SetterWhichSetsYOnThisTo23); |
| 9651 LocalContext context; | 9839 LocalContext context; |
| 9652 context->Global()->Set(v8_str("P"), templ->NewInstance()); | 9840 context->Global()->Set(v8_str("P"), templ->NewInstance()); |
| 9653 CompileRun("function C1() {" | 9841 CompileRun("function C1() {" |
| 9654 " this.x = 23;" | 9842 " this.x = 23;" |
| 9655 "};" | 9843 "};" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9717 CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value()); | 9905 CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value()); |
| 9718 } | 9906 } |
| 9719 | 9907 |
| 9720 script = v8::Script::Compile(v8_str("new C2();")); | 9908 script = v8::Script::Compile(v8_str("new C2();")); |
| 9721 for (int i = 0; i < 10; i++) { | 9909 for (int i = 0; i < 10; i++) { |
| 9722 v8::Handle<v8::Object> c2 = v8::Handle<v8::Object>::Cast(script->Run()); | 9910 v8::Handle<v8::Object> c2 = v8::Handle<v8::Object>::Cast(script->Run()); |
| 9723 CHECK_EQ(23, c2->Get(v8_str("x"))->Int32Value()); | 9911 CHECK_EQ(23, c2->Get(v8_str("x"))->Int32Value()); |
| 9724 CHECK_EQ(42, c2->Get(v8_str("y"))->Int32Value()); | 9912 CHECK_EQ(42, c2->Get(v8_str("y"))->Int32Value()); |
| 9725 } | 9913 } |
| 9726 } | 9914 } |
| 9915 |
| 9916 |
| 9917 TEST(Bug618) { |
| 9918 const char* source = "function C1() {" |
| 9919 " this.x = 23;" |
| 9920 "};" |
| 9921 "C1.prototype = P;"; |
| 9922 |
| 9923 v8::HandleScope scope; |
| 9924 LocalContext context; |
| 9925 v8::Local<v8::Script> script; |
| 9926 |
| 9927 // Use a simple object as prototype. |
| 9928 v8::Local<v8::Object> prototype = v8::Object::New(); |
| 9929 prototype->Set(v8_str("y"), v8_num(42)); |
| 9930 context->Global()->Set(v8_str("P"), prototype); |
| 9931 |
| 9932 // This compile will add the code to the compilation cache. |
| 9933 CompileRun(source); |
| 9934 |
| 9935 script = v8::Script::Compile(v8_str("new C1();")); |
| 9936 for (int i = 0; i < 10; i++) { |
| 9937 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); |
| 9938 CHECK_EQ(23, c1->Get(v8_str("x"))->Int32Value()); |
| 9939 CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value()); |
| 9940 } |
| 9941 |
| 9942 // Use an API object with accessors as prototype. |
| 9943 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 9944 templ->SetAccessor(v8_str("x"), |
| 9945 GetterWhichReturns42, |
| 9946 SetterWhichSetsYOnThisTo23); |
| 9947 context->Global()->Set(v8_str("P"), templ->NewInstance()); |
| 9948 |
| 9949 // This compile will get the code from the compilation cache. |
| 9950 CompileRun(source); |
| 9951 |
| 9952 script = v8::Script::Compile(v8_str("new C1();")); |
| 9953 for (int i = 0; i < 10; i++) { |
| 9954 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); |
| 9955 CHECK_EQ(42, c1->Get(v8_str("x"))->Int32Value()); |
| 9956 CHECK_EQ(23, c1->Get(v8_str("y"))->Int32Value()); |
| 9957 } |
| 9958 } |
| OLD | NEW |