19 static uint32_t gen() {
24 seed =
static_cast<unsigned int>(z);
25 return static_cast<uint32_t
>(
seed >> 16);
29 using namespace v8::internal;
34 static void InitializeVM() {
37 const char* extensions[] = {
"v8/print" };
46 static const int NUMBER_OF_BUILDING_BLOCKS = 128;
47 static const int DEEP_DEPTH = 8 * 1024;
48 static const int SUPER_DEEP_DEPTH = 80 * 1024;
55 length_ =
string.length();
58 virtual size_t length()
const {
return length_; }
70 length_ =
string.length();
72 virtual const char*
data()
const {
return data_; }
73 virtual size_t length()
const {
return length_; }
81 static void InitializeBuildingBlocks(
85 Zone* zone = Isolate::Current()->zone();
86 for (
int i = 0; i < NUMBER_OF_BUILDING_BLOCKS; i++) {
94 for (
int j = 0; j < len; j++) {
95 buf[j] = gen() % 65536;
99 for (
int j = 0; j < len; j++) {
100 CHECK_EQ(buf[j], building_blocks[i]->Get(j));
106 for (
int j = 0; j < len; j++) {
107 buf[j] = gen() % 128;
111 for (
int j = 0; j < len; j++) {
112 CHECK_EQ(buf[j], building_blocks[i]->Get(j));
118 for (
int j = 0; j < len; j++) {
119 buf[j] = gen() % 65536;
122 building_blocks[i] =
FACTORY->NewExternalStringFromTwoByte(resource);
123 for (
int j = 0; j < len; j++) {
124 CHECK_EQ(buf[j], building_blocks[i]->Get(j));
129 char* buf = NewArray<char>(len);
130 for (
int j = 0; j < len; j++) {
131 buf[j] = gen() % 128;
135 for (
int j = 0; j < len; j++) {
136 CHECK_EQ(buf[j], building_blocks[i]->Get(j));
138 DeleteArray<char>(buf);
150 for (
int i = 0; i < depth; i++) {
151 answer =
FACTORY->NewConsString(
153 building_blocks[i % NUMBER_OF_BUILDING_BLOCKS]);
163 for (
int i = depth - 1; i >= 0; i--) {
164 answer =
FACTORY->NewConsString(
165 building_blocks[i % NUMBER_OF_BUILDING_BLOCKS],
177 if (to - from == 1) {
178 return building_blocks[from % NUMBER_OF_BUILDING_BLOCKS];
180 if (to - from == 2) {
182 building_blocks[from % NUMBER_OF_BUILDING_BLOCKS],
183 building_blocks[(from+1) % NUMBER_OF_BUILDING_BLOCKS]);
186 ConstructBalancedHelper(building_blocks, from, from + ((to - from) / 2));
188 ConstructBalancedHelper(building_blocks, from + ((to - from) / 2), to);
189 return FACTORY->NewConsString(part1, part2);
195 return ConstructBalancedHelper(building_blocks, 0, DEEP_DEPTH);
207 CHECK(buffer2.has_more());
221 while (buffer.
has_more() && i < chars) {
222 CHECK(buffer2.has_more());
227 s1->Get(s1->length() - 1);
228 s2->Get(s2->length() - 1);
233 printf(
"TestTraverse\n");
238 InitializeBuildingBlocks(building_blocks);
241 Handle<String> left_asymmetric = ConstructLeft(building_blocks, DEEP_DEPTH);
242 Handle<String> right_asymmetric = ConstructRight(building_blocks, DEEP_DEPTH);
245 Traverse(flat, symmetric);
247 Traverse(flat, left_asymmetric);
249 Traverse(flat, right_asymmetric);
252 ConstructLeft(building_blocks, SUPER_DEEP_DEPTH);
254 ConstructRight(building_blocks, SUPER_DEEP_DEPTH);
256 TraverseFirst(left_asymmetric, left_deep_asymmetric, 1050);
258 TraverseFirst(left_asymmetric, right_deep_asymmetric, 65536);
262 Traverse(flat, left_asymmetric);
266 Traverse(flat, right_asymmetric);
270 Traverse(flat, symmetric);
277 static const int DEEP_ASCII_DEPTH = 100000;
281 printf(
"TestDeepAscii\n");
285 char*
foo = NewArray<char>(DEEP_ASCII_DEPTH);
286 for (
int i = 0; i < DEEP_ASCII_DEPTH; i++) {
287 foo[i] =
"foo "[i % 4];
292 for (
int i = 0; i < DEEP_ASCII_DEPTH; i += 10) {
293 string =
FACTORY->NewConsString(
string, foo_string);
298 for (
int i = 0; i < 500; i++) {
299 TraverseFirst(flat_string,
string, DEEP_ASCII_DEPTH);
301 DeleteArray<char>(
foo);
310 const char* ascii_string =
"abcdef12345";
321 const uint16_t mixed_string[] = {0x02E4, 0x0064, 0x12E4, 0x0030, 0x3045};
323 const unsigned char as_utf8[11] = {0xCB, 0xA4, 0x64, 0xE1, 0x8B, 0xA4, 0x30,
324 0xE3, 0x81, 0x85, 0x00};
326 const int lengths[12] = {0, 0, 2, 3, 3, 3, 6, 7, 7, 7, 10, 11};
327 const int char_lengths[12] = {0, 0, 1, 2, 2, 2, 3, 4, 4, 4, 5, 5};
332 const char kNoChar =
static_cast<char>(-1);
333 for (
int i = 0; i <= 11; i++) {
335 for (
int j = 0; j < 11; j++)
338 int written = mixed->
WriteUtf8(buffer, i, &chars_written);
340 CHECK_EQ(char_lengths[i], chars_written);
342 for (
int j = 0; j < lengths[i]; j++)
343 CHECK_EQ(as_utf8[j], static_cast<unsigned char>(buffer[j]));
345 for (
int j = lengths[i]; j < 11; j++)
356 Zone* zone = Isolate::Current()->zone();
359 static const int kMaxLength = 20;
369 for (
int i = 0; i <= kMaxLength; i++) {
370 char* ascii = zone->
NewArray<
char>(i + 1);
371 for (
int j = 0; j < i; j++) {
383 for (
int j = 0; j < i; j++) {
384 non_ascii[j] = 0x1234;
392 non_ascii_external_string);
397 global->
Set(v8_str(
"external_ascii"), ascii_external_strings);
398 global->
Set(v8_str(
"external_non_ascii"), non_ascii_external_strings);
402 static const char* source =
404 " var ascii_chars = 'aaaaaaaaaaaaaaaaaaaa';"
405 " var non_ascii_chars = '\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234';"
406 " if (ascii_chars.length != max_length) return 1;"
407 " if (non_ascii_chars.length != max_length) return 2;"
408 " var ascii = Array(max_length + 1);"
409 " var non_ascii = Array(max_length + 1);"
410 " for (var i = 0; i <= max_length; i++) {"
411 " ascii[i] = ascii_chars.substring(0, i);"
412 " non_ascii[i] = non_ascii_chars.substring(0, i);"
414 " for (var i = 0; i <= max_length; i++) {"
415 " if (ascii[i] != external_ascii[i]) return 3;"
416 " if (non_ascii[i] != external_non_ascii[i]) return 4;"
417 " for (var j = 0; j < i; j++) {"
418 " if (external_ascii[i] !="
419 " (external_ascii[j] + external_ascii[i - j])) return 5;"
420 " if (external_non_ascii[i] !="
421 " (external_non_ascii[j] + external_non_ascii[i - j])) return 6;"
422 " if (non_ascii[i] != (non_ascii[j] + non_ascii[i - j])) return 7;"
423 " if (ascii[i] != (ascii[j] + ascii[i - j])) return 8;"
424 " if (ascii[i] != (external_ascii[j] + ascii[i - j])) return 9;"
425 " if (ascii[i] != (ascii[j] + external_ascii[i - j])) return 10;"
426 " if (non_ascii[i] !="
427 " (external_non_ascii[j] + non_ascii[i - j])) return 11;"
428 " if (non_ascii[i] !="
429 " (non_ascii[j] + external_non_ascii[i - j])) return 12;"
435 CHECK_EQ(0, CompileRun(source)->Int32Value());
449 const char* lines[] = {
452 "var s = \"1073741828\";",
473 for (
int i = 0; (line = lines[i]); i++) {
474 printf(
"%s\n", line);
488 FLAG_string_slices =
true;
494 CHECK(parent->IsConsString());
495 CHECK(!parent->IsFlat());
498 CHECK(parent->IsFlat());
499 CHECK(slice->IsSlicedString());
503 CHECK(slice->IsFlat());
512 virtual size_t length()
const {
return data_.length(); }
513 virtual const char*
data()
const {
return data_.start(); }
520 FLAG_string_slices =
true;
526 CHECK(string->IsExternalString());
528 CHECK(slice->IsSlicedString());
529 CHECK(string->IsExternalString());
532 CHECK(slice->IsFlat());
539 FLAG_string_slices =
true;
544 const char* init =
"var str = 'abcdefghijklmnopqrstuvwxyz';";
545 const char*
check =
"str.slice(0,26)";
546 const char* crosscheck =
"str.slice(1,25)";
550 result = CompileRun(check);
553 CHECK(!string->IsSlicedString());
555 string =
FACTORY->NewSubString(
string, 0, 26);
556 CHECK(!string->IsSlicedString());
557 result = CompileRun(crosscheck);
558 CHECK(result->IsString());
560 CHECK(string->IsSlicedString());
561 CHECK_EQ(
"bcdefghijklmnopqrstuvwxy", *(string->ToCString()));
568 FLAG_string_slices =
true;
573 const char* init =
"var str = 'abcdefghijklmnopqrstuvwxyz';";
574 const char* slice =
"var slice = str.slice(1,-1); slice";
575 const char* slice_from_slice =
"slice.slice(1,-1);";
578 result = CompileRun(slice);
581 CHECK(string->IsSlicedString());
583 CHECK_EQ(
"bcdefghijklmnopqrstuvwxy", *(string->ToCString()));
585 result = CompileRun(slice_from_slice);
588 CHECK(string->IsSlicedString());
590 CHECK_EQ(
"cdefghijklmnopqrstuvwx", *(string->ToCString()));
596 static const int K = 1024;
606 static const char* join_causing_out_of_memory =
607 "var two_14 = Math.pow(2, 14);"
608 "var two_17 = Math.pow(2, 17);"
609 "var s = Array(two_17 + 1).join('c');"
611 "for (var i = 1; i <= two_14; i++) a.push(s);"
627 static void CheckException(
const char* source) {
629 CHECK(CompileRun(source).IsEmpty());
636 FLAG_allow_natives_syntax =
true;
641 CompileRun(
"var short = 'abcdef';");
644 CheckException(
"%_SubString(short, 0, 10000);");
645 CheckException(
"%_SubString(short, -1234, 5);");
646 CheckException(
"%_SubString(short, 5, 2);");
648 CheckException(
"%_SubString(short, 1, Infinity);");
649 CheckException(
"%_SubString(short, NaN, 5);");
651 CheckException(
"%_SubString(short, '2', '5');");
653 result = CompileRun(
"%_SubString(short, Math.sqrt(4), 5.1);");
655 CHECK_EQ(
"cde", *(string->ToCString()));
657 CompileRun(
"var long = 'abcdefghijklmnopqrstuvwxyz';");
659 CheckException(
"%_SubString(long, 0, 10000);");
660 CheckException(
"%_SubString(long, -1234, 17);");
661 CheckException(
"%_SubString(long, 17, 2);");
663 CheckException(
"%_SubString(long, 1, Infinity);");
664 CheckException(
"%_SubString(long, NaN, 17);");
666 CheckException(
"%_SubString(long, '2', '17');");
668 result = CompileRun(
"%_SubString(long, Math.sqrt(4), 17.1);");
670 CHECK_EQ(
"cdefghijklmnopq", *(string->ToCString()));
674 CompileRun(
"var slice = long.slice(1, 15);");
675 CheckException(
"%_SubString(slice, 0, 17);");
687 "for (var i = 0; i < 16; i++) { "
690 "a.replace(/a/g, a); ");
static Local< Script > Compile(Handle< String > source, ScriptOrigin *origin=NULL, ScriptData *pre_data=NULL, Handle< String > script_data=Handle< String >())
void FlattenString(Handle< String > string)
V8EXPORT int WriteUtf8(char *buffer, int length=-1, int *nchars_ref=NULL, int options=NO_OPTIONS) const
void set_max_young_space_size(int value)
#define CHECK_EQ(expected, value)
bool HasOutOfMemoryException()
static Smi * FromInt(int value)
static V8EXPORT Local< String > New(const char *data, int length=-1)
V8EXPORT Local< Int32 > ToInt32() const
AsciiResource(Vector< const char > string)
virtual const char * data() const
static Smi * cast(Object *object)
virtual size_t length() const
static const int kMinLength
void set_max_old_space_size(int value)
static SlicedString * cast(Object *obj)
V8EXPORT int Utf8Length() const
virtual ~AsciiVectorResource()
virtual size_t length() const
static String * Cast(v8::Value *obj)
virtual const uint16_t * data() const
virtual const char * data() const
Vector< const char > CStrVector(const char *data)
int StrLength(const char *string)
V8EXPORT bool IsNumber() const
AsciiVectorResource(i::Vector< const char > vector)
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination trace on stack replacement optimize closures functions with arguments object optimize functions containing for in loops profiler considers IC stability primitive functions trigger their own optimization re try self optimization if it failed insert an interrupt check at function exit execution budget before interrupt is triggered call count before self optimization self_optimization count_based_interrupts weighted_back_edges trace_opt emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 enable use of ARMv7 instructions if enable use of MIPS FPU instructions if NULL
static V8EXPORT Local< Integer > New(int32_t value)
virtual size_t length() const
static Persistent< Context > New(ExtensionConfiguration *extensions=NULL, Handle< ObjectTemplate > global_template=Handle< ObjectTemplate >(), Handle< Value > global_object=Handle< Value >())
static V8EXPORT Local< String > NewExternal(ExternalStringResource *resource)
bool V8EXPORT SetResourceConstraints(ResourceConstraints *constraints)
static ConsString * cast(Object *obj)
void check(i::Vector< const char > string)
Resource(Vector< const uc16 > string)
static V8EXPORT Local< Object > New()
static v8::internal::Handle< v8::internal::TemplateInfo > OpenHandle(const Template *that)
V8EXPORT bool Set(Handle< Value > key, Handle< Value > value, PropertyAttribute attribs=None)
static void IgnoreOutOfMemoryException()