| 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 118 |
| 119 struct IntegerTrait { | 119 struct IntegerTrait { |
| 120 typedef int64_t nativeType; | 120 typedef int64_t nativeType; |
| 121 static Dart_Handle convert(Dart_Handle object, int64_t* value) | 121 static Dart_Handle convert(Dart_Handle object, int64_t* value) |
| 122 { | 122 { |
| 123 return Dart_IntegerToInt64(object, value); | 123 return Dart_IntegerToInt64(object, value); |
| 124 // FIXME: support bigints. | 124 // FIXME: support bigints. |
| 125 } | 125 } |
| 126 }; | 126 }; |
| 127 | 127 |
| 128 template <> |
| 129 double DartUtilities::toNative<double>(Dart_Handle object) |
| 130 { |
| 131 return DartUtilities::toDouble(object); |
| 132 } |
| 133 |
| 134 template <> |
| 135 float DartUtilities::toNative<float>(Dart_Handle object) |
| 136 { |
| 137 return DartUtilities::toDouble(object); |
| 138 } |
| 139 |
| 140 template <> |
| 141 int8_t DartUtilities::toNative<int8_t>(Dart_Handle object) |
| 142 { |
| 143 return DartUtilities::toInteger(object); |
| 144 } |
| 145 |
| 146 template <> |
| 147 int16_t DartUtilities::toNative<int16_t>(Dart_Handle object) |
| 148 { |
| 149 return DartUtilities::toInteger(object); |
| 150 } |
| 151 |
| 152 template <> |
| 153 int32_t DartUtilities::toNative<int32_t>(Dart_Handle object) |
| 154 { |
| 155 return DartUtilities::toInteger(object); |
| 156 } |
| 157 |
| 158 template <> |
| 159 int64_t DartUtilities::toNative<int64_t>(Dart_Handle object) |
| 160 { |
| 161 return DartUtilities::toInteger(object); |
| 162 } |
| 163 |
| 164 template <> |
| 165 uint8_t DartUtilities::toNative<uint8_t>(Dart_Handle object) |
| 166 { |
| 167 return DartUtilities::toInteger(object); |
| 168 } |
| 169 |
| 170 template <> |
| 171 uint16_t DartUtilities::toNative<uint16_t>(Dart_Handle object) |
| 172 { |
| 173 return DartUtilities::toInteger(object); |
| 174 } |
| 175 |
| 176 template <> |
| 177 uint32_t DartUtilities::toNative<uint32_t>(Dart_Handle object) |
| 178 { |
| 179 return DartUtilities::toInteger(object); |
| 180 } |
| 181 |
| 128 int64_t DartUtilities::toInteger(Dart_Handle object, Dart_Handle& exception) | 182 int64_t DartUtilities::toInteger(Dart_Handle object, Dart_Handle& exception) |
| 129 { | 183 { |
| 130 return convert<IntegerTrait>(object, exception); | 184 return convert<IntegerTrait>(object, exception); |
| 131 } | 185 } |
| 132 | 186 |
| 133 int64_t DartUtilities::toInteger(Dart_Handle object) | 187 int64_t DartUtilities::toInteger(Dart_Handle object) |
| 134 { | 188 { |
| 135 Dart_Handle exception = 0; | 189 Dart_Handle exception = 0; |
| 136 int64_t value = DartUtilities::toInteger(object, exception); | 190 int64_t value = DartUtilities::toInteger(object, exception); |
| 137 ASSERT(!exception); | 191 ASSERT(!exception); |
| 138 return value; | 192 return value; |
| 139 } | 193 } |
| 140 | 194 |
| 141 struct DoubleTrait { | 195 struct DoubleTrait { |
| 142 typedef double nativeType; | 196 typedef double nativeType; |
| 143 static Dart_Handle convert(Dart_Handle object, double* value) | 197 static Dart_Handle convert(Dart_Handle object, double* value) |
| 144 { | 198 { |
| 145 if (!Dart_IsNumber(object)) | 199 if (!Dart_IsNumber(object)) |
| 146 return Dart_Error("the object !is Number"); | 200 return Dart_Error("the object !is Number"); |
| 147 | 201 |
| 148 object = Dart_InvokeDynamic(object, Dart_NewString("toDouble"), 0, 0); | 202 if (!Dart_IsDouble(object)) { |
| 149 if (Dart_IsError(object)) | 203 object = Dart_InvokeDynamic(object, Dart_NewString("toDouble"), 0, 0
); |
| 150 return object; | 204 if (Dart_IsError(object)) |
| 205 return object; |
| 206 } |
| 151 | 207 |
| 152 return Dart_DoubleValue(object, value); | 208 return Dart_DoubleValue(object, value); |
| 153 } | 209 } |
| 154 }; | 210 }; |
| 155 | 211 |
| 156 double DartUtilities::toDouble(Dart_Handle object, Dart_Handle& exception) | 212 double DartUtilities::toDouble(Dart_Handle object, Dart_Handle& exception) |
| 157 { | 213 { |
| 158 return convert<DoubleTrait>(object, exception); | 214 return convert<DoubleTrait>(object, exception); |
| 159 } | 215 } |
| 160 | 216 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 return DartNode::toNative(object, exception); | 294 return DartNode::toNative(object, exception); |
| 239 } | 295 } |
| 240 | 296 |
| 241 // FIXME: this function requires better testing. Currently blocking as new Messa
geChannel hasn't been implemented yet. | 297 // FIXME: this function requires better testing. Currently blocking as new Messa
geChannel hasn't been implemented yet. |
| 242 void DartUtilities::toMessagePortArray(Dart_Handle value, MessagePortArray& port
Array, Dart_Handle& exception) | 298 void DartUtilities::toMessagePortArray(Dart_Handle value, MessagePortArray& port
Array, Dart_Handle& exception) |
| 243 { | 299 { |
| 244 Dart_Handle dom = Dart_LookupLibrary(Dart_NewString(DartUtilities::domLibrar
yName)); | 300 Dart_Handle dom = Dart_LookupLibrary(Dart_NewString(DartUtilities::domLibrar
yName)); |
| 245 ASSERT(!Dart_IsError(dom)); | 301 ASSERT(!Dart_IsError(dom)); |
| 246 | 302 |
| 247 Dart_Handle asList = Dart_InvokeStatic(dom, Dart_NewString("Utils"), Dart_Ne
wString("convertToList"), 1, &value); | 303 Dart_Handle asList = Dart_InvokeStatic(dom, Dart_NewString("Utils"), Dart_Ne
wString("convertToList"), 1, &value); |
| 248 if (Dart_IsError(asList)) { | 304 if (!checkResult(asList, exception)) |
| 249 DartUtilities::reportProblem(DartUtilities::scriptExecutionContext(), as
List); | |
| 250 exception = DartDOMWrapper::exceptionCodeToDartException(INVALID_STATE_E
RR); | |
| 251 return; | 305 return; |
| 252 } | |
| 253 ASSERT(Dart_IsList(asList)); | 306 ASSERT(Dart_IsList(asList)); |
| 254 | 307 |
| 255 intptr_t length = 0; | 308 intptr_t length = 0; |
| 256 Dart_ListLength(asList, &length); | 309 Dart_ListLength(asList, &length); |
| 257 portArray.resize(length); | 310 portArray.resize(length); |
| 258 for (int i = 0; i < length; i++) { | 311 for (int i = 0; i < length; i++) { |
| 259 Dart_Handle element = Dart_ListGetAt(asList, i); | 312 Dart_Handle element = Dart_ListGetAt(asList, i); |
| 260 if (Dart_IsError(element)) { | 313 if (!checkResult(element, exception)) |
| 261 exception = DartDOMWrapper::exceptionCodeToDartException(INVALID_STA
TE_ERR); | |
| 262 return; | 314 return; |
| 263 } | |
| 264 | 315 |
| 265 MessagePort* messagePort = DartMessagePort::toNative(element, exception)
.get(); | 316 MessagePort* messagePort = DartMessagePort::toNative(element, exception)
.get(); |
| 266 if (exception) { | 317 if (exception) |
| 267 exception = DartDOMWrapper::exceptionCodeToDartException(INVALID_STA
TE_ERR); | |
| 268 return; | 318 return; |
| 269 } | |
| 270 | 319 |
| 271 ASSERT(messagePort); | 320 ASSERT(messagePort); |
| 272 portArray[i] = messagePort; | 321 portArray[i] = messagePort; |
| 273 } | 322 } |
| 274 } | 323 } |
| 275 | 324 |
| 276 class DartDOMData { | 325 class DartDOMData { |
| 277 public: | 326 public: |
| 278 DartDOMData() | 327 DartDOMData() |
| 279 : m_scriptExecutionContext(0) | 328 : m_scriptExecutionContext(0) |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 errorMessage += String("\nError converting stack trace to a string:
") + Dart_GetError(stacktrace); | 514 errorMessage += String("\nError converting stack trace to a string:
") + Dart_GetError(stacktrace); |
| 466 else | 515 else |
| 467 errorMessage += String("\nStack Trace: ") + DartUtilities::dartStrin
gToString(stacktrace); | 516 errorMessage += String("\nStack Trace: ") + DartUtilities::dartStrin
gToString(stacktrace); |
| 468 } | 517 } |
| 469 | 518 |
| 470 if (context && context->isDocument()) | 519 if (context && context->isDocument()) |
| 471 static_cast<Document*>(context)->reportException(errorMessage, lineNumbe
r, sourceFile, callStack); | 520 static_cast<Document*>(context)->reportException(errorMessage, lineNumbe
r, sourceFile, callStack); |
| 472 } | 521 } |
| 473 | 522 |
| 474 } | 523 } |
| OLD | NEW |