Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: Source/bindings/core/v8/V8ThrowException.cpp

Issue 895553002: Use correct context when throwing an exception (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN Y 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN Y
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN Y 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN Y
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O N 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O N
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */ 23 */
24 24
25 #include "config.h" 25 #include "config.h"
26 #include "bindings/core/v8/V8ThrowException.h" 26 #include "bindings/core/v8/V8ThrowException.h"
27 27
28 #include "bindings/core/v8/BindingSecurity.h"
28 #include "bindings/core/v8/V8Binding.h" 29 #include "bindings/core/v8/V8Binding.h"
29 #include "bindings/core/v8/V8DOMException.h" 30 #include "bindings/core/v8/V8DOMException.h"
30 #include "core/dom/DOMException.h" 31 #include "core/dom/DOMException.h"
31 #include "core/dom/ExceptionCode.h" 32 #include "core/dom/ExceptionCode.h"
32 33
33 namespace blink { 34 namespace blink {
34 35
35 static void domExceptionStackGetter(v8::Local<v8::String> name, const v8::Proper tyCallbackInfo<v8::Value>& info) 36 static void domExceptionStackGetter(v8::Local<v8::String> name, const v8::Proper tyCallbackInfo<v8::Value>& info)
36 { 37 {
37 ASSERT(info.Data()->IsObject()); 38 ASSERT(info.Data()->IsObject());
(...skipping 17 matching lines...) Expand all
55 return V8ThrowException::createGeneralError(isolate, sanitizedMessage); 56 return V8ThrowException::createGeneralError(isolate, sanitizedMessage);
56 if (ec == V8TypeError) 57 if (ec == V8TypeError)
57 return V8ThrowException::createTypeError(isolate, sanitizedMessage); 58 return V8ThrowException::createTypeError(isolate, sanitizedMessage);
58 if (ec == V8RangeError) 59 if (ec == V8RangeError)
59 return V8ThrowException::createRangeError(isolate, sanitizedMessage); 60 return V8ThrowException::createRangeError(isolate, sanitizedMessage);
60 if (ec == V8SyntaxError) 61 if (ec == V8SyntaxError)
61 return V8ThrowException::createSyntaxError(isolate, sanitizedMessage); 62 return V8ThrowException::createSyntaxError(isolate, sanitizedMessage);
62 if (ec == V8ReferenceError) 63 if (ec == V8ReferenceError)
63 return V8ThrowException::createReferenceError(isolate, sanitizedMessage) ; 64 return V8ThrowException::createReferenceError(isolate, sanitizedMessage) ;
64 65
66 v8::Handle<v8::Object> sanitizedCreationContext = creationContext;
67
68 // FIXME: Is the current context always the right choice?
69 Frame* frame = toFrameIfNotDetached(creationContext->CreationContext());
70 if (!frame || !BindingSecurity::shouldAllowAccessToFrame(isolate, frame, DoN otReportSecurityError))
71 sanitizedCreationContext = isolate->GetCurrentContext()->Global();
72
73
65 RefPtrWillBeRawPtr<DOMException> domException = DOMException::create(ec, san itizedMessage, unsanitizedMessage); 74 RefPtrWillBeRawPtr<DOMException> domException = DOMException::create(ec, san itizedMessage, unsanitizedMessage);
66 v8::Handle<v8::Value> exception = toV8(domException.get(), creationContext, isolate); 75 v8::Handle<v8::Value> exception = toV8(domException.get(), sanitizedCreation Context, isolate);
67 76
68 if (exception.IsEmpty()) 77 if (exception.IsEmpty())
69 return v8Undefined(); 78 return v8Undefined();
70 79
71 // Attach an Error object to the DOMException. This is then lazily used to g et the stack value. 80 // Attach an Error object to the DOMException. This is then lazily used to g et the stack value.
72 v8::Handle<v8::Value> error = v8::Exception::Error(v8String(isolate, domExce ption->message())); 81 v8::Handle<v8::Value> error = v8::Exception::Error(v8String(isolate, domExce ption->message()));
73 ASSERT(!error.IsEmpty()); 82 ASSERT(!error.IsEmpty());
74 ASSERT(exception->IsObject()); 83 ASSERT(exception->IsObject());
75 exception->ToObject(isolate)->SetAccessor(v8AtomicString(isolate, "stack"), domExceptionStackGetter, domExceptionStackSetter, error); 84 exception->ToObject(isolate)->SetAccessor(v8AtomicString(isolate, "stack"), domExceptionStackGetter, domExceptionStackSetter, error);
76 V8HiddenValue::setHiddenValue(isolate, exception->ToObject(isolate), V8Hidde nValue::error(isolate), error); 85 V8HiddenValue::setHiddenValue(isolate, exception->ToObject(isolate), V8Hidde nValue::error(isolate), error);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 } 153 }
145 154
146 v8::Handle<v8::Value> V8ThrowException::throwException(v8::Handle<v8::Value> exc eption, v8::Isolate* isolate) 155 v8::Handle<v8::Value> V8ThrowException::throwException(v8::Handle<v8::Value> exc eption, v8::Isolate* isolate)
147 { 156 {
148 if (!v8::V8::IsExecutionTerminating()) 157 if (!v8::V8::IsExecutionTerminating())
149 isolate->ThrowException(exception); 158 isolate->ThrowException(exception);
150 return v8::Undefined(isolate); 159 return v8::Undefined(isolate);
151 } 160 }
152 161
153 } // namespace blink 162 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698