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 17015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17026 reresult = CompileRun("str2.charCodeAt(2);"); | 17026 reresult = CompileRun("str2.charCodeAt(2);"); |
17027 CHECK_EQ(static_cast<int32_t>('e'), reresult->Int32Value()); | 17027 CHECK_EQ(static_cast<int32_t>('e'), reresult->Int32Value()); |
17028 } | 17028 } |
17029 | 17029 |
17030 | 17030 |
17031 TEST(ContainsOnlyOneByte) { | 17031 TEST(ContainsOnlyOneByte) { |
17032 v8::V8::Initialize(); | 17032 v8::V8::Initialize(); |
17033 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 17033 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
17034 v8::HandleScope scope(isolate); | 17034 v8::HandleScope scope(isolate); |
17035 // Make a buffer long enough that it won't automatically be converted. | 17035 // Make a buffer long enough that it won't automatically be converted. |
17036 const int length = 200; | 17036 const int length = 512; |
17037 i::SmartArrayPointer<uint16_t> string_contents(new uint16_t[length]); | 17037 // Ensure word aligned assignment. |
| 17038 const int aligned_length = length*sizeof(uintptr_t)/sizeof(uint16_t); |
| 17039 i::SmartArrayPointer<uintptr_t> |
| 17040 aligned_contents(new uintptr_t[aligned_length]); |
| 17041 uint16_t* string_contents = reinterpret_cast<uint16_t*>(*aligned_contents); |
17038 // Set to contain only one byte. | 17042 // Set to contain only one byte. |
17039 for (int i = 0; i < length-1; i++) { | 17043 for (int i = 0; i < length-1; i++) { |
17040 string_contents[i] = 0x41; | 17044 string_contents[i] = 0x41; |
17041 } | 17045 } |
17042 string_contents[length-1] = 0; | 17046 string_contents[length-1] = 0; |
17043 // Simple case. | 17047 // Simple case. |
17044 Handle<String> string; | 17048 Handle<String> string; |
17045 string = String::NewExternal(new TestResource(*string_contents)); | 17049 string = String::NewExternal(new TestResource(string_contents)); |
17046 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte()); | 17050 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte()); |
17047 // Counter example. | 17051 // Counter example. |
17048 string = String::NewFromTwoByte(isolate, *string_contents); | 17052 string = String::NewFromTwoByte(isolate, string_contents); |
17049 CHECK(string->IsOneByte() && string->ContainsOnlyOneByte()); | 17053 CHECK(string->IsOneByte() && string->ContainsOnlyOneByte()); |
17050 // Test left right and balanced cons strings. | 17054 // Test left right and balanced cons strings. |
17051 Handle<String> base = String::NewFromUtf8(isolate, "a"); | 17055 Handle<String> base = String::NewFromUtf8(isolate, "a"); |
17052 Handle<String> left = base; | 17056 Handle<String> left = base; |
17053 Handle<String> right = base; | 17057 Handle<String> right = base; |
17054 for (int i = 0; i < 1000; i++) { | 17058 for (int i = 0; i < 1000; i++) { |
17055 left = String::Concat(base, left); | 17059 left = String::Concat(base, left); |
17056 right = String::Concat(right, base); | 17060 right = String::Concat(right, base); |
17057 } | 17061 } |
17058 Handle<String> balanced = String::Concat(left, base); | 17062 Handle<String> balanced = String::Concat(left, base); |
17059 balanced = String::Concat(balanced, right); | 17063 balanced = String::Concat(balanced, right); |
17060 Handle<String> cons_strings[] = {left, balanced, right}; | 17064 Handle<String> cons_strings[] = {left, balanced, right}; |
17061 Handle<String> two_byte = | 17065 Handle<String> two_byte = |
17062 String::NewExternal(new TestResource(*string_contents)); | 17066 String::NewExternal(new TestResource(string_contents)); |
17063 for (size_t i = 0; i < ARRAY_SIZE(cons_strings); i++) { | 17067 for (size_t i = 0; i < ARRAY_SIZE(cons_strings); i++) { |
17064 // Base assumptions. | 17068 // Base assumptions. |
17065 string = cons_strings[i]; | 17069 string = cons_strings[i]; |
17066 CHECK(string->IsOneByte() && string->ContainsOnlyOneByte()); | 17070 CHECK(string->IsOneByte() && string->ContainsOnlyOneByte()); |
17067 // Test left and right concatentation. | 17071 // Test left and right concatentation. |
17068 string = String::Concat(two_byte, cons_strings[i]); | 17072 string = String::Concat(two_byte, cons_strings[i]); |
17069 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte()); | 17073 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte()); |
17070 string = String::Concat(cons_strings[i], two_byte); | 17074 string = String::Concat(cons_strings[i], two_byte); |
17071 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte()); | 17075 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte()); |
17072 } | 17076 } |
| 17077 // Set bits in different positions |
| 17078 // for strings of different lengths and alignments. |
| 17079 for (int alignment = 0; alignment < 7; alignment++) { |
| 17080 for (int size = 2; alignment + size < length; size *= 2) { |
| 17081 int zero_offset = size + alignment; |
| 17082 string_contents[zero_offset] = 0; |
| 17083 for (int i = 0; i < size; i++) { |
| 17084 int shift = 8 + (i % 7); |
| 17085 string_contents[alignment + i] = 1 << shift; |
| 17086 string = |
| 17087 String::NewExternal(new TestResource(string_contents + alignment)); |
| 17088 CHECK_EQ(size, string->Length()); |
| 17089 CHECK(!string->ContainsOnlyOneByte()); |
| 17090 string_contents[alignment + i] = 0x41; |
| 17091 } |
| 17092 string_contents[zero_offset] = 0x41; |
| 17093 } |
| 17094 } |
17073 } | 17095 } |
17074 | 17096 |
17075 | 17097 |
17076 // Failed access check callback that performs a GC on each invocation. | 17098 // Failed access check callback that performs a GC on each invocation. |
17077 void FailedAccessCheckCallbackGC(Local<v8::Object> target, | 17099 void FailedAccessCheckCallbackGC(Local<v8::Object> target, |
17078 v8::AccessType type, | 17100 v8::AccessType type, |
17079 Local<v8::Value> data) { | 17101 Local<v8::Value> data) { |
17080 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 17102 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
17081 } | 17103 } |
17082 | 17104 |
(...skipping 2217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19300 i::Semaphore* sem_; | 19322 i::Semaphore* sem_; |
19301 volatile int sem_value_; | 19323 volatile int sem_value_; |
19302 }; | 19324 }; |
19303 | 19325 |
19304 | 19326 |
19305 THREADED_TEST(SemaphoreInterruption) { | 19327 THREADED_TEST(SemaphoreInterruption) { |
19306 ThreadInterruptTest().RunTest(); | 19328 ThreadInterruptTest().RunTest(); |
19307 } | 19329 } |
19308 | 19330 |
19309 #endif // WIN32 | 19331 #endif // WIN32 |
OLD | NEW |