| 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&
sanitizedMessage, const String& unsanitizedMessage, const v8::Handle<v8::Object
>& creationContext, 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()); | 52 ASSERT(ec == SecurityError || unsanitizedMessage.isEmpty()); |
| 53 | 53 |
| 54 // FIXME: Handle other WebIDL exception types. | 54 // FIXME: Handle other WebIDL exception types. |
| 55 if (ec == TypeError) | 55 if (ec == TypeError) |
| 56 return V8ThrowException::createTypeError(sanitizedMessage, isolate); | 56 return V8ThrowException::createTypeError(sanitizedMessage, isolate); |
| 57 | 57 |
| 58 RefPtr<DOMException> domException = DOMException::create(ec, sanitizedMessag
e, unsanitizedMessage); | 58 RefPtr<DOMException> domException = DOMException::create(ec, sanitizedMessag
e, unsanitizedMessage); |
| 59 v8::Handle<v8::Value> exception = toV8(domException, v8::Handle<v8::Object>(
), isolate); | 59 v8::Handle<v8::Value> exception = toV8(domException, creationContext, isolat
e); |
| 60 | 60 |
| 61 if (exception.IsEmpty()) | 61 if (exception.IsEmpty()) |
| 62 return v8Undefined(); | 62 return v8Undefined(); |
| 63 | 63 |
| 64 // Attach an Error object to the DOMException. This is then lazily used to g
et the stack value. | 64 // 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)); | 65 v8::Handle<v8::Value> error = v8::Exception::Error(v8String(domException->me
ssage(), isolate)); |
| 66 ASSERT(!error.IsEmpty()); | 66 ASSERT(!error.IsEmpty()); |
| 67 ASSERT(exception->IsObject()); | 67 ASSERT(exception->IsObject()); |
| 68 exception->ToObject()->SetAccessor(v8::String::NewSymbol("stack"), domExcept
ionStackGetter, domExceptionStackSetter, error); | 68 exception->ToObject()->SetAccessor(v8::String::NewSymbol("stack"), domExcept
ionStackGetter, domExceptionStackSetter, error); |
| 69 | 69 |
| 70 return exception; | 70 return exception; |
| 71 } | 71 } |
| 72 | 72 |
| 73 v8::Handle<v8::Value> V8ThrowException::throwDOMException(int ec, const String&
sanitizedMessage, const String& unsanitizedMessage, v8::Isolate* isolate) | 73 v8::Handle<v8::Value> V8ThrowException::throwDOMException(int ec, const String&
sanitizedMessage, const String& unsanitizedMessage, const v8::Handle<v8::Object>
& creationContext, v8::Isolate* isolate) |
| 74 { | 74 { |
| 75 ASSERT(ec == SecurityError || unsanitizedMessage.isEmpty()); | 75 ASSERT(ec == SecurityError || unsanitizedMessage.isEmpty()); |
| 76 v8::Handle<v8::Value> exception = createDOMException(ec, sanitizedMessage, u
nsanitizedMessage, isolate); | 76 v8::Handle<v8::Value> exception = createDOMException(ec, sanitizedMessage, u
nsanitizedMessage, creationContext, isolate); |
| 77 if (exception.IsEmpty()) | 77 if (exception.IsEmpty()) |
| 78 return v8Undefined(); | 78 return v8Undefined(); |
| 79 | 79 |
| 80 return V8ThrowException::throwError(exception, isolate); | 80 return V8ThrowException::throwError(exception, isolate); |
| 81 } | 81 } |
| 82 | 82 |
| 83 v8::Handle<v8::Value> V8ThrowException::createError(V8ErrorType type, const Stri
ng& message, v8::Isolate* isolate) | 83 v8::Handle<v8::Value> V8ThrowException::createError(V8ErrorType type, const Stri
ng& message, v8::Isolate* isolate) |
| 84 { | 84 { |
| 85 switch (type) { | 85 switch (type) { |
| 86 case v8RangeError: | 86 case v8RangeError: |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 } | 119 } |
| 120 | 120 |
| 121 v8::Handle<v8::Value> V8ThrowException::throwError(v8::Handle<v8::Value> excepti
on, v8::Isolate* isolate) | 121 v8::Handle<v8::Value> V8ThrowException::throwError(v8::Handle<v8::Value> excepti
on, v8::Isolate* isolate) |
| 122 { | 122 { |
| 123 if (!v8::V8::IsExecutionTerminating()) | 123 if (!v8::V8::IsExecutionTerminating()) |
| 124 v8::ThrowException(exception); | 124 v8::ThrowException(exception); |
| 125 return v8::Undefined(isolate); | 125 return v8::Undefined(isolate); |
| 126 } | 126 } |
| 127 | 127 |
| 128 } // namespace WebCore | 128 } // namespace WebCore |
| OLD | NEW |