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

Side by Side Diff: sky/engine/bindings-dart/core/dart/DartExceptionState.cpp

Issue 875013003: Import Dart bindings as of Blink r188698. This merely copies the files over and does not attach any… (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 11 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
(Empty)
1 // Copyright (c) 2014, Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 #include "config.h"
31 #include "bindings/core/dart/DartExceptionState.h"
32
33 #include "bindings/core/dart/DartDOMException.h"
34 #include "bindings/core/dart/DartUtilities.h"
35 #include "wtf/text/WTFString.h"
36
37 #include <stdio.h>
38
39 namespace blink {
40
41 void DartExceptionState::throwDOMException(const ExceptionCode& ec, const String & message)
42 {
43 setException(ec, message);
44 }
45
46 void DartExceptionState::throwSecurityError(const String& sanitizedMessage, cons t String& unsanitizedMessage)
47 {
48 // SecurityError is thrown via ::throwSecurityError, and _careful_ considera tion must be given to the data exposed to JavaScript via the 'sanitizedMessage'.
49 setException(SecurityError, sanitizedMessage);
50 }
51
52 void DartExceptionState::rethrowV8Exception(v8::Handle<v8::Value> value)
53 {
54 const char* msg = "A Javascript exception occurred";
55 ASSERT(!m_exception);
56 m_exception = Dart_NewPersistentHandle(Dart_NewStringFromCString(msg));
57 setMessage(msg);
58 setHadException(true);
59 }
60
61 void DartExceptionState::setException(const ExceptionCode& ec, const String& msg )
62 {
63 setCode(ec);
64 setHadException(true);
65 String excp = DOMException::getErrorMessage(ec) + " " + msg;
66 RefPtr<DOMException> domException = DOMException::create(ec, excp);
67 ASSERT(!m_exception);
68 m_exception = Dart_NewPersistentHandle(DartDOMException::toDart(domException ));
69 setMessage(msg);
70 }
71
72 void DartExceptionState::clearException()
73 {
74 setCode(0);
75 setHadException(false);
76 if (m_exception) {
77 Dart_DeletePersistentHandle(m_exception);
78 m_exception = 0;
79 }
80 }
81
82 void DartExceptionState::throwException()
83 {
84 // FIXMEMULTIVM: The control flow here does not match V8's. Dart_ThrowExcept ion immediately
85 // transfers control, which may skip running C++ destructors on the stack an d ref-counting
86 // leaks. Should move throwIfNeeded from ExceptionState to V8ExceptionState and remove this.
87 ASSERT_NOT_REACHED();
88
89 ASSERT(code());
90 ASSERT(hadException());
91 ASSERT(m_exception);
92 DartDOMData* domData = DartDOMData::current();
93 Dart_SetPersistentHandle(domData->currentException(), m_exception);
94 Dart_DeletePersistentHandle(m_exception);
95 m_exception = 0;
96 Dart_ThrowException(domData->currentException());
97 ASSERT_NOT_REACHED();
98 }
99
100 Dart_Handle DartExceptionState::toDart(Dart_NativeArguments args, bool autoDartS cope)
101 {
102 ASSERT(hadException());
103 ASSERT(m_exception);
104
105 if (autoDartScope) {
106 Dart_Handle localException = Dart_HandleFromPersistent(m_exception);
107 Dart_DeletePersistentHandle(m_exception);
108 m_exception = 0;
109 return localException;
110 }
111 DartDOMData* domData = static_cast<DartDOMData*>(Dart_GetNativeIsolateData(a rgs));
112 Dart_SetPersistentHandle(domData->currentException(), m_exception);
113 Dart_DeletePersistentHandle(m_exception);
114 m_exception = 0;
115 return domData->currentException();
116 }
117
118 void DartExceptionState::throwTypeError(const String& message)
119 {
120 throwDartCoreError("ArgumentError", message, V8TypeError);
121 }
122
123 void DartExceptionState::throwRangeError(const String& message)
124 {
125 throwDartCoreError("RangeError", message, V8RangeError);
126 }
127
128 void DartExceptionState::throwDartCoreError(const String& className, const Strin g& message, const ExceptionCode& ec)
129 {
130 setCode(ec);
131 setHadException(true);
132 setMessage(message);
133
134 Dart_Handle error = DartUtilities::toDartCoreException(className, message);
135
136 ASSERT(!m_exception);
137 m_exception = Dart_NewPersistentHandle(error);
138 }
139
140 ScriptPromise DartExceptionState::reject(ScriptState* state)
141 {
142 // FIXMEDART: implement.
143 DART_UNIMPLEMENTED();
144 return ScriptPromise::empty(state);
145 }
146
147
148 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/bindings-dart/core/dart/DartExceptionState.h ('k') | sky/engine/bindings-dart/core/dart/DartGCController.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698