| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 static bool IsNaN(double x) { | 44 static bool IsNaN(double x) { |
| 45 #ifdef WIN32 | 45 #ifdef WIN32 |
| 46 return _isnan(x); | 46 return _isnan(x); |
| 47 #else | 47 #else |
| 48 return isnan(x); | 48 return isnan(x); |
| 49 #endif | 49 #endif |
| 50 } | 50 } |
| 51 | 51 |
| 52 using ::v8::AccessorInfo; | 52 using ::v8::AccessorInfo; |
| 53 using ::v8::Arguments; |
| 53 using ::v8::Context; | 54 using ::v8::Context; |
| 54 using ::v8::Extension; | 55 using ::v8::Extension; |
| 55 using ::v8::Function; | 56 using ::v8::Function; |
| 57 using ::v8::FunctionTemplate; |
| 58 using ::v8::Handle; |
| 56 using ::v8::HandleScope; | 59 using ::v8::HandleScope; |
| 57 using ::v8::Local; | 60 using ::v8::Local; |
| 61 using ::v8::Message; |
| 62 using ::v8::MessageCallback; |
| 58 using ::v8::Object; | 63 using ::v8::Object; |
| 59 using ::v8::ObjectTemplate; | 64 using ::v8::ObjectTemplate; |
| 60 using ::v8::Persistent; | 65 using ::v8::Persistent; |
| 61 using ::v8::Script; | 66 using ::v8::Script; |
| 67 using ::v8::StackTrace; |
| 62 using ::v8::String; | 68 using ::v8::String; |
| 69 using ::v8::TryCatch; |
| 70 using ::v8::Undefined; |
| 71 using ::v8::V8; |
| 63 using ::v8::Value; | 72 using ::v8::Value; |
| 64 using ::v8::V8; | |
| 65 | 73 |
| 66 namespace i = ::i; | 74 namespace i = ::i; |
| 67 | 75 |
| 68 | 76 |
| 69 static void ExpectString(const char* code, const char* expected) { | 77 static void ExpectString(const char* code, const char* expected) { |
| 70 Local<Value> result = CompileRun(code); | 78 Local<Value> result = CompileRun(code); |
| 71 CHECK(result->IsString()); | 79 CHECK(result->IsString()); |
| 72 String::AsciiValue ascii(result); | 80 String::AsciiValue ascii(result); |
| 73 CHECK_EQ(expected, *ascii); | 81 CHECK_EQ(expected, *ascii); |
| 74 } | 82 } |
| (...skipping 8494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8569 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); | 8577 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); |
| 8570 templ->InstanceTemplate()->SetNamedPropertyHandler(InterceptorLoadXICGetter); | 8578 templ->InstanceTemplate()->SetNamedPropertyHandler(InterceptorLoadXICGetter); |
| 8571 LocalContext env; | 8579 LocalContext env; |
| 8572 env->Global()->Set(v8_str("obj"), | 8580 env->Global()->Set(v8_str("obj"), |
| 8573 templ->GetFunction()->NewInstance()); | 8581 templ->GetFunction()->NewInstance()); |
| 8574 ExpectTrue("obj.x === 42"); | 8582 ExpectTrue("obj.x === 42"); |
| 8575 ExpectTrue("!obj.propertyIsEnumerable('x')"); | 8583 ExpectTrue("!obj.propertyIsEnumerable('x')"); |
| 8576 } | 8584 } |
| 8577 | 8585 |
| 8578 | 8586 |
| 8587 static Handle<Value> ThrowingGetter(Local<String> name, |
| 8588 const AccessorInfo& info) { |
| 8589 ApiTestFuzzer::Fuzz(); |
| 8590 ThrowException(Handle<Value>()); |
| 8591 return Undefined(); |
| 8592 } |
| 8593 |
| 8594 |
| 8595 THREADED_TEST(VariousGetPropertiesAndThrowingCallbacks) { |
| 8596 HandleScope scope; |
| 8597 LocalContext context; |
| 8598 |
| 8599 Local<FunctionTemplate> templ = FunctionTemplate::New(); |
| 8600 Local<ObjectTemplate> instance_templ = templ->InstanceTemplate(); |
| 8601 instance_templ->SetAccessor(v8_str("f"), ThrowingGetter); |
| 8602 |
| 8603 Local<Object> instance = templ->GetFunction()->NewInstance(); |
| 8604 |
| 8605 Local<Object> another = Object::New(); |
| 8606 another->SetPrototype(instance); |
| 8607 |
| 8608 Local<Object> with_js_getter = CompileRun( |
| 8609 "o = {};\n" |
| 8610 "o.__defineGetter__('f', function() { throw undefined; });\n" |
| 8611 "o\n").As<Object>(); |
| 8612 CHECK(!with_js_getter.IsEmpty()); |
| 8613 |
| 8614 TryCatch try_catch; |
| 8615 |
| 8616 Local<Value> result = instance->GetRealNamedProperty(v8_str("f")); |
| 8617 CHECK(try_catch.HasCaught()); |
| 8618 try_catch.Reset(); |
| 8619 CHECK(result.IsEmpty()); |
| 8620 |
| 8621 result = another->GetRealNamedProperty(v8_str("f")); |
| 8622 CHECK(try_catch.HasCaught()); |
| 8623 try_catch.Reset(); |
| 8624 CHECK(result.IsEmpty()); |
| 8625 |
| 8626 result = another->GetRealNamedPropertyInPrototypeChain(v8_str("f")); |
| 8627 CHECK(try_catch.HasCaught()); |
| 8628 try_catch.Reset(); |
| 8629 CHECK(result.IsEmpty()); |
| 8630 |
| 8631 result = another->Get(v8_str("f")); |
| 8632 CHECK(try_catch.HasCaught()); |
| 8633 try_catch.Reset(); |
| 8634 CHECK(result.IsEmpty()); |
| 8635 |
| 8636 result = with_js_getter->GetRealNamedProperty(v8_str("f")); |
| 8637 CHECK(try_catch.HasCaught()); |
| 8638 try_catch.Reset(); |
| 8639 CHECK(result.IsEmpty()); |
| 8640 |
| 8641 result = with_js_getter->Get(v8_str("f")); |
| 8642 CHECK(try_catch.HasCaught()); |
| 8643 try_catch.Reset(); |
| 8644 CHECK(result.IsEmpty()); |
| 8645 } |
| 8646 |
| 8647 |
| 8648 static Handle<Value> ThrowingCallbackWithTryCatch(const Arguments& args) { |
| 8649 TryCatch try_catch; |
| 8650 // Verboseness is important: it triggers message delivery which can call into |
| 8651 // external code. |
| 8652 try_catch.SetVerbose(true); |
| 8653 CompileRun("throw 'from JS';"); |
| 8654 CHECK(try_catch.HasCaught()); |
| 8655 CHECK(!i::Isolate::Current()->has_pending_exception()); |
| 8656 CHECK(!i::Isolate::Current()->has_scheduled_exception()); |
| 8657 return Undefined(); |
| 8658 } |
| 8659 |
| 8660 |
| 8661 static void WithTryCatch(Handle<Message> message, Handle<Value> data) { |
| 8662 TryCatch try_catch; |
| 8663 } |
| 8664 |
| 8665 |
| 8666 static void ThrowFromJS(Handle<Message> message, Handle<Value> data) { |
| 8667 CompileRun("throw 'ThrowInJS';"); |
| 8668 } |
| 8669 |
| 8670 |
| 8671 static void ThrowViaApi(Handle<Message> message, Handle<Value> data) { |
| 8672 ThrowException(v8_str("ThrowViaApi")); |
| 8673 } |
| 8674 |
| 8675 |
| 8676 static void WebKitLike(Handle<Message> message, Handle<Value> data) { |
| 8677 Handle<String> errorMessageString = message->Get(); |
| 8678 CHECK(!errorMessageString.IsEmpty()); |
| 8679 message->GetStackTrace(); |
| 8680 message->GetScriptResourceName(); |
| 8681 } |
| 8682 |
| 8683 THREADED_TEST(ExceptionsDoNotPropagatePastTryCatch) { |
| 8684 HandleScope scope; |
| 8685 LocalContext context; |
| 8686 |
| 8687 Local<Function> func = |
| 8688 FunctionTemplate::New(ThrowingCallbackWithTryCatch)->GetFunction(); |
| 8689 context->Global()->Set(v8_str("func"), func); |
| 8690 |
| 8691 MessageCallback callbacks[] = |
| 8692 { NULL, WebKitLike, ThrowViaApi, ThrowFromJS, WithTryCatch }; |
| 8693 for (unsigned i = 0; i < sizeof(callbacks)/sizeof(callbacks[0]); i++) { |
| 8694 MessageCallback callback = callbacks[i]; |
| 8695 if (callback != NULL) { |
| 8696 V8::AddMessageListener(callback); |
| 8697 } |
| 8698 ExpectFalse( |
| 8699 "var thrown = false;\n" |
| 8700 "try { func(); } catch(e) { thrown = true; }\n" |
| 8701 "thrown\n"); |
| 8702 if (callback != NULL) { |
| 8703 V8::RemoveMessageListeners(callback); |
| 8704 } |
| 8705 } |
| 8706 } |
| 8707 |
| 8708 |
| 8579 static v8::Handle<Value> ParentGetter(Local<String> name, | 8709 static v8::Handle<Value> ParentGetter(Local<String> name, |
| 8580 const AccessorInfo& info) { | 8710 const AccessorInfo& info) { |
| 8581 ApiTestFuzzer::Fuzz(); | 8711 ApiTestFuzzer::Fuzz(); |
| 8582 return v8_num(1); | 8712 return v8_num(1); |
| 8583 } | 8713 } |
| 8584 | 8714 |
| 8585 | 8715 |
| 8586 static v8::Handle<Value> ChildGetter(Local<String> name, | 8716 static v8::Handle<Value> ChildGetter(Local<String> name, |
| 8587 const AccessorInfo& info) { | 8717 const AccessorInfo& info) { |
| 8588 ApiTestFuzzer::Fuzz(); | 8718 ApiTestFuzzer::Fuzz(); |
| (...skipping 4886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13475 v8::Handle<v8::Function> define_property = | 13605 v8::Handle<v8::Function> define_property = |
| 13476 CompileRun("(function() {" | 13606 CompileRun("(function() {" |
| 13477 " Object.defineProperty(" | 13607 " Object.defineProperty(" |
| 13478 " this," | 13608 " this," |
| 13479 " 1," | 13609 " 1," |
| 13480 " { configurable: true, enumerable: true, value: 3 });" | 13610 " { configurable: true, enumerable: true, value: 3 });" |
| 13481 "})").As<Function>(); | 13611 "})").As<Function>(); |
| 13482 context->DetachGlobal(); | 13612 context->DetachGlobal(); |
| 13483 define_property->Call(proxy, 0, NULL); | 13613 define_property->Call(proxy, 0, NULL); |
| 13484 } | 13614 } |
| OLD | NEW |