| 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 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 | 806 |
| 807 Local<Value> result = v8_compile("(new obj()).toString()")->Run(); | 807 Local<Value> result = v8_compile("(new obj()).toString()")->Run(); |
| 808 CHECK_EQ(v8_str("[object funky]"), result); | 808 CHECK_EQ(v8_str("[object funky]"), result); |
| 809 | 809 |
| 810 result = v8_compile("(new obj()).m")->Run(); | 810 result = v8_compile("(new obj()).m")->Run(); |
| 811 CHECK_EQ(239, result->Int32Value()); | 811 CHECK_EQ(239, result->Int32Value()); |
| 812 } | 812 } |
| 813 } | 813 } |
| 814 | 814 |
| 815 | 815 |
| 816 static void* expected_ptr; |
| 817 static v8::Handle<v8::Value> callback(const v8::Arguments& args) { |
| 818 void* ptr = v8::External::Unwrap(args.Data()); |
| 819 CHECK_EQ(expected_ptr, ptr); |
| 820 return v8::Boolean::New(true); |
| 821 } |
| 822 |
| 823 |
| 824 static void TestExternalPointerWrapping() { |
| 825 v8::HandleScope scope; |
| 826 LocalContext env; |
| 827 |
| 828 v8::Handle<v8::Value> data = v8::External::Wrap(expected_ptr); |
| 829 |
| 830 v8::Handle<v8::Object> obj = v8::Object::New(); |
| 831 obj->Set(v8_str("func"), |
| 832 v8::FunctionTemplate::New(callback, data)->GetFunction()); |
| 833 env->Global()->Set(v8_str("obj"), obj); |
| 834 |
| 835 CHECK(CompileRun( |
| 836 "function foo() {\n" |
| 837 " for (var i = 0; i < 13; i++) obj.func();\n" |
| 838 "}\n" |
| 839 "foo(), true")->BooleanValue()); |
| 840 } |
| 841 |
| 842 |
| 843 THREADED_TEST(ExternalWrap) { |
| 844 // Check heap allocated object. |
| 845 int* ptr = new int; |
| 846 expected_ptr = ptr; |
| 847 TestExternalPointerWrapping(); |
| 848 delete ptr; |
| 849 |
| 850 // Check stack allocated object. |
| 851 int foo; |
| 852 expected_ptr = &foo; |
| 853 TestExternalPointerWrapping(); |
| 854 |
| 855 // Check not aligned addresses. |
| 856 const int n = 100; |
| 857 char* s = new char[n]; |
| 858 for (int i = 0; i < n; i++) { |
| 859 expected_ptr = s + i; |
| 860 TestExternalPointerWrapping(); |
| 861 } |
| 862 |
| 863 delete[] s; |
| 864 |
| 865 // Check several invalid addresses. |
| 866 expected_ptr = reinterpret_cast<void*>(1); |
| 867 TestExternalPointerWrapping(); |
| 868 |
| 869 expected_ptr = reinterpret_cast<void*>(0xdeadbeef); |
| 870 TestExternalPointerWrapping(); |
| 871 |
| 872 expected_ptr = reinterpret_cast<void*>(0xdeadbeef + 1); |
| 873 TestExternalPointerWrapping(); |
| 874 |
| 875 #if defined(V8_HOST_ARCH_X64) |
| 876 // Check a value with a leading 1 bit in x64 Smi encoding. |
| 877 expected_ptr = reinterpret_cast<void*>(0x400000000); |
| 878 TestExternalPointerWrapping(); |
| 879 |
| 880 expected_ptr = reinterpret_cast<void*>(0xdeadbeefdeadbeef); |
| 881 TestExternalPointerWrapping(); |
| 882 |
| 883 expected_ptr = reinterpret_cast<void*>(0xdeadbeefdeadbeef + 1); |
| 884 TestExternalPointerWrapping(); |
| 885 #endif |
| 886 } |
| 887 |
| 888 |
| 816 THREADED_TEST(FindInstanceInPrototypeChain) { | 889 THREADED_TEST(FindInstanceInPrototypeChain) { |
| 817 v8::HandleScope scope; | 890 v8::HandleScope scope; |
| 818 LocalContext env; | 891 LocalContext env; |
| 819 | 892 |
| 820 Local<v8::FunctionTemplate> base = v8::FunctionTemplate::New(); | 893 Local<v8::FunctionTemplate> base = v8::FunctionTemplate::New(); |
| 821 Local<v8::FunctionTemplate> derived = v8::FunctionTemplate::New(); | 894 Local<v8::FunctionTemplate> derived = v8::FunctionTemplate::New(); |
| 822 Local<v8::FunctionTemplate> other = v8::FunctionTemplate::New(); | 895 Local<v8::FunctionTemplate> other = v8::FunctionTemplate::New(); |
| 823 derived->Inherit(base); | 896 derived->Inherit(base); |
| 824 | 897 |
| 825 Local<v8::Function> base_function = base->GetFunction(); | 898 Local<v8::Function> base_function = base->GetFunction(); |
| (...skipping 1454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2280 " try {" | 2353 " try {" |
| 2281 " CCatcher('throw 7;');" | 2354 " CCatcher('throw 7;');" |
| 2282 " } finally {" | 2355 " } finally {" |
| 2283 " }" | 2356 " }" |
| 2284 "} catch (e) {" | 2357 "} catch (e) {" |
| 2285 "}"); | 2358 "}"); |
| 2286 CHECK(result->IsTrue()); | 2359 CHECK(result->IsTrue()); |
| 2287 } | 2360 } |
| 2288 | 2361 |
| 2289 | 2362 |
| 2363 static void check_reference_error_message( |
| 2364 v8::Handle<v8::Message> message, |
| 2365 v8::Handle<v8::Value> data) { |
| 2366 const char* reference_error = "Uncaught ReferenceError: asdf is not defined"; |
| 2367 CHECK(message->Get()->Equals(v8_str(reference_error))); |
| 2368 } |
| 2369 |
| 2370 |
| 2371 // Test that overwritten toString methods are not invoked on uncaught |
| 2372 // exception formatting. However, they are invoked when performing |
| 2373 // normal error string conversions. |
| 2374 TEST(APIThrowMessageOverwrittenToString) { |
| 2375 v8::HandleScope scope; |
| 2376 v8::V8::AddMessageListener(check_reference_error_message); |
| 2377 LocalContext context; |
| 2378 CompileRun("ReferenceError.prototype.toString =" |
| 2379 " function() { return 'Whoops' }"); |
| 2380 CompileRun("asdf;"); |
| 2381 CompileRun("ReferenceError.prototype.constructor.name = void 0;"); |
| 2382 CompileRun("asdf;"); |
| 2383 CompileRun("ReferenceError.prototype.constructor = void 0;"); |
| 2384 CompileRun("asdf;"); |
| 2385 CompileRun("ReferenceError.prototype.__proto__ = new Object();"); |
| 2386 CompileRun("asdf;"); |
| 2387 CompileRun("ReferenceError.prototype = new Object();"); |
| 2388 CompileRun("asdf;"); |
| 2389 v8::Handle<Value> string = CompileRun("try { asdf; } catch(e) { e + ''; }"); |
| 2390 CHECK(string->Equals(v8_str("Whoops"))); |
| 2391 CompileRun("ReferenceError.prototype.constructor = new Object();" |
| 2392 "ReferenceError.prototype.constructor.name = 1;" |
| 2393 "Number.prototype.toString = function() { return 'Whoops'; };" |
| 2394 "ReferenceError.prototype.toString = Object.prototype.toString;"); |
| 2395 CompileRun("asdf;"); |
| 2396 v8::V8::RemoveMessageListeners(check_message); |
| 2397 } |
| 2398 |
| 2399 |
| 2290 static void receive_message(v8::Handle<v8::Message> message, | 2400 static void receive_message(v8::Handle<v8::Message> message, |
| 2291 v8::Handle<v8::Value> data) { | 2401 v8::Handle<v8::Value> data) { |
| 2292 message->Get(); | 2402 message->Get(); |
| 2293 message_received = true; | 2403 message_received = true; |
| 2294 } | 2404 } |
| 2295 | 2405 |
| 2296 | 2406 |
| 2297 TEST(APIThrowMessage) { | 2407 TEST(APIThrowMessage) { |
| 2298 message_received = false; | 2408 message_received = false; |
| 2299 v8::HandleScope scope; | 2409 v8::HandleScope scope; |
| (...skipping 8208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10508 result = CompileRun("for (var i = 0; i < 8; i++) {" | 10618 result = CompileRun("for (var i = 0; i < 8; i++) {" |
| 10509 " ext_array[i] = 5;" | 10619 " ext_array[i] = 5;" |
| 10510 "}" | 10620 "}" |
| 10511 "for (var i = 0; i < 8; i++) {" | 10621 "for (var i = 0; i < 8; i++) {" |
| 10512 " ext_array[i] = -Infinity;" | 10622 " ext_array[i] = -Infinity;" |
| 10513 "}" | 10623 "}" |
| 10514 "ext_array[5];"); | 10624 "ext_array[5];"); |
| 10515 CHECK_EQ(0, result->Int32Value()); | 10625 CHECK_EQ(0, result->Int32Value()); |
| 10516 CHECK_EQ(0, | 10626 CHECK_EQ(0, |
| 10517 i::Smi::cast(jsobj->GetElement(5)->ToObjectChecked())->value()); | 10627 i::Smi::cast(jsobj->GetElement(5)->ToObjectChecked())->value()); |
| 10628 |
| 10629 // Check truncation behavior of integral arrays. |
| 10630 const char* unsigned_data = |
| 10631 "var source_data = [0.6, 10.6];" |
| 10632 "var expected_results = [0, 10];"; |
| 10633 const char* signed_data = |
| 10634 "var source_data = [0.6, 10.6, -0.6, -10.6];" |
| 10635 "var expected_results = [0, 10, 0, -10];"; |
| 10636 bool is_unsigned = |
| 10637 (array_type == v8::kExternalUnsignedByteArray || |
| 10638 array_type == v8::kExternalUnsignedShortArray || |
| 10639 array_type == v8::kExternalUnsignedIntArray); |
| 10640 |
| 10641 i::OS::SNPrintF(test_buf, |
| 10642 "%s" |
| 10643 "var all_passed = true;" |
| 10644 "for (var i = 0; i < source_data.length; i++) {" |
| 10645 " for (var j = 0; j < 8; j++) {" |
| 10646 " ext_array[j] = source_data[i];" |
| 10647 " }" |
| 10648 " all_passed = all_passed &&" |
| 10649 " (ext_array[5] == expected_results[i]);" |
| 10650 "}" |
| 10651 "all_passed;", |
| 10652 (is_unsigned ? unsigned_data : signed_data)); |
| 10653 result = CompileRun(test_buf.start()); |
| 10654 CHECK_EQ(true, result->BooleanValue()); |
| 10518 } | 10655 } |
| 10519 | 10656 |
| 10520 result = CompileRun("ext_array[3] = 33;" | 10657 result = CompileRun("ext_array[3] = 33;" |
| 10521 "delete ext_array[3];" | 10658 "delete ext_array[3];" |
| 10522 "ext_array[3];"); | 10659 "ext_array[3];"); |
| 10523 CHECK_EQ(33, result->Int32Value()); | 10660 CHECK_EQ(33, result->Int32Value()); |
| 10524 | 10661 |
| 10525 result = CompileRun("ext_array[0] = 10; ext_array[1] = 11;" | 10662 result = CompileRun("ext_array[0] = 10; ext_array[1] = 11;" |
| 10526 "ext_array[2] = 12; ext_array[3] = 13;" | 10663 "ext_array[2] = 12; ext_array[3] = 13;" |
| 10527 "ext_array.__defineGetter__('2'," | 10664 "ext_array.__defineGetter__('2'," |
| (...skipping 1849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12377 v8::Context::Scope context_scope(context.local()); | 12514 v8::Context::Scope context_scope(context.local()); |
| 12378 | 12515 |
| 12379 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(); | 12516 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(); |
| 12380 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator); | 12517 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator); |
| 12381 context->Global()->Set(v8_str("o"), tmpl->NewInstance()); | 12518 context->Global()->Set(v8_str("o"), tmpl->NewInstance()); |
| 12382 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( | 12519 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( |
| 12383 "var result = []; for (var k in o) result.push(k); result")); | 12520 "var result = []; for (var k in o) result.push(k); result")); |
| 12384 CHECK_EQ(1, result->Length()); | 12521 CHECK_EQ(1, result->Length()); |
| 12385 CHECK_EQ(v8_str("universalAnswer"), result->Get(0)); | 12522 CHECK_EQ(v8_str("universalAnswer"), result->Get(0)); |
| 12386 } | 12523 } |
| OLD | NEW |