| OLD | NEW |
| 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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 template <class BindingsClass> | 240 template <class BindingsClass> |
| 241 static void wrapperWeakCallback(Dart_Handle, void* peer) | 241 static void wrapperWeakCallback(Dart_Handle, void* peer) |
| 242 { | 242 { |
| 243 DartDOMData* domData = DartIsolate::currentDOMData(); | 243 DartDOMData* domData = DartIsolate::currentDOMData(); |
| 244 typename BindingsClass::NativeType* domObject = static_cast<typename Bin
dingsClass::NativeType*>(peer); | 244 typename BindingsClass::NativeType* domObject = static_cast<typename Bin
dingsClass::NativeType*>(peer); |
| 245 BindingsClass::NativeTraits::removeWrapper(domData, domObject); | 245 BindingsClass::NativeTraits::removeWrapper(domData, domObject); |
| 246 domObject->deref(); | 246 domObject->deref(); |
| 247 } | 247 } |
| 248 }; | 248 }; |
| 249 | 249 |
| 250 // ParameterAdapter. | |
| 251 | |
| 252 template <typename Value> | |
| 253 class ParameterAdapterBase { | |
| 254 public: | |
| 255 bool conversionSuccessful() const { return !m_exception; } | |
| 256 | |
| 257 Dart_Handle exception() const | |
| 258 { | |
| 259 ASSERT(!conversionSuccessful()); | |
| 260 return m_exception; | |
| 261 } | |
| 262 | |
| 263 protected: | |
| 264 | |
| 265 ParameterAdapterBase() | |
| 266 : m_value() | |
| 267 , m_exception(0) { } | |
| 268 | |
| 269 void setException(Dart_Handle exception) | |
| 270 { | |
| 271 ASSERT(exception); | |
| 272 m_exception = exception; | |
| 273 ASSERT(!conversionSuccessful()); | |
| 274 } | |
| 275 | |
| 276 const Value& value() const | |
| 277 { | |
| 278 ASSERT(conversionSuccessful()); | |
| 279 return m_value; | |
| 280 } | |
| 281 | |
| 282 void setValue(Value value) | |
| 283 { | |
| 284 m_value = value; | |
| 285 } | |
| 286 | |
| 287 protected: | |
| 288 Value m_value; | |
| 289 | |
| 290 template <class C> | |
| 291 void init(C* c, Dart_Handle handle) | |
| 292 { | |
| 293 Dart_Handle exception = 0; | |
| 294 this->setValue(c->convert(handle, exception)); | |
| 295 if (exception) | |
| 296 this->setException(exception); | |
| 297 } | |
| 298 | |
| 299 template <class C> | |
| 300 void init(C* c, Dart_Handle handle, DartUtilities::ConversionFlag conversion
Flag) | |
| 301 { | |
| 302 if (conversionFlag == DartUtilities::ConvertNullToDefaultValue) { | |
| 303 if (Dart_IsNull(handle)) | |
| 304 return; | |
| 305 } | |
| 306 Dart_Handle exception = 0; | |
| 307 this->setValue(c->convert(handle, exception)); | |
| 308 if (exception) | |
| 309 this->setException(exception); | |
| 310 } | |
| 311 | |
| 312 private: | |
| 313 Dart_Handle m_exception; | |
| 314 }; | |
| 315 | |
| 316 template <class DartBindingsClass> | |
| 317 class ParameterAdapter {}; | |
| 318 | |
| 319 // FIXME: [performance] need better treatment of String vs. AtomicString, cf. v8
implementation. | |
| 320 template <> | |
| 321 class ParameterAdapter<String> : public ParameterAdapterBase< RefPtr<StringImpl>
> { | |
| 322 public: | |
| 323 explicit ParameterAdapter(Dart_Handle handle, DartUtilities::ConversionFlag
flag = DartUtilities::ConvertNone) | |
| 324 { | |
| 325 Dart_Handle exception = 0; | |
| 326 setValue(DartUtilities::toStringImpl(handle, flag, exception)); | |
| 327 if (exception) | |
| 328 setException(exception); | |
| 329 } | |
| 330 operator String() const { return String(this->value()); } | |
| 331 operator AtomicString() const { return AtomicString(this->value()); } | |
| 332 }; | |
| 333 | |
| 334 } | 250 } |
| 335 | 251 |
| 336 #endif // DartDOMWrapper_h | 252 #endif // DartDOMWrapper_h |
| OLD | NEW |