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

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

Issue 1111163003: Replace v8::Handle<> with v8::Local<> in bindings/core/v8/* (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 7 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
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
(...skipping 28 matching lines...) Expand all
39 v8::Local<v8::Value> value; 39 v8::Local<v8::Value> value;
40 if (info.Data().As<v8::Object>()->Get(isolate->GetCurrentContext(), v8Atomic String(isolate, "stack")).ToLocal(&value)) 40 if (info.Data().As<v8::Object>()->Get(isolate->GetCurrentContext(), v8Atomic String(isolate, "stack")).ToLocal(&value))
41 v8SetReturnValue(info, value); 41 v8SetReturnValue(info, value);
42 } 42 }
43 43
44 static void domExceptionStackSetter(v8::Local<v8::Name> name, v8::Local<v8::Valu e> value, const v8::PropertyCallbackInfo<void>& info) 44 static void domExceptionStackSetter(v8::Local<v8::Name> name, v8::Local<v8::Valu e> value, const v8::PropertyCallbackInfo<void>& info)
45 { 45 {
46 info.Data().As<v8::Object>()->Set(v8AtomicString(info.GetIsolate(), "stack") , value); 46 info.Data().As<v8::Object>()->Set(v8AtomicString(info.GetIsolate(), "stack") , value);
47 } 47 }
48 48
49 v8::Handle<v8::Value> V8ThrowException::createDOMException(v8::Isolate* isolate, int ec, const String& sanitizedMessage, const String& unsanitizedMessage, const v8::Handle<v8::Object>& creationContext) 49 v8::Local<v8::Value> V8ThrowException::createDOMException(v8::Isolate* isolate, int ec, const String& sanitizedMessage, const String& unsanitizedMessage, const v8::Local<v8::Object>& creationContext)
50 { 50 {
51 if (ec <= 0 || v8::V8::IsExecutionTerminating()) 51 if (ec <= 0 || v8::V8::IsExecutionTerminating())
52 return v8Undefined(); 52 return v8Undefined();
53 53
54 ASSERT(ec == SecurityError || unsanitizedMessage.isEmpty()); 54 ASSERT(ec == SecurityError || unsanitizedMessage.isEmpty());
55 55
56 if (ec == V8GeneralError) 56 if (ec == V8GeneralError)
57 return V8ThrowException::createGeneralError(isolate, sanitizedMessage); 57 return V8ThrowException::createGeneralError(isolate, sanitizedMessage);
58 if (ec == V8TypeError) 58 if (ec == V8TypeError)
59 return V8ThrowException::createTypeError(isolate, sanitizedMessage); 59 return V8ThrowException::createTypeError(isolate, sanitizedMessage);
60 if (ec == V8RangeError) 60 if (ec == V8RangeError)
61 return V8ThrowException::createRangeError(isolate, sanitizedMessage); 61 return V8ThrowException::createRangeError(isolate, sanitizedMessage);
62 if (ec == V8SyntaxError) 62 if (ec == V8SyntaxError)
63 return V8ThrowException::createSyntaxError(isolate, sanitizedMessage); 63 return V8ThrowException::createSyntaxError(isolate, sanitizedMessage);
64 if (ec == V8ReferenceError) 64 if (ec == V8ReferenceError)
65 return V8ThrowException::createReferenceError(isolate, sanitizedMessage) ; 65 return V8ThrowException::createReferenceError(isolate, sanitizedMessage) ;
66 66
67 v8::Handle<v8::Object> sanitizedCreationContext = creationContext; 67 v8::Local<v8::Object> sanitizedCreationContext = creationContext;
68 68
69 // FIXME: Is the current context always the right choice? 69 // FIXME: Is the current context always the right choice?
70 Frame* frame = toFrameIfNotDetached(creationContext->CreationContext()); 70 Frame* frame = toFrameIfNotDetached(creationContext->CreationContext());
71 if (!frame || !BindingSecurity::shouldAllowAccessToFrame(isolate, frame, DoN otReportSecurityError)) 71 if (!frame || !BindingSecurity::shouldAllowAccessToFrame(isolate, frame, DoN otReportSecurityError))
72 sanitizedCreationContext = isolate->GetCurrentContext()->Global(); 72 sanitizedCreationContext = isolate->GetCurrentContext()->Global();
73 73
74 v8::TryCatch tryCatch; 74 v8::TryCatch tryCatch;
75 75
76 DOMException* domException = DOMException::create(ec, sanitizedMessage, unsa nitizedMessage); 76 DOMException* domException = DOMException::create(ec, sanitizedMessage, unsa nitizedMessage);
77 v8::Local<v8::Value> exception = toV8(domException, sanitizedCreationContext , isolate); 77 v8::Local<v8::Value> exception = toV8(domException, sanitizedCreationContext , isolate);
78 78
79 if (tryCatch.HasCaught()) { 79 if (tryCatch.HasCaught()) {
80 ASSERT(exception.IsEmpty()); 80 ASSERT(exception.IsEmpty());
81 return tryCatch.Exception(); 81 return tryCatch.Exception();
82 } 82 }
83 ASSERT(!exception.IsEmpty()); 83 ASSERT(!exception.IsEmpty());
84 84
85 // Attach an Error object to the DOMException. This is then lazily used to g et the stack value. 85 // Attach an Error object to the DOMException. This is then lazily used to g et the stack value.
86 v8::Local<v8::Value> error = v8::Exception::Error(v8String(isolate, domExcep tion->message())); 86 v8::Local<v8::Value> error = v8::Exception::Error(v8String(isolate, domExcep tion->message()));
87 ASSERT(!error.IsEmpty()); 87 ASSERT(!error.IsEmpty());
88 v8::Local<v8::Object> exceptionObject = exception.As<v8::Object>(); 88 v8::Local<v8::Object> exceptionObject = exception.As<v8::Object>();
89 v8::Maybe<bool> result = exceptionObject->SetAccessor(isolate->GetCurrentCon text(), v8AtomicString(isolate, "stack"), domExceptionStackGetter, domExceptionS tackSetter, v8::MaybeLocal<v8::Value>(error)); 89 v8::Maybe<bool> result = exceptionObject->SetAccessor(isolate->GetCurrentCon text(), v8AtomicString(isolate, "stack"), domExceptionStackGetter, domExceptionS tackSetter, v8::MaybeLocal<v8::Value>(error));
90 ASSERT_UNUSED(result, result.FromJust()); 90 ASSERT_UNUSED(result, result.FromJust());
91 V8HiddenValue::setHiddenValue(isolate, exceptionObject, V8HiddenValue::error (isolate), error); 91 V8HiddenValue::setHiddenValue(isolate, exceptionObject, V8HiddenValue::error (isolate), error);
92 92
93 return exception; 93 return exception;
94 } 94 }
95 95
96 v8::Handle<v8::Value> V8ThrowException::throwDOMException(int ec, const String& sanitizedMessage, const String& unsanitizedMessage, const v8::Handle<v8::Object> & creationContext, v8::Isolate* isolate) 96 v8::Local<v8::Value> V8ThrowException::throwDOMException(int ec, const String& s anitizedMessage, const String& unsanitizedMessage, const v8::Local<v8::Object>& creationContext, v8::Isolate* isolate)
97 { 97 {
98 ASSERT(ec == SecurityError || unsanitizedMessage.isEmpty()); 98 ASSERT(ec == SecurityError || unsanitizedMessage.isEmpty());
99 v8::Handle<v8::Value> exception = createDOMException(isolate, ec, sanitizedM essage, unsanitizedMessage, creationContext); 99 v8::Local<v8::Value> exception = createDOMException(isolate, ec, sanitizedMe ssage, unsanitizedMessage, creationContext);
100 if (exception.IsEmpty()) 100 if (exception.IsEmpty())
101 return v8Undefined(); 101 return v8Undefined();
102 102
103 return V8ThrowException::throwException(exception, isolate); 103 return V8ThrowException::throwException(exception, isolate);
104 } 104 }
105 105
106 v8::Handle<v8::Value> V8ThrowException::createGeneralError(v8::Isolate* isolate, const String& message) 106 v8::Local<v8::Value> V8ThrowException::createGeneralError(v8::Isolate* isolate, const String& message)
107 { 107 {
108 return v8::Exception::Error(v8String(isolate, message.isNull() ? "Error" : m essage)); 108 return v8::Exception::Error(v8String(isolate, message.isNull() ? "Error" : m essage));
109 } 109 }
110 110
111 v8::Handle<v8::Value> V8ThrowException::throwGeneralError(v8::Isolate* isolate, const String& message) 111 v8::Local<v8::Value> V8ThrowException::throwGeneralError(v8::Isolate* isolate, c onst String& message)
112 { 112 {
113 v8::Handle<v8::Value> exception = V8ThrowException::createGeneralError(isola te, message); 113 v8::Local<v8::Value> exception = V8ThrowException::createGeneralError(isolat e, message);
114 return V8ThrowException::throwException(exception, isolate); 114 return V8ThrowException::throwException(exception, isolate);
115 } 115 }
116 116
117 v8::Handle<v8::Value> V8ThrowException::createTypeError(v8::Isolate* isolate, co nst String& message) 117 v8::Local<v8::Value> V8ThrowException::createTypeError(v8::Isolate* isolate, con st String& message)
118 { 118 {
119 return v8::Exception::TypeError(v8String(isolate, message.isNull() ? "Type e rror" : message)); 119 return v8::Exception::TypeError(v8String(isolate, message.isNull() ? "Type e rror" : message));
120 } 120 }
121 121
122 v8::Handle<v8::Value> V8ThrowException::throwTypeError(v8::Isolate* isolate, con st String& message) 122 v8::Local<v8::Value> V8ThrowException::throwTypeError(v8::Isolate* isolate, cons t String& message)
123 { 123 {
124 v8::Handle<v8::Value> exception = V8ThrowException::createTypeError(isolate, message); 124 v8::Local<v8::Value> exception = V8ThrowException::createTypeError(isolate, message);
125 return V8ThrowException::throwException(exception, isolate); 125 return V8ThrowException::throwException(exception, isolate);
126 } 126 }
127 127
128 v8::Handle<v8::Value> V8ThrowException::createRangeError(v8::Isolate* isolate, c onst String& message) 128 v8::Local<v8::Value> V8ThrowException::createRangeError(v8::Isolate* isolate, co nst String& message)
129 { 129 {
130 return v8::Exception::RangeError(v8String(isolate, message.isNull() ? "Range error" : message)); 130 return v8::Exception::RangeError(v8String(isolate, message.isNull() ? "Range error" : message));
131 } 131 }
132 132
133 v8::Handle<v8::Value> V8ThrowException::throwRangeError(v8::Isolate* isolate, co nst String& message) 133 v8::Local<v8::Value> V8ThrowException::throwRangeError(v8::Isolate* isolate, con st String& message)
134 { 134 {
135 v8::Handle<v8::Value> exception = V8ThrowException::createRangeError(isolate , message); 135 v8::Local<v8::Value> exception = V8ThrowException::createRangeError(isolate, message);
136 return V8ThrowException::throwException(exception, isolate); 136 return V8ThrowException::throwException(exception, isolate);
137 } 137 }
138 138
139 v8::Handle<v8::Value> V8ThrowException::createSyntaxError(v8::Isolate* isolate, const String& message) 139 v8::Local<v8::Value> V8ThrowException::createSyntaxError(v8::Isolate* isolate, c onst String& message)
140 { 140 {
141 return v8::Exception::SyntaxError(v8String(isolate, message.isNull() ? "Synt ax error" : message)); 141 return v8::Exception::SyntaxError(v8String(isolate, message.isNull() ? "Synt ax error" : message));
142 } 142 }
143 143
144 v8::Handle<v8::Value> V8ThrowException::throwSyntaxError(v8::Isolate* isolate, c onst String& message) 144 v8::Local<v8::Value> V8ThrowException::throwSyntaxError(v8::Isolate* isolate, co nst String& message)
145 { 145 {
146 v8::Handle<v8::Value> exception = V8ThrowException::createSyntaxError(isolat e, message); 146 v8::Local<v8::Value> exception = V8ThrowException::createSyntaxError(isolate , message);
147 return V8ThrowException::throwException(exception, isolate); 147 return V8ThrowException::throwException(exception, isolate);
148 } 148 }
149 149
150 v8::Handle<v8::Value> V8ThrowException::createReferenceError(v8::Isolate* isolat e, const String& message) 150 v8::Local<v8::Value> V8ThrowException::createReferenceError(v8::Isolate* isolate , const String& message)
151 { 151 {
152 return v8::Exception::ReferenceError(v8String(isolate, message.isNull() ? "R eference error" : message)); 152 return v8::Exception::ReferenceError(v8String(isolate, message.isNull() ? "R eference error" : message));
153 } 153 }
154 154
155 v8::Handle<v8::Value> V8ThrowException::throwReferenceError(v8::Isolate* isolate , const String& message) 155 v8::Local<v8::Value> V8ThrowException::throwReferenceError(v8::Isolate* isolate, const String& message)
156 { 156 {
157 v8::Handle<v8::Value> exception = V8ThrowException::createReferenceError(iso late, message); 157 v8::Local<v8::Value> exception = V8ThrowException::createReferenceError(isol ate, message);
158 return V8ThrowException::throwException(exception, isolate); 158 return V8ThrowException::throwException(exception, isolate);
159 } 159 }
160 160
161 v8::Handle<v8::Value> V8ThrowException::throwException(v8::Handle<v8::Value> exc eption, v8::Isolate* isolate) 161 v8::Local<v8::Value> V8ThrowException::throwException(v8::Local<v8::Value> excep tion, v8::Isolate* isolate)
162 { 162 {
163 if (!v8::V8::IsExecutionTerminating()) 163 if (!v8::V8::IsExecutionTerminating())
164 isolate->ThrowException(exception); 164 isolate->ThrowException(exception);
165 return v8::Undefined(isolate); 165 return v8::Undefined(isolate);
166 } 166 }
167 167
168 } // namespace blink 168 } // namespace blink
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/V8ThrowException.h ('k') | Source/bindings/core/v8/WrapCanvasContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698