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

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

Issue 21173004: Version 3.20.11.1 (Closed) Base URL: https://v8.googlecode.com/svn/trunk
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/x64/lithium-x64.cc ('k') | test/cctest/test-cpu-profiler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 #include "platform.h" 48 #include "platform.h"
49 #include "snapshot.h" 49 #include "snapshot.h"
50 #include "unicode-inl.h" 50 #include "unicode-inl.h"
51 #include "utils.h" 51 #include "utils.h"
52 #include "vm-state.h" 52 #include "vm-state.h"
53 53
54 static const bool kLogThreading = false; 54 static const bool kLogThreading = false;
55 55
56 using ::v8::AccessorInfo; 56 using ::v8::AccessorInfo;
57 using ::v8::Arguments; 57 using ::v8::Arguments;
58 using ::v8::Boolean;
59 using ::v8::BooleanObject;
60 using ::v8::Context; 58 using ::v8::Context;
61 using ::v8::Extension; 59 using ::v8::Extension;
62 using ::v8::Function; 60 using ::v8::Function;
63 using ::v8::FunctionTemplate; 61 using ::v8::FunctionTemplate;
64 using ::v8::Handle; 62 using ::v8::Handle;
65 using ::v8::HandleScope; 63 using ::v8::HandleScope;
66 using ::v8::Local; 64 using ::v8::Local;
67 using ::v8::Message; 65 using ::v8::Message;
68 using ::v8::MessageCallback; 66 using ::v8::MessageCallback;
69 using ::v8::Object; 67 using ::v8::Object;
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 char* buf = i::NewArray<char>(buf_size); 614 char* buf = i::NewArray<char>(buf_size);
617 memset(buf, 'a', buf_size); 615 memset(buf, 'a', buf_size);
618 buf[buf_size - 1] = '\0'; 616 buf[buf_size - 1] = '\0';
619 Local<String> large_string = String::New(buf); 617 Local<String> large_string = String::New(buf);
620 i::DeleteArray(buf); 618 i::DeleteArray(buf);
621 // Large strings should be immediately accepted. 619 // Large strings should be immediately accepted.
622 CHECK(large_string->CanMakeExternal()); 620 CHECK(large_string->CanMakeExternal());
623 } 621 }
624 622
625 623
626 TEST(MakingExternalUnalignedAsciiString) {
627 LocalContext env;
628 v8::HandleScope scope(env->GetIsolate());
629
630 CompileRun("function cons(a, b) { return a + b; }"
631 "function slice(a) { return a.substring(1); }");
632 // Create a cons string that will land in old pointer space.
633 Local<String> cons = Local<String>::Cast(CompileRun(
634 "cons('abcdefghijklm', 'nopqrstuvwxyz');"));
635 // Create a sliced string that will land in old pointer space.
636 Local<String> slice = Local<String>::Cast(CompileRun(
637 "slice('abcdefghijklmnopqrstuvwxyz');"));
638
639 // Trigger GCs so that the newly allocated string moves to old gen.
640 SimulateFullSpace(HEAP->old_pointer_space());
641 HEAP->CollectGarbage(i::NEW_SPACE); // in survivor space now
642 HEAP->CollectGarbage(i::NEW_SPACE); // in old gen now
643
644 // Turn into external string with unaligned resource data.
645 int dispose_count = 0;
646 const char* c_cons = "_abcdefghijklmnopqrstuvwxyz";
647 bool success = cons->MakeExternal(
648 new TestAsciiResource(i::StrDup(c_cons) + 1, &dispose_count));
649 CHECK(success);
650 const char* c_slice = "_bcdefghijklmnopqrstuvwxyz";
651 success = slice->MakeExternal(
652 new TestAsciiResource(i::StrDup(c_slice) + 1, &dispose_count));
653 CHECK(success);
654
655 // Trigger GCs and force evacuation.
656 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
657 HEAP->CollectAllGarbage(i::Heap::kReduceMemoryFootprintMask);
658 }
659
660
661 THREADED_TEST(UsingExternalString) { 624 THREADED_TEST(UsingExternalString) {
662 i::Factory* factory = i::Isolate::Current()->factory(); 625 i::Factory* factory = i::Isolate::Current()->factory();
663 { 626 {
664 v8::HandleScope scope(v8::Isolate::GetCurrent()); 627 v8::HandleScope scope(v8::Isolate::GetCurrent());
665 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); 628 uint16_t* two_byte_string = AsciiToTwoByteString("test string");
666 Local<String> string = 629 Local<String> string =
667 String::NewExternal(new TestResource(two_byte_string)); 630 String::NewExternal(new TestResource(two_byte_string));
668 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); 631 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string);
669 // Trigger GCs so that the newly allocated string moves to old gen. 632 // Trigger GCs so that the newly allocated string moves to old gen.
670 HEAP->CollectGarbage(i::NEW_SPACE); // in survivor space now 633 HEAP->CollectGarbage(i::NEW_SPACE); // in survivor space now
(...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after
1481 v8::Handle<Value> boxed_string = CompileRun("new String(\"test\")"); 1444 v8::Handle<Value> boxed_string = CompileRun("new String(\"test\")");
1482 CHECK(boxed_string->IsStringObject()); 1445 CHECK(boxed_string->IsStringObject());
1483 v8::Handle<Value> unboxed_string = CompileRun("\"test\""); 1446 v8::Handle<Value> unboxed_string = CompileRun("\"test\"");
1484 CHECK(!unboxed_string->IsStringObject()); 1447 CHECK(!unboxed_string->IsStringObject());
1485 v8::Handle<Value> boxed_not_string = CompileRun("new Number(42)"); 1448 v8::Handle<Value> boxed_not_string = CompileRun("new Number(42)");
1486 CHECK(!boxed_not_string->IsStringObject()); 1449 CHECK(!boxed_not_string->IsStringObject());
1487 v8::Handle<Value> not_object = CompileRun("0"); 1450 v8::Handle<Value> not_object = CompileRun("0");
1488 CHECK(!not_object->IsStringObject()); 1451 CHECK(!not_object->IsStringObject());
1489 v8::Handle<v8::StringObject> as_boxed = boxed_string.As<v8::StringObject>(); 1452 v8::Handle<v8::StringObject> as_boxed = boxed_string.As<v8::StringObject>();
1490 CHECK(!as_boxed.IsEmpty()); 1453 CHECK(!as_boxed.IsEmpty());
1491 Local<v8::String> the_string = as_boxed->ValueOf(); 1454 Local<v8::String> the_string = as_boxed->StringValue();
1492 CHECK(!the_string.IsEmpty()); 1455 CHECK(!the_string.IsEmpty());
1493 ExpectObject("\"test\"", the_string); 1456 ExpectObject("\"test\"", the_string);
1494 v8::Handle<v8::Value> new_boxed_string = v8::StringObject::New(the_string); 1457 v8::Handle<v8::Value> new_boxed_string = v8::StringObject::New(the_string);
1495 CHECK(new_boxed_string->IsStringObject()); 1458 CHECK(new_boxed_string->IsStringObject());
1496 as_boxed = new_boxed_string.As<v8::StringObject>(); 1459 as_boxed = new_boxed_string.As<v8::StringObject>();
1497 the_string = as_boxed->ValueOf(); 1460 the_string = as_boxed->StringValue();
1498 CHECK(!the_string.IsEmpty()); 1461 CHECK(!the_string.IsEmpty());
1499 ExpectObject("\"test\"", the_string); 1462 ExpectObject("\"test\"", the_string);
1500 } 1463 }
1501 1464
1502 1465
1503 THREADED_TEST(NumberObject) { 1466 THREADED_TEST(NumberObject) {
1504 LocalContext env; 1467 LocalContext env;
1505 v8::HandleScope scope(env->GetIsolate()); 1468 v8::HandleScope scope(env->GetIsolate());
1506 v8::Handle<Value> boxed_number = CompileRun("new Number(42)"); 1469 v8::Handle<Value> boxed_number = CompileRun("new Number(42)");
1507 CHECK(boxed_number->IsNumberObject()); 1470 CHECK(boxed_number->IsNumberObject());
1508 v8::Handle<Value> unboxed_number = CompileRun("42"); 1471 v8::Handle<Value> unboxed_number = CompileRun("42");
1509 CHECK(!unboxed_number->IsNumberObject()); 1472 CHECK(!unboxed_number->IsNumberObject());
1510 v8::Handle<Value> boxed_not_number = CompileRun("new Boolean(false)"); 1473 v8::Handle<Value> boxed_not_number = CompileRun("new Boolean(false)");
1511 CHECK(!boxed_not_number->IsNumberObject()); 1474 CHECK(!boxed_not_number->IsNumberObject());
1512 v8::Handle<v8::NumberObject> as_boxed = boxed_number.As<v8::NumberObject>(); 1475 v8::Handle<v8::NumberObject> as_boxed = boxed_number.As<v8::NumberObject>();
1513 CHECK(!as_boxed.IsEmpty()); 1476 CHECK(!as_boxed.IsEmpty());
1514 double the_number = as_boxed->ValueOf(); 1477 double the_number = as_boxed->NumberValue();
1515 CHECK_EQ(42.0, the_number); 1478 CHECK_EQ(42.0, the_number);
1516 v8::Handle<v8::Value> new_boxed_number = v8::NumberObject::New(43); 1479 v8::Handle<v8::Value> new_boxed_number = v8::NumberObject::New(43);
1517 CHECK(new_boxed_number->IsNumberObject()); 1480 CHECK(new_boxed_number->IsNumberObject());
1518 as_boxed = new_boxed_number.As<v8::NumberObject>(); 1481 as_boxed = new_boxed_number.As<v8::NumberObject>();
1519 the_number = as_boxed->ValueOf(); 1482 the_number = as_boxed->NumberValue();
1520 CHECK_EQ(43.0, the_number); 1483 CHECK_EQ(43.0, the_number);
1521 } 1484 }
1522 1485
1523 1486
1524 THREADED_TEST(BooleanObject) { 1487 THREADED_TEST(BooleanObject) {
1525 LocalContext env; 1488 LocalContext env;
1526 v8::HandleScope scope(env->GetIsolate()); 1489 v8::HandleScope scope(env->GetIsolate());
1527 v8::Handle<Value> boxed_boolean = CompileRun("new Boolean(true)"); 1490 v8::Handle<Value> boxed_boolean = CompileRun("new Boolean(true)");
1528 CHECK(boxed_boolean->IsBooleanObject()); 1491 CHECK(boxed_boolean->IsBooleanObject());
1529 v8::Handle<Value> unboxed_boolean = CompileRun("true"); 1492 v8::Handle<Value> unboxed_boolean = CompileRun("true");
1530 CHECK(!unboxed_boolean->IsBooleanObject()); 1493 CHECK(!unboxed_boolean->IsBooleanObject());
1531 v8::Handle<Value> boxed_not_boolean = CompileRun("new Number(42)"); 1494 v8::Handle<Value> boxed_not_boolean = CompileRun("new Number(42)");
1532 CHECK(!boxed_not_boolean->IsBooleanObject()); 1495 CHECK(!boxed_not_boolean->IsBooleanObject());
1533 v8::Handle<v8::BooleanObject> as_boxed = 1496 v8::Handle<v8::BooleanObject> as_boxed =
1534 boxed_boolean.As<v8::BooleanObject>(); 1497 boxed_boolean.As<v8::BooleanObject>();
1535 CHECK(!as_boxed.IsEmpty()); 1498 CHECK(!as_boxed.IsEmpty());
1536 bool the_boolean = as_boxed->ValueOf(); 1499 bool the_boolean = as_boxed->BooleanValue();
1537 CHECK_EQ(true, the_boolean); 1500 CHECK_EQ(true, the_boolean);
1538 v8::Handle<v8::Value> boxed_true = v8::BooleanObject::New(true); 1501 v8::Handle<v8::Value> boxed_true = v8::BooleanObject::New(true);
1539 v8::Handle<v8::Value> boxed_false = v8::BooleanObject::New(false); 1502 v8::Handle<v8::Value> boxed_false = v8::BooleanObject::New(false);
1540 CHECK(boxed_true->IsBooleanObject()); 1503 CHECK(boxed_true->IsBooleanObject());
1541 CHECK(boxed_false->IsBooleanObject()); 1504 CHECK(boxed_false->IsBooleanObject());
1542 as_boxed = boxed_true.As<v8::BooleanObject>(); 1505 as_boxed = boxed_true.As<v8::BooleanObject>();
1543 CHECK_EQ(true, as_boxed->ValueOf()); 1506 CHECK_EQ(true, as_boxed->BooleanValue());
1544 as_boxed = boxed_false.As<v8::BooleanObject>(); 1507 as_boxed = boxed_false.As<v8::BooleanObject>();
1545 CHECK_EQ(false, as_boxed->ValueOf()); 1508 CHECK_EQ(false, as_boxed->BooleanValue());
1546 } 1509 }
1547 1510
1548 1511
1549 THREADED_TEST(PrimitiveAndWrappedBooleans) {
1550 LocalContext env;
1551 v8::HandleScope scope(env->GetIsolate());
1552
1553 Local<Value> primitive_false = Boolean::New(false);
1554 CHECK(primitive_false->IsBoolean());
1555 CHECK(!primitive_false->IsBooleanObject());
1556 CHECK(!primitive_false->BooleanValue());
1557 CHECK(!primitive_false->IsTrue());
1558 CHECK(primitive_false->IsFalse());
1559
1560 Local<Value> false_value = BooleanObject::New(false);
1561 CHECK(!false_value->IsBoolean());
1562 CHECK(false_value->IsBooleanObject());
1563 CHECK(false_value->BooleanValue());
1564 CHECK(!false_value->IsTrue());
1565 CHECK(!false_value->IsFalse());
1566
1567 Local<BooleanObject> false_boolean_object = false_value.As<BooleanObject>();
1568 CHECK(!false_boolean_object->IsBoolean());
1569 CHECK(false_boolean_object->IsBooleanObject());
1570 // TODO(svenpanne) Uncomment when BooleanObject::BooleanValue() is deleted.
1571 // CHECK(false_boolean_object->BooleanValue());
1572 CHECK(!false_boolean_object->ValueOf());
1573 CHECK(!false_boolean_object->IsTrue());
1574 CHECK(!false_boolean_object->IsFalse());
1575
1576 Local<Value> primitive_true = Boolean::New(true);
1577 CHECK(primitive_true->IsBoolean());
1578 CHECK(!primitive_true->IsBooleanObject());
1579 CHECK(primitive_true->BooleanValue());
1580 CHECK(primitive_true->IsTrue());
1581 CHECK(!primitive_true->IsFalse());
1582
1583 Local<Value> true_value = BooleanObject::New(true);
1584 CHECK(!true_value->IsBoolean());
1585 CHECK(true_value->IsBooleanObject());
1586 CHECK(true_value->BooleanValue());
1587 CHECK(!true_value->IsTrue());
1588 CHECK(!true_value->IsFalse());
1589
1590 Local<BooleanObject> true_boolean_object = true_value.As<BooleanObject>();
1591 CHECK(!true_boolean_object->IsBoolean());
1592 CHECK(true_boolean_object->IsBooleanObject());
1593 // TODO(svenpanne) Uncomment when BooleanObject::BooleanValue() is deleted.
1594 // CHECK(true_boolean_object->BooleanValue());
1595 CHECK(true_boolean_object->ValueOf());
1596 CHECK(!true_boolean_object->IsTrue());
1597 CHECK(!true_boolean_object->IsFalse());
1598 }
1599
1600
1601 THREADED_TEST(Number) { 1512 THREADED_TEST(Number) {
1602 LocalContext env; 1513 LocalContext env;
1603 v8::HandleScope scope(env->GetIsolate()); 1514 v8::HandleScope scope(env->GetIsolate());
1604 double PI = 3.1415926; 1515 double PI = 3.1415926;
1605 Local<v8::Number> pi_obj = v8::Number::New(PI); 1516 Local<v8::Number> pi_obj = v8::Number::New(PI);
1606 CHECK_EQ(PI, pi_obj->NumberValue()); 1517 CHECK_EQ(PI, pi_obj->NumberValue());
1607 } 1518 }
1608 1519
1609 1520
1610 THREADED_TEST(ToNumber) { 1521 THREADED_TEST(ToNumber) {
(...skipping 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after
2613 CHECK(sym_val->StrictEquals(sym2)); 2524 CHECK(sym_val->StrictEquals(sym2));
2614 CHECK(v8::Symbol::Cast(*sym_val)->Equals(sym2)); 2525 CHECK(v8::Symbol::Cast(*sym_val)->Equals(sym2));
2615 2526
2616 v8::Local<v8::Value> sym_obj = v8::SymbolObject::New(isolate, sym2); 2527 v8::Local<v8::Value> sym_obj = v8::SymbolObject::New(isolate, sym2);
2617 CHECK(sym_obj->IsSymbolObject()); 2528 CHECK(sym_obj->IsSymbolObject());
2618 CHECK(!sym2->IsSymbolObject()); 2529 CHECK(!sym2->IsSymbolObject());
2619 CHECK(!obj->IsSymbolObject()); 2530 CHECK(!obj->IsSymbolObject());
2620 CHECK(sym_obj->Equals(sym2)); 2531 CHECK(sym_obj->Equals(sym2));
2621 CHECK(!sym_obj->StrictEquals(sym2)); 2532 CHECK(!sym_obj->StrictEquals(sym2));
2622 CHECK(v8::SymbolObject::Cast(*sym_obj)->Equals(sym_obj)); 2533 CHECK(v8::SymbolObject::Cast(*sym_obj)->Equals(sym_obj));
2623 CHECK(v8::SymbolObject::Cast(*sym_obj)->ValueOf()->Equals(sym2)); 2534 CHECK(v8::SymbolObject::Cast(*sym_obj)->SymbolValue()->Equals(sym2));
2624 2535
2625 // Make sure delete of a non-existent symbol property works. 2536 // Make sure delete of a non-existent symbol property works.
2626 CHECK(obj->Delete(sym1)); 2537 CHECK(obj->Delete(sym1));
2627 CHECK(!obj->Has(sym1)); 2538 CHECK(!obj->Has(sym1));
2628 2539
2629 CHECK(obj->Set(sym1, v8::Integer::New(1503))); 2540 CHECK(obj->Set(sym1, v8::Integer::New(1503)));
2630 CHECK(obj->Has(sym1)); 2541 CHECK(obj->Has(sym1));
2631 CHECK_EQ(1503, obj->Get(sym1)->Int32Value()); 2542 CHECK_EQ(1503, obj->Get(sym1)->Int32Value());
2632 CHECK(obj->Set(sym1, v8::Integer::New(2002))); 2543 CHECK(obj->Set(sym1, v8::Integer::New(2002)));
2633 CHECK(obj->Has(sym1)); 2544 CHECK(obj->Has(sym1));
(...skipping 10587 matching lines...) Expand 10 before | Expand all | Expand 10 after
13221 v8::String::Utf8Value name(value); 13132 v8::String::Utf8Value name(value);
13222 CHECK_EQ("asdf", *name); 13133 CHECK_EQ("asdf", *name);
13223 } 13134 }
13224 13135
13225 13136
13226 THREADED_TEST(DateAccess) { 13137 THREADED_TEST(DateAccess) {
13227 LocalContext context; 13138 LocalContext context;
13228 v8::HandleScope scope(context->GetIsolate()); 13139 v8::HandleScope scope(context->GetIsolate());
13229 v8::Handle<v8::Value> date = v8::Date::New(1224744689038.0); 13140 v8::Handle<v8::Value> date = v8::Date::New(1224744689038.0);
13230 CHECK(date->IsDate()); 13141 CHECK(date->IsDate());
13231 CHECK_EQ(1224744689038.0, date.As<v8::Date>()->ValueOf()); 13142 CHECK_EQ(1224744689038.0, date.As<v8::Date>()->NumberValue());
13232 } 13143 }
13233 13144
13234 13145
13235 void CheckProperties(v8::Handle<v8::Value> val, int elmc, const char* elmv[]) { 13146 void CheckProperties(v8::Handle<v8::Value> val, int elmc, const char* elmv[]) {
13236 v8::Handle<v8::Object> obj = val.As<v8::Object>(); 13147 v8::Handle<v8::Object> obj = val.As<v8::Object>();
13237 v8::Handle<v8::Array> props = obj->GetPropertyNames(); 13148 v8::Handle<v8::Array> props = obj->GetPropertyNames();
13238 CHECK_EQ(elmc, props->Length()); 13149 CHECK_EQ(elmc, props->Length());
13239 for (int i = 0; i < elmc; i++) { 13150 for (int i = 0; i < elmc; i++) {
13240 v8::String::Utf8Value elm(props->Get(v8::Integer::New(i))); 13151 v8::String::Utf8Value elm(props->Get(v8::Integer::New(i)));
13241 CHECK_EQ(elmv[i], *elm); 13152 CHECK_EQ(elmv[i], *elm);
(...skipping 6744 matching lines...) Expand 10 before | Expand all | Expand 10 after
19986 CheckCorrectThrow("%HasProperty(other, 'x')"); 19897 CheckCorrectThrow("%HasProperty(other, 'x')");
19987 CheckCorrectThrow("%HasElement(other, 1)"); 19898 CheckCorrectThrow("%HasElement(other, 1)");
19988 CheckCorrectThrow("%IsPropertyEnumerable(other, 'x')"); 19899 CheckCorrectThrow("%IsPropertyEnumerable(other, 'x')");
19989 CheckCorrectThrow("%GetPropertyNames(other)"); 19900 CheckCorrectThrow("%GetPropertyNames(other)");
19990 CheckCorrectThrow("%GetLocalPropertyNames(other, true)"); 19901 CheckCorrectThrow("%GetLocalPropertyNames(other, true)");
19991 CheckCorrectThrow("%DefineOrRedefineAccessorProperty(" 19902 CheckCorrectThrow("%DefineOrRedefineAccessorProperty("
19992 "other, 'x', null, null, 1)"); 19903 "other, 'x', null, null, 1)");
19993 } 19904 }
19994 19905
19995 #endif // WIN32 19906 #endif // WIN32
OLDNEW
« no previous file with comments | « src/x64/lithium-x64.cc ('k') | test/cctest/test-cpu-profiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698