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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 | 44 |
45 static bool IsNaN(double x) { | 45 static bool IsNaN(double x) { |
46 #ifdef WIN32 | 46 #ifdef WIN32 |
47 return _isnan(x); | 47 return _isnan(x); |
48 #else | 48 #else |
49 return isnan(x); | 49 return isnan(x); |
50 #endif | 50 #endif |
51 } | 51 } |
52 | 52 |
53 using ::v8::AccessorInfo; | 53 using ::v8::AccessorInfo; |
54 using ::v8::Arguments; | |
55 using ::v8::Context; | 54 using ::v8::Context; |
56 using ::v8::Extension; | 55 using ::v8::Extension; |
57 using ::v8::Function; | 56 using ::v8::Function; |
58 using ::v8::FunctionTemplate; | |
59 using ::v8::Handle; | |
60 using ::v8::HandleScope; | 57 using ::v8::HandleScope; |
61 using ::v8::Local; | 58 using ::v8::Local; |
62 using ::v8::Message; | |
63 using ::v8::MessageCallback; | |
64 using ::v8::Object; | 59 using ::v8::Object; |
65 using ::v8::ObjectTemplate; | 60 using ::v8::ObjectTemplate; |
66 using ::v8::Persistent; | 61 using ::v8::Persistent; |
67 using ::v8::Script; | 62 using ::v8::Script; |
68 using ::v8::StackTrace; | |
69 using ::v8::String; | 63 using ::v8::String; |
70 using ::v8::TryCatch; | 64 using ::v8::Value; |
71 using ::v8::Undefined; | |
72 using ::v8::V8; | 65 using ::v8::V8; |
73 using ::v8::Value; | |
74 | 66 |
75 namespace i = ::i; | 67 namespace i = ::i; |
76 | 68 |
77 | 69 |
78 static void ExpectString(const char* code, const char* expected) { | 70 static void ExpectString(const char* code, const char* expected) { |
79 Local<Value> result = CompileRun(code); | 71 Local<Value> result = CompileRun(code); |
80 CHECK(result->IsString()); | 72 CHECK(result->IsString()); |
81 String::AsciiValue ascii(result); | 73 String::AsciiValue ascii(result); |
82 CHECK_EQ(expected, *ascii); | 74 CHECK_EQ(expected, *ascii); |
83 } | 75 } |
(...skipping 8493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8577 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); | 8569 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); |
8578 templ->InstanceTemplate()->SetNamedPropertyHandler(InterceptorLoadXICGetter); | 8570 templ->InstanceTemplate()->SetNamedPropertyHandler(InterceptorLoadXICGetter); |
8579 LocalContext env; | 8571 LocalContext env; |
8580 env->Global()->Set(v8_str("obj"), | 8572 env->Global()->Set(v8_str("obj"), |
8581 templ->GetFunction()->NewInstance()); | 8573 templ->GetFunction()->NewInstance()); |
8582 ExpectTrue("obj.x === 42"); | 8574 ExpectTrue("obj.x === 42"); |
8583 ExpectTrue("!obj.propertyIsEnumerable('x')"); | 8575 ExpectTrue("!obj.propertyIsEnumerable('x')"); |
8584 } | 8576 } |
8585 | 8577 |
8586 | 8578 |
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::Top::has_pending_exception()); | |
8656 CHECK(!i::Top::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 | |
8709 static v8::Handle<Value> ParentGetter(Local<String> name, | 8579 static v8::Handle<Value> ParentGetter(Local<String> name, |
8710 const AccessorInfo& info) { | 8580 const AccessorInfo& info) { |
8711 ApiTestFuzzer::Fuzz(); | 8581 ApiTestFuzzer::Fuzz(); |
8712 return v8_num(1); | 8582 return v8_num(1); |
8713 } | 8583 } |
8714 | 8584 |
8715 | 8585 |
8716 static v8::Handle<Value> ChildGetter(Local<String> name, | 8586 static v8::Handle<Value> ChildGetter(Local<String> name, |
8717 const AccessorInfo& info) { | 8587 const AccessorInfo& info) { |
8718 ApiTestFuzzer::Fuzz(); | 8588 ApiTestFuzzer::Fuzz(); |
(...skipping 4521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13240 v8::Handle<v8::Function> define_property = | 13110 v8::Handle<v8::Function> define_property = |
13241 CompileRun("(function() {" | 13111 CompileRun("(function() {" |
13242 " Object.defineProperty(" | 13112 " Object.defineProperty(" |
13243 " this," | 13113 " this," |
13244 " 1," | 13114 " 1," |
13245 " { configurable: true, enumerable: true, value: 3 });" | 13115 " { configurable: true, enumerable: true, value: 3 });" |
13246 "})").As<Function>(); | 13116 "})").As<Function>(); |
13247 context->DetachGlobal(); | 13117 context->DetachGlobal(); |
13248 define_property->Call(proxy, 0, NULL); | 13118 define_property->Call(proxy, 0, NULL); |
13249 } | 13119 } |
OLD | NEW |