Chromium Code Reviews| 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 | 119 |
| 120 struct IntegerTrait { | 120 struct IntegerTrait { |
| 121 typedef int64_t nativeType; | 121 typedef int64_t nativeType; |
| 122 static Dart_Handle convert(Dart_Handle object, int64_t* value) | 122 static Dart_Handle convert(Dart_Handle object, int64_t* value) |
| 123 { | 123 { |
| 124 return Dart_IntegerToInt64(object, value); | 124 return Dart_IntegerToInt64(object, value); |
| 125 // FIXME: support bigints. | 125 // FIXME: support bigints. |
| 126 } | 126 } |
| 127 }; | 127 }; |
| 128 | 128 |
| 129 template <> | |
| 130 double DartUtilities::toNative<double>(Dart_Handle object) | |
| 131 { | |
| 132 return DartUtilities::toDouble(object); | |
|
antonm
2012/01/19 14:05:49
I am not sure you can use those helpers, what if I
Nikolay
2012/01/19 15:08:46
Done.
| |
| 133 } | |
| 134 | |
| 135 template <> | |
| 136 float DartUtilities::toNative<float>(Dart_Handle object) | |
| 137 { | |
| 138 return DartUtilities::toDouble(object); | |
| 139 } | |
| 140 | |
| 141 template <> | |
| 142 int8_t DartUtilities::toNative<int8_t>(Dart_Handle object) | |
| 143 { | |
| 144 return DartUtilities::toInteger(object); | |
| 145 } | |
| 146 | |
| 147 template <> | |
| 148 int16_t DartUtilities::toNative<int16_t>(Dart_Handle object) | |
| 149 { | |
| 150 return DartUtilities::toInteger(object); | |
| 151 } | |
| 152 | |
| 153 template <> | |
| 154 int32_t DartUtilities::toNative<int32_t>(Dart_Handle object) | |
| 155 { | |
| 156 return DartUtilities::toInteger(object); | |
| 157 } | |
| 158 | |
| 159 template <> | |
| 160 int64_t DartUtilities::toNative<int64_t>(Dart_Handle object) | |
| 161 { | |
| 162 return DartUtilities::toInteger(object); | |
| 163 } | |
| 164 | |
| 165 template <> | |
| 166 uint8_t DartUtilities::toNative<uint8_t>(Dart_Handle object) | |
| 167 { | |
| 168 return DartUtilities::toInteger(object); | |
|
antonm
2012/01/19 14:05:49
What if I pass -1 into such a function?
Nikolay
2012/01/19 15:08:46
c cast will apply. I think this behavior is natura
antonm
2012/01/19 15:33:13
I don't think so, as in Dart numbers doesn't have
Nikolay
2012/01/20 11:38:37
According to simple test in JS console this is beh
antonm
2012/01/20 17:35:57
Thanks a lot for verifying how JS works.
However,
| |
| 169 } | |
| 170 | |
| 171 template <> | |
| 172 uint16_t DartUtilities::toNative<uint16_t>(Dart_Handle object) | |
| 173 { | |
| 174 return DartUtilities::toInteger(object); | |
| 175 } | |
| 176 | |
| 177 template <> | |
| 178 uint32_t DartUtilities::toNative<uint32_t>(Dart_Handle object) | |
| 179 { | |
| 180 return DartUtilities::toInteger(object); | |
| 181 } | |
| 182 | |
| 129 int64_t DartUtilities::toInteger(Dart_Handle object, Dart_Handle& exception) | 183 int64_t DartUtilities::toInteger(Dart_Handle object, Dart_Handle& exception) |
| 130 { | 184 { |
| 131 return convert<IntegerTrait>(object, exception); | 185 return convert<IntegerTrait>(object, exception); |
| 132 } | 186 } |
| 133 | 187 |
| 134 int64_t DartUtilities::toInteger(Dart_Handle object) | 188 int64_t DartUtilities::toInteger(Dart_Handle object) |
| 135 { | 189 { |
| 136 Dart_Handle exception = 0; | 190 Dart_Handle exception = 0; |
| 137 int64_t value = DartUtilities::toInteger(object, exception); | 191 int64_t value = DartUtilities::toInteger(object, exception); |
| 138 ASSERT(!exception); | 192 ASSERT(!exception); |
| 139 return value; | 193 return value; |
| 140 } | 194 } |
| 141 | 195 |
| 142 struct DoubleTrait { | 196 struct DoubleTrait { |
| 143 typedef double nativeType; | 197 typedef double nativeType; |
| 144 static Dart_Handle convert(Dart_Handle object, double* value) | 198 static Dart_Handle convert(Dart_Handle object, double* value) |
| 145 { | 199 { |
| 146 if (!Dart_IsNumber(object)) | 200 if (!Dart_IsNumber(object)) |
| 147 return Dart_Error("the object !is Number"); | 201 return Dart_Error("the object !is Number"); |
| 148 | 202 |
| 149 object = Dart_InvokeDynamic(object, Dart_NewString("toDouble"), 0, 0); | 203 if (!Dart_IsDouble(object)) { |
| 150 if (Dart_IsError(object)) | 204 object = Dart_InvokeDynamic(object, Dart_NewString("toDouble"), 0, 0 ); |
| 151 return object; | 205 if (Dart_IsError(object)) |
| 206 return object; | |
| 207 } | |
| 152 | 208 |
| 153 return Dart_DoubleValue(object, value); | 209 return Dart_DoubleValue(object, value); |
| 154 } | 210 } |
| 155 }; | 211 }; |
| 156 | 212 |
| 157 double DartUtilities::toDouble(Dart_Handle object, Dart_Handle& exception) | 213 double DartUtilities::toDouble(Dart_Handle object, Dart_Handle& exception) |
| 158 { | 214 { |
| 159 return convert<DoubleTrait>(object, exception); | 215 return convert<DoubleTrait>(object, exception); |
| 160 } | 216 } |
| 161 | 217 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 return DartNode::toNative(object, exception); | 295 return DartNode::toNative(object, exception); |
| 240 } | 296 } |
| 241 | 297 |
| 242 // FIXME: this function requires better testing. Currently blocking as new Messa geChannel hasn't been implemented yet. | 298 // FIXME: this function requires better testing. Currently blocking as new Messa geChannel hasn't been implemented yet. |
| 243 void DartUtilities::toMessagePortArray(Dart_Handle value, MessagePortArray& port Array, Dart_Handle& exception) | 299 void DartUtilities::toMessagePortArray(Dart_Handle value, MessagePortArray& port Array, Dart_Handle& exception) |
| 244 { | 300 { |
| 245 Dart_Handle dom = Dart_LookupLibrary(Dart_NewString(DartUtilities::domLibrar yName)); | 301 Dart_Handle dom = Dart_LookupLibrary(Dart_NewString(DartUtilities::domLibrar yName)); |
| 246 ASSERT(!Dart_IsError(dom)); | 302 ASSERT(!Dart_IsError(dom)); |
| 247 | 303 |
| 248 Dart_Handle asList = Dart_InvokeStatic(dom, Dart_NewString("Utils"), Dart_Ne wString("convertToList"), 1, &value); | 304 Dart_Handle asList = Dart_InvokeStatic(dom, Dart_NewString("Utils"), Dart_Ne wString("convertToList"), 1, &value); |
| 249 if (Dart_IsError(asList)) { | 305 if (!checkResult(asList, exception)) |
| 250 DartUtilities::reportProblem(DartUtilities::scriptExecutionContext(), as List); | |
| 251 exception = DartDOMWrapper::exceptionCodeToDartException(INVALID_STATE_E RR); | |
| 252 return; | 306 return; |
| 253 } | |
| 254 ASSERT(Dart_IsList(asList)); | 307 ASSERT(Dart_IsList(asList)); |
| 255 | 308 |
| 256 intptr_t length = 0; | 309 intptr_t length = 0; |
| 257 Dart_ListLength(asList, &length); | 310 Dart_ListLength(asList, &length); |
| 258 portArray.resize(length); | 311 portArray.resize(length); |
| 259 for (int i = 0; i < length; i++) { | 312 for (int i = 0; i < length; i++) { |
| 260 Dart_Handle element = Dart_ListGetAt(asList, i); | 313 Dart_Handle element = Dart_ListGetAt(asList, i); |
| 261 if (Dart_IsError(element)) { | 314 if (!checkResult(element, exception)) |
| 262 exception = DartDOMWrapper::exceptionCodeToDartException(INVALID_STA TE_ERR); | |
| 263 return; | 315 return; |
| 264 } | |
| 265 | 316 |
| 266 MessagePort* messagePort = DartMessagePort::toNative(element, exception) .get(); | 317 MessagePort* messagePort = DartMessagePort::toNative(element, exception) .get(); |
| 267 if (exception) { | 318 if (exception) |
| 268 exception = DartDOMWrapper::exceptionCodeToDartException(INVALID_STA TE_ERR); | |
| 269 return; | 319 return; |
| 270 } | |
| 271 | 320 |
| 272 ASSERT(messagePort); | 321 ASSERT(messagePort); |
| 273 portArray[i] = messagePort; | 322 portArray[i] = messagePort; |
| 274 } | 323 } |
| 275 } | 324 } |
| 276 | 325 |
| 277 class DartDOMData { | 326 class DartDOMData { |
| 278 public: | 327 public: |
| 279 DartDOMData() | 328 DartDOMData() |
| 280 : m_scriptExecutionContext(0) | 329 : m_scriptExecutionContext(0) |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 473 errorMessage += String("\nError converting stack trace to a string: ") + Dart_GetError(stacktrace); | 522 errorMessage += String("\nError converting stack trace to a string: ") + Dart_GetError(stacktrace); |
| 474 else | 523 else |
| 475 errorMessage += String("\nStack Trace: ") + DartUtilities::dartStrin gToString(stacktrace); | 524 errorMessage += String("\nStack Trace: ") + DartUtilities::dartStrin gToString(stacktrace); |
| 476 } | 525 } |
| 477 | 526 |
| 478 if (context && context->isDocument()) | 527 if (context && context->isDocument()) |
| 479 static_cast<Document*>(context)->reportException(errorMessage, lineNumbe r, sourceFile, callStack); | 528 static_cast<Document*>(context)->reportException(errorMessage, lineNumbe r, sourceFile, callStack); |
| 480 } | 529 } |
| 481 | 530 |
| 482 } | 531 } |
| OLD | NEW |