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

Side by Side Diff: Source/WebCore/bindings/dart/DartUtilities.h

Issue 10660025: Cleanup dart to string conversions. (Closed) Base URL: svn://svn.chromium.org/multivm/trunk/webkit
Patch Set: . Created 8 years, 6 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
OLDNEW
1 // Copyright 2011, Google Inc. 1 // Copyright 2011, Google Inc.
2 // All rights reserved. 2 // 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 are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 class DartApplicationLoader; 43 class DartApplicationLoader;
44 class DartDOMData; 44 class DartDOMData;
45 class Dictionary; 45 class Dictionary;
46 class Frame; 46 class Frame;
47 class ScriptArguments; 47 class ScriptArguments;
48 class ScriptCallStack; 48 class ScriptCallStack;
49 class ScriptExecutionContext; 49 class ScriptExecutionContext;
50 class SerializedScriptValue; 50 class SerializedScriptValue;
51 class WebKitFlags; 51 class WebKitFlags;
52 52
53 typedef HashMap<void*, Dart_Handle> DartDOMMap; 53 class DartStringAdapter {
54 public:
55 explicit DartStringAdapter(PassRefPtr<StringImpl> stringImpl)
56 : m_stringImpl(stringImpl)
57 {
58 }
59
60 operator String() const { return String(m_stringImpl); }
61 operator AtomicString() const { return AtomicString(m_stringImpl); }
62
63 private:
64 RefPtr<StringImpl> m_stringImpl;
65 };
54 66
55 class DartUtilities { 67 class DartUtilities {
56 public: 68 public:
57 enum ConversionFlag { 69 enum ConversionFlag {
58 ConvertNone = 0, 70 ConvertNone = 0,
59 ConvertNullToDefaultValue = 1 71 ConvertNullToDefaultValue = 1
60 }; 72 };
61 73
62 static const char* htmlLibraryName; 74 static const char* htmlLibraryName;
63 75
64 static PassRefPtr<StringImpl> toStringImpl(Dart_Handle, ConversionFlag flag, Dart_Handle& exception);
65 // FIXME: we should get rid of this one in favour of toStringImpl.
66 static String dartStringToString(Dart_Handle object)
67 {
68 Dart_Handle exception = 0;
69 RefPtr<StringImpl> impl = toStringImpl(object, ConvertNone, exception);
70 ASSERT(!exception);
71 return String(impl.release());
72 }
73
74 static Dart_Handle stringImplToDartString(StringImpl*); 76 static Dart_Handle stringImplToDartString(StringImpl*);
75 static Dart_Handle stringToDartString(const String&); 77 static Dart_Handle stringToDartString(const String&);
76 static Dart_Handle stringToDartString(const AtomicString&); 78 static Dart_Handle stringToDartString(const AtomicString&);
77 79
78 static Dart_Handle errorToException(Dart_Handle error) 80 static Dart_Handle errorToException(Dart_Handle error)
79 { 81 {
80 ASSERT(Dart_IsError(error)); 82 ASSERT(Dart_IsError(error));
81 if (Dart_ErrorHasException(error)) 83 if (Dart_ErrorHasException(error))
82 return Dart_ErrorGetException(error); 84 return Dart_ErrorGetException(error);
83 return Dart_NewString(Dart_GetError(error)); 85 return Dart_NewString(Dart_GetError(error));
84 } 86 }
85 87
86 static bool checkResult(Dart_Handle result, Dart_Handle& exception) 88 static bool checkResult(Dart_Handle result, Dart_Handle& exception)
87 { 89 {
88 if (!Dart_IsError(result)) 90 if (!Dart_IsError(result))
89 return true; 91 return true;
90 92
91 exception = errorToException(result); 93 exception = errorToException(result);
92 return false; 94 return false;
93 } 95 }
94 96
95 static void extractListElements(Dart_Handle list, Dart_Handle& exception, Ve ctor<Dart_Handle>& elements); 97 static void extractListElements(Dart_Handle list, Dart_Handle& exception, Ve ctor<Dart_Handle>& elements);
96 static void extractMapElements(Dart_Handle map, Dart_Handle& exception, Vect or<Dart_Handle>& keys, Vector<Dart_Handle>& values); 98 static void extractMapElements(Dart_Handle map, Dart_Handle& exception, Vect or<Dart_Handle>& keys, Vector<Dart_Handle>& values);
97 99
98 static int64_t toInteger(Dart_Handle object, Dart_Handle& exception); 100 static int64_t toInteger(Dart_Handle object, Dart_Handle& exception);
101 static String toString(Dart_Handle object);
99 static void toMessagePortArray(Dart_Handle object, MessagePortArray&, ArrayB ufferArray&, Dart_Handle& exception); 102 static void toMessagePortArray(Dart_Handle object, MessagePortArray&, ArrayB ufferArray&, Dart_Handle& exception);
100 static PassRefPtr<SerializedScriptValue> toSerializedScriptValue(Dart_Handle object, MessagePortArray*, ArrayBufferArray*, Dart_Handle& exception); 103 static PassRefPtr<SerializedScriptValue> toSerializedScriptValue(Dart_Handle object, MessagePortArray*, ArrayBufferArray*, Dart_Handle& exception);
101 static PassRefPtr<WebKitFlags> toWebKitFlags(Dart_Handle object, Dart_Handle & exception); 104 static PassRefPtr<WebKitFlags> toWebKitFlags(Dart_Handle object, Dart_Handle & exception);
102 static Dictionary dartToDictionary(Dart_Handle, Dart_Handle& exception); 105 static Dictionary dartToDictionary(Dart_Handle, Dart_Handle& exception);
103 106
104 static DOMWindow* domWindowForCurrentIsolate(); 107 static DOMWindow* domWindowForCurrentIsolate();
105 108
106 static Dart_Handle htmlLibraryForCurrentIsolate(); 109 static Dart_Handle htmlLibraryForCurrentIsolate();
107 static Dart_Handle pageLibraryForCurrentIsolate(); 110 static Dart_Handle pageLibraryForCurrentIsolate();
108 111
(...skipping 30 matching lines...) Expand all
139 } 142 }
140 143
141 static Dart_Handle internalErrorException(const char* msg) 144 static Dart_Handle internalErrorException(const char* msg)
142 { 145 {
143 // FIXME: wrap into proper type. 146 // FIXME: wrap into proper type.
144 return Dart_NewString(msg); 147 return Dart_NewString(msg);
145 } 148 }
146 149
147 static Dart_Handle invokeUtilsMethod(const char* methodName, int argCount, D art_Handle* args); 150 static Dart_Handle invokeUtilsMethod(const char* methodName, int argCount, D art_Handle* args);
148 151
152 static DartStringAdapter dartToString(Dart_Handle object, Dart_Handle& excep tion)
153 {
154 // FIXME: [performance] need better treatment of String vs. AtomicString , cf. v8 implementation.
155 return DartStringAdapter(toStringImpl(object, exception));
156 }
157 static DartStringAdapter dartToStringWithNullCheck(Dart_Handle object, Dart_ Handle& exception)
Anton Muhin 2012/06/26 16:52:28 wdyt, do we need to distinguish those? maybe we s
podivilov 2012/06/26 18:07:38 Passing nulls to c++ methods is a bit scary... Als
158 {
159 if (Dart_IsNull(object))
160 return DartStringAdapter(0);
161 return dartToString(object, exception);
162 }
149 static Dart_Handle stringToDart(const AtomicString& value, ConversionFlag fl ag = ConvertNone); 163 static Dart_Handle stringToDart(const AtomicString& value, ConversionFlag fl ag = ConvertNone);
150 static Dart_Handle stringToDart(const String& value, ConversionFlag flag = C onvertNone); 164 static Dart_Handle stringToDart(const String& value, ConversionFlag flag = C onvertNone);
151 165
152 static bool dartToBool(Dart_Handle, Dart_Handle& exception); 166 static bool dartToBool(Dart_Handle, Dart_Handle& exception);
153 static Dart_Handle boolToDart(bool value) 167 static Dart_Handle boolToDart(bool value)
154 { 168 {
155 return Dart_NewBoolean(value); 169 return Dart_NewBoolean(value);
156 } 170 }
157 171
158 static int dartToInt(Dart_Handle, Dart_Handle& exception); 172 static int dartToInt(Dart_Handle, Dart_Handle& exception);
(...skipping 29 matching lines...) Expand all
188 return Dart_NewDouble(value); 202 return Dart_NewDouble(value);
189 } 203 }
190 204
191 static Dart_Handle numberToDart(double value); 205 static Dart_Handle numberToDart(double value);
192 206
193 static ScriptValue dartToScriptValue(Dart_Handle, Dart_Handle& exception); 207 static ScriptValue dartToScriptValue(Dart_Handle, Dart_Handle& exception);
194 static Dart_Handle scriptValueToDart(const ScriptValue& value); 208 static Dart_Handle scriptValueToDart(const ScriptValue& value);
195 209
196 static PassRefPtr<SerializedScriptValue> dartToSerializedScriptValue(Dart_Ha ndle, Dart_Handle& exception); 210 static PassRefPtr<SerializedScriptValue> dartToSerializedScriptValue(Dart_Ha ndle, Dart_Handle& exception);
197 static Dart_Handle serializedScriptValueToDart(SerializedScriptValue* value) ; 211 static Dart_Handle serializedScriptValueToDart(SerializedScriptValue* value) ;
212
213 private:
214 static PassRefPtr<StringImpl> toStringImpl(Dart_Handle object, Dart_Handle& exception);
198 }; 215 };
199 216
200 class DartApiScope { 217 class DartApiScope {
201 public: 218 public:
202 DartApiScope() { Dart_EnterScope(); } 219 DartApiScope() { Dart_EnterScope(); }
203 ~DartApiScope() { Dart_ExitScope(); } 220 ~DartApiScope() { Dart_ExitScope(); }
204 }; 221 };
205 222
206 #define DART_UNIMPLEMENTED_EXCEPTION() DartUtilities::notImplementedException(__ FILE__, __LINE__) 223 #define DART_UNIMPLEMENTED_EXCEPTION() DartUtilities::notImplementedException(__ FILE__, __LINE__)
207 #define DART_UNIMPLEMENTED() Dart_ThrowException(DART_UNIMPLEMENTED_EXCEPTION()) ; 224 #define DART_UNIMPLEMENTED() Dart_ThrowException(DART_UNIMPLEMENTED_EXCEPTION()) ;
208 225
209 } // namespace WebCore 226 } // namespace WebCore
210 227
211 #endif // DartUtilities_h 228 #endif // DartUtilities_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698