OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 26 matching lines...) Expand all Loading... |
37 ASSERT(info.Data()->IsObject()); | 37 ASSERT(info.Data()->IsObject()); |
38 v8SetReturnValue(info, info.Data()->ToObject()->Get(v8::String::NewSymbol("s
tack"))); | 38 v8SetReturnValue(info, info.Data()->ToObject()->Get(v8::String::NewSymbol("s
tack"))); |
39 } | 39 } |
40 | 40 |
41 static void domExceptionStackSetter(v8::Local<v8::String> name, v8::Local<v8::Va
lue> value, const v8::PropertyCallbackInfo<void>& info) | 41 static void domExceptionStackSetter(v8::Local<v8::String> name, v8::Local<v8::Va
lue> value, const v8::PropertyCallbackInfo<void>& info) |
42 { | 42 { |
43 ASSERT(info.Data()->IsObject()); | 43 ASSERT(info.Data()->IsObject()); |
44 info.Data()->ToObject()->Set(v8::String::NewSymbol("stack"), value); | 44 info.Data()->ToObject()->Set(v8::String::NewSymbol("stack"), value); |
45 } | 45 } |
46 | 46 |
47 v8::Handle<v8::Value> V8ThrowException::createDOMException(int ec, const String&
sanitizedMessage, const String& unsanitizedMessage, v8::Isolate* isolate) | 47 v8::Handle<v8::Value> V8ThrowException::createDOMException(int ec, const String&
message, v8::Isolate* isolate) |
48 { | 48 { |
49 if (ec <= 0 || v8::V8::IsExecutionTerminating()) | 49 if (ec <= 0 || v8::V8::IsExecutionTerminating()) |
50 return v8Undefined(); | 50 return v8Undefined(); |
51 | 51 |
52 ASSERT(ec == SecurityError || unsanitizedMessage.isEmpty()); | |
53 | |
54 // FIXME: Handle other WebIDL exception types. | 52 // FIXME: Handle other WebIDL exception types. |
55 if (ec == TypeError) | 53 if (ec == TypeError) |
56 return V8ThrowException::createTypeError(sanitizedMessage, isolate); | 54 return V8ThrowException::createTypeError(message, isolate); |
57 | 55 |
58 RefPtr<DOMException> domException = DOMException::create(ec, sanitizedMessag
e, unsanitizedMessage); | 56 RefPtr<DOMException> domException = DOMException::create(ec, message); |
59 v8::Handle<v8::Value> exception = toV8(domException, v8::Handle<v8::Object>(
), isolate); | 57 v8::Handle<v8::Value> exception = toV8(domException, v8::Handle<v8::Object>(
), isolate); |
60 | 58 |
61 if (exception.IsEmpty()) | 59 if (exception.IsEmpty()) |
62 return v8Undefined(); | 60 return v8Undefined(); |
63 | 61 |
64 // Attach an Error object to the DOMException. This is then lazily used to g
et the stack value. | 62 // Attach an Error object to the DOMException. This is then lazily used to g
et the stack value. |
65 v8::Handle<v8::Value> error = v8::Exception::Error(v8String(domException->me
ssage(), isolate)); | 63 v8::Handle<v8::Value> error = v8::Exception::Error(v8String(domException->me
ssage(), isolate)); |
66 ASSERT(!error.IsEmpty()); | 64 ASSERT(!error.IsEmpty()); |
67 ASSERT(exception->IsObject()); | 65 ASSERT(exception->IsObject()); |
68 exception->ToObject()->SetAccessor(v8::String::NewSymbol("stack"), domExcept
ionStackGetter, domExceptionStackSetter, error); | 66 exception->ToObject()->SetAccessor(v8::String::NewSymbol("stack"), domExcept
ionStackGetter, domExceptionStackSetter, error); |
69 | 67 |
70 return exception; | 68 return exception; |
71 } | 69 } |
72 | 70 |
73 v8::Handle<v8::Value> V8ThrowException::throwDOMException(int ec, const String&
sanitizedMessage, const String& unsanitizedMessage, v8::Isolate* isolate) | 71 v8::Handle<v8::Value> V8ThrowException::throwDOMException(int ec, const String&
message, v8::Isolate* isolate) |
74 { | 72 { |
75 ASSERT(ec == SecurityError || unsanitizedMessage.isEmpty()); | 73 v8::Handle<v8::Value> exception = createDOMException(ec, message, isolate); |
76 v8::Handle<v8::Value> exception = createDOMException(ec, sanitizedMessage, u
nsanitizedMessage, isolate); | |
77 if (exception.IsEmpty()) | 74 if (exception.IsEmpty()) |
78 return v8Undefined(); | 75 return v8Undefined(); |
79 | 76 |
80 return V8ThrowException::throwError(exception); | 77 return V8ThrowException::throwError(exception); |
81 } | 78 } |
82 | 79 |
83 v8::Handle<v8::Value> V8ThrowException::createError(V8ErrorType type, const Stri
ng& message, v8::Isolate* isolate) | 80 v8::Handle<v8::Value> V8ThrowException::createError(V8ErrorType type, const Stri
ng& message, v8::Isolate* isolate) |
84 { | 81 { |
85 switch (type) { | 82 switch (type) { |
86 case v8RangeError: | 83 case v8RangeError: |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 } | 122 } |
126 | 123 |
127 v8::Handle<v8::Value> V8ThrowException::throwError(v8::Handle<v8::Value> excepti
on) | 124 v8::Handle<v8::Value> V8ThrowException::throwError(v8::Handle<v8::Value> excepti
on) |
128 { | 125 { |
129 if (!v8::V8::IsExecutionTerminating()) | 126 if (!v8::V8::IsExecutionTerminating()) |
130 v8::ThrowException(exception); | 127 v8::ThrowException(exception); |
131 return v8::Undefined(); | 128 return v8::Undefined(); |
132 } | 129 } |
133 | 130 |
134 } // namespace WebCore | 131 } // namespace WebCore |
OLD | NEW |