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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 v8::HandleScope scope; | 247 v8::HandleScope scope; |
248 LocalContext env; | 248 LocalContext env; |
249 const char* c_source = "1 + 2 + 3"; | 249 const char* c_source = "1 + 2 + 3"; |
250 Local<String> source = String::New(c_source); | 250 Local<String> source = String::New(c_source); |
251 Local<Script> script = Script::Compile(source); | 251 Local<Script> script = Script::Compile(source); |
252 CHECK_EQ(6, script->Run()->Int32Value()); | 252 CHECK_EQ(6, script->Run()->Int32Value()); |
253 } | 253 } |
254 | 254 |
255 | 255 |
256 static uint16_t* AsciiToTwoByteString(const char* source) { | 256 static uint16_t* AsciiToTwoByteString(const char* source) { |
257 size_t array_length = strlen(source) + 1; | 257 int array_length = i::StrLength(source) + 1; |
258 uint16_t* converted = i::NewArray<uint16_t>(array_length); | 258 uint16_t* converted = i::NewArray<uint16_t>(array_length); |
259 for (size_t i = 0; i < array_length; i++) converted[i] = source[i]; | 259 for (int i = 0; i < array_length; i++) converted[i] = source[i]; |
260 return converted; | 260 return converted; |
261 } | 261 } |
262 | 262 |
263 | 263 |
264 class TestResource: public String::ExternalStringResource { | 264 class TestResource: public String::ExternalStringResource { |
265 public: | 265 public: |
266 static int dispose_count; | 266 static int dispose_count; |
267 | 267 |
268 explicit TestResource(uint16_t* data) | 268 explicit TestResource(uint16_t* data) |
269 : data_(data), length_(0) { | 269 : data_(data), length_(0) { |
(...skipping 6372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6642 | 6642 |
6643 | 6643 |
6644 // This test verifies that pre-compilation (aka preparsing) can be called | 6644 // This test verifies that pre-compilation (aka preparsing) can be called |
6645 // without initializing the whole VM. Thus we cannot run this test in a | 6645 // without initializing the whole VM. Thus we cannot run this test in a |
6646 // multi-threaded setup. | 6646 // multi-threaded setup. |
6647 TEST(PreCompile) { | 6647 TEST(PreCompile) { |
6648 // TODO(155): This test would break without the initialization of V8. This is | 6648 // TODO(155): This test would break without the initialization of V8. This is |
6649 // a workaround for now to make this test not fail. | 6649 // a workaround for now to make this test not fail. |
6650 v8::V8::Initialize(); | 6650 v8::V8::Initialize(); |
6651 const char *script = "function foo(a) { return a+1; }"; | 6651 const char *script = "function foo(a) { return a+1; }"; |
6652 v8::ScriptData *sd = v8::ScriptData::PreCompile(script, strlen(script)); | 6652 v8::ScriptData *sd = |
| 6653 v8::ScriptData::PreCompile(script, i::StrLength(script)); |
6653 CHECK_NE(sd->Length(), 0); | 6654 CHECK_NE(sd->Length(), 0); |
6654 CHECK_NE(sd->Data(), NULL); | 6655 CHECK_NE(sd->Data(), NULL); |
6655 delete sd; | 6656 delete sd; |
6656 } | 6657 } |
6657 | 6658 |
6658 | 6659 |
6659 // This tests that we do not allow dictionary load/call inline caches | 6660 // This tests that we do not allow dictionary load/call inline caches |
6660 // to use functions that have not yet been compiled. The potential | 6661 // to use functions that have not yet been compiled. The potential |
6661 // problem of loading a function that has not yet been compiled can | 6662 // problem of loading a function that has not yet been compiled can |
6662 // arise because we share code between contexts via the compilation | 6663 // arise because we share code between contexts via the compilation |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7038 // Test that we can still flatten a string if the components it is built up | 7039 // Test that we can still flatten a string if the components it is built up |
7039 // from have been turned into 16 bit strings in the mean time. | 7040 // from have been turned into 16 bit strings in the mean time. |
7040 THREADED_TEST(MorphCompositeStringTest) { | 7041 THREADED_TEST(MorphCompositeStringTest) { |
7041 const char* c_string = "Now is the time for all good men" | 7042 const char* c_string = "Now is the time for all good men" |
7042 " to come to the aid of the party"; | 7043 " to come to the aid of the party"; |
7043 uint16_t* two_byte_string = AsciiToTwoByteString(c_string); | 7044 uint16_t* two_byte_string = AsciiToTwoByteString(c_string); |
7044 { | 7045 { |
7045 v8::HandleScope scope; | 7046 v8::HandleScope scope; |
7046 LocalContext env; | 7047 LocalContext env; |
7047 AsciiVectorResource ascii_resource( | 7048 AsciiVectorResource ascii_resource( |
7048 i::Vector<const char>(c_string, strlen(c_string))); | 7049 i::Vector<const char>(c_string, i::StrLength(c_string))); |
7049 UC16VectorResource uc16_resource( | 7050 UC16VectorResource uc16_resource( |
7050 i::Vector<const uint16_t>(two_byte_string, strlen(c_string))); | 7051 i::Vector<const uint16_t>(two_byte_string, |
| 7052 i::StrLength(c_string))); |
7051 | 7053 |
7052 Local<String> lhs(v8::Utils::ToLocal( | 7054 Local<String> lhs(v8::Utils::ToLocal( |
7053 i::Factory::NewExternalStringFromAscii(&ascii_resource))); | 7055 i::Factory::NewExternalStringFromAscii(&ascii_resource))); |
7054 Local<String> rhs(v8::Utils::ToLocal( | 7056 Local<String> rhs(v8::Utils::ToLocal( |
7055 i::Factory::NewExternalStringFromAscii(&ascii_resource))); | 7057 i::Factory::NewExternalStringFromAscii(&ascii_resource))); |
7056 | 7058 |
7057 env->Global()->Set(v8_str("lhs"), lhs); | 7059 env->Global()->Set(v8_str("lhs"), lhs); |
7058 env->Global()->Set(v8_str("rhs"), rhs); | 7060 env->Global()->Set(v8_str("rhs"), rhs); |
7059 | 7061 |
7060 CompileRun( | 7062 CompileRun( |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7098 "0.5", | 7100 "0.5", |
7099 "-0.5", // This mainly testes PushBack in the Scanner. | 7101 "-0.5", // This mainly testes PushBack in the Scanner. |
7100 "--0.5", // This mainly testes PushBack in the Scanner. | 7102 "--0.5", // This mainly testes PushBack in the Scanner. |
7101 NULL | 7103 NULL |
7102 }; | 7104 }; |
7103 | 7105 |
7104 // Compile the sources as external two byte strings. | 7106 // Compile the sources as external two byte strings. |
7105 for (int i = 0; ascii_sources[i] != NULL; i++) { | 7107 for (int i = 0; ascii_sources[i] != NULL; i++) { |
7106 uint16_t* two_byte_string = AsciiToTwoByteString(ascii_sources[i]); | 7108 uint16_t* two_byte_string = AsciiToTwoByteString(ascii_sources[i]); |
7107 UC16VectorResource uc16_resource( | 7109 UC16VectorResource uc16_resource( |
7108 i::Vector<const uint16_t>(two_byte_string, strlen(ascii_sources[i]))); | 7110 i::Vector<const uint16_t>(two_byte_string, |
| 7111 i::StrLength(ascii_sources[i]))); |
7109 v8::Local<v8::String> source = v8::String::NewExternal(&uc16_resource); | 7112 v8::Local<v8::String> source = v8::String::NewExternal(&uc16_resource); |
7110 v8::Script::Compile(source); | 7113 v8::Script::Compile(source); |
7111 } | 7114 } |
7112 } | 7115 } |
7113 | 7116 |
7114 | 7117 |
7115 class RegExpStringModificationTest { | 7118 class RegExpStringModificationTest { |
7116 public: | 7119 public: |
7117 RegExpStringModificationTest() | 7120 RegExpStringModificationTest() |
7118 : block_(i::OS::CreateSemaphore(0)), | 7121 : block_(i::OS::CreateSemaphore(0)), |
(...skipping 1091 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8210 v8::Locker locker; | 8213 v8::Locker locker; |
8211 CHECK(stack_limit == set_limit); | 8214 CHECK(stack_limit == set_limit); |
8212 } | 8215 } |
8213 } | 8216 } |
8214 | 8217 |
8215 | 8218 |
8216 THREADED_TEST(GetHeapStatistics) { | 8219 THREADED_TEST(GetHeapStatistics) { |
8217 v8::HandleScope scope; | 8220 v8::HandleScope scope; |
8218 LocalContext c1; | 8221 LocalContext c1; |
8219 v8::HeapStatistics heap_statistics; | 8222 v8::HeapStatistics heap_statistics; |
8220 CHECK_EQ(heap_statistics.total_heap_size(), 0); | 8223 CHECK_EQ(static_cast<int>(heap_statistics.total_heap_size()), 0); |
8221 CHECK_EQ(heap_statistics.used_heap_size(), 0); | 8224 CHECK_EQ(static_cast<int>(heap_statistics.used_heap_size()), 0); |
8222 v8::V8::GetHeapStatistics(&heap_statistics); | 8225 v8::V8::GetHeapStatistics(&heap_statistics); |
8223 CHECK_NE(heap_statistics.total_heap_size(), 0); | 8226 CHECK_NE(static_cast<int>(heap_statistics.total_heap_size()), 0); |
8224 CHECK_NE(heap_statistics.used_heap_size(), 0); | 8227 CHECK_NE(static_cast<int>(heap_statistics.used_heap_size()), 0); |
8225 } | 8228 } |
8226 | 8229 |
8227 | 8230 |
8228 static double DoubleFromBits(uint64_t value) { | 8231 static double DoubleFromBits(uint64_t value) { |
8229 double target; | 8232 double target; |
8230 #ifdef BIG_ENDIAN_FLOATING_POINT | 8233 #ifdef BIG_ENDIAN_FLOATING_POINT |
8231 const int kIntSize = 4; | 8234 const int kIntSize = 4; |
8232 // Somebody swapped the lower and higher half of doubles. | 8235 // Somebody swapped the lower and higher half of doubles. |
8233 memcpy(&target, reinterpret_cast<char*>(&value) + kIntSize, kIntSize); | 8236 memcpy(&target, reinterpret_cast<char*>(&value) + kIntSize, kIntSize); |
8234 memcpy(reinterpret_cast<char*>(&target) + kIntSize, &value, kIntSize); | 8237 memcpy(reinterpret_cast<char*>(&target) + kIntSize, &value, kIntSize); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8369 " i++;" | 8372 " i++;" |
8370 " return s(o);" | 8373 " return s(o);" |
8371 " }" | 8374 " }" |
8372 " }" | 8375 " }" |
8373 "};" | 8376 "};" |
8374 "s(o);"); | 8377 "s(o);"); |
8375 CHECK(try_catch.HasCaught()); | 8378 CHECK(try_catch.HasCaught()); |
8376 v8::String::Utf8Value value(try_catch.Exception()); | 8379 v8::String::Utf8Value value(try_catch.Exception()); |
8377 CHECK_EQ(0, strcmp(*value, "Hey!")); | 8380 CHECK_EQ(0, strcmp(*value, "Hey!")); |
8378 } | 8381 } |
OLD | NEW |