Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #library('js_helper'); | 5 #library('js_helper'); |
| 6 | 6 |
| 7 #import('coreimpl.dart'); | 7 #import('coreimpl.dart'); |
| 8 | 8 |
| 9 #source('date_helper.dart'); | 9 #source('date_helper.dart'); |
| 10 #source('regexp_helper.dart'); | 10 #source('regexp_helper.dart'); |
| (...skipping 1255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1266 /** | 1266 /** |
| 1267 * Called from catch blocks in generated code to extract the Dart | 1267 * Called from catch blocks in generated code to extract the Dart |
| 1268 * exception from the thrown value. The thrown value may have been | 1268 * exception from the thrown value. The thrown value may have been |
| 1269 * created by [captureStackTrace] or it may be a 'native' JS | 1269 * created by [captureStackTrace] or it may be a 'native' JS |
| 1270 * exception. | 1270 * exception. |
| 1271 * | 1271 * |
| 1272 * Some native exceptions are mapped to new Dart instances, others are | 1272 * Some native exceptions are mapped to new Dart instances, others are |
| 1273 * returned unmodified. | 1273 * returned unmodified. |
| 1274 */ | 1274 */ |
| 1275 unwrapException(ex) { | 1275 unwrapException(ex) { |
| 1276 // Note that we are checking if the object has the property. If it | |
| 1277 // has, it could be set null if the thrown value is null. | |
|
ahe
2012/03/08 18:32:02
"set null" -> "null"
| |
| 1276 if (JS('bool', @'"dartException" in $0', ex)) { | 1278 if (JS('bool', @'"dartException" in $0', ex)) { |
| 1277 return JS('Object', @'$0.dartException', ex); | 1279 return JS('Object', @'$0.dartException', ex); |
| 1278 } else if (JS('bool', @'$0 instanceof TypeError', ex)) { | 1280 } else if (JS('bool', @'$0 instanceof TypeError', ex)) { |
| 1279 // TODO(ahe): ex.type is Chrome specific. | 1281 // TODO(ahe): ex.type is Chrome specific. |
| 1280 var type = JS('String', @'$0.type', ex); | 1282 var type = JS('String', @'$0.type', ex); |
| 1281 var jsArguments = JS('Object', @'$0.arguments', ex); | 1283 var jsArguments = JS('Object', @'$0.arguments', ex); |
| 1282 var name = jsArguments[0]; | 1284 var name = jsArguments[0]; |
| 1283 if (type == 'property_not_function' || | 1285 if (type == 'property_not_function' || |
| 1284 type == 'called_non_callable' || | 1286 type == 'called_non_callable' || |
| 1285 type == 'non_object_property_call' || | 1287 type == 'non_object_property_call' || |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1326 result[key] = value; | 1328 result[key] = value; |
| 1327 } | 1329 } |
| 1328 return result; | 1330 return result; |
| 1329 } | 1331 } |
| 1330 | 1332 |
| 1331 /** | 1333 /** |
| 1332 * Called by generated code to convert a Dart closure to a JS | 1334 * Called by generated code to convert a Dart closure to a JS |
| 1333 * closure when the Dart closure is passed to the DOM. | 1335 * closure when the Dart closure is passed to the DOM. |
| 1334 */ | 1336 */ |
| 1335 convertDartClosureToJS(closure) { | 1337 convertDartClosureToJS(closure) { |
| 1336 return JS("var", @"""function() { | 1338 var function = JS('var', @'$0.$identity', closure); |
| 1339 if (JS('bool', @'!!$0', function)) return function; | |
| 1340 function = JS("var", @"""function() { | |
| 1337 var dartClosure = $0; | 1341 var dartClosure = $0; |
| 1338 switch (arguments.length) { | 1342 switch (arguments.length) { |
| 1339 case 0: return $1(dartClosure); | 1343 case 0: return $1(dartClosure); |
| 1340 case 1: return $2(dartClosure, arguments[0]); | 1344 case 1: return $2(dartClosure, arguments[0]); |
| 1341 case 2: return $3(dartClosure, arguments[0], arguments[1]); | 1345 case 2: return $3(dartClosure, arguments[0], arguments[1]); |
| 1342 default: | 1346 default: |
| 1343 throw new Error('Unsupported number of arguments for wrapped closure'); | 1347 throw new Error('Unsupported number of arguments for wrapped closure'); |
| 1344 } | 1348 } |
| 1345 }""", | 1349 }""", |
| 1346 closure, | 1350 closure, |
| 1347 callClosure0, | 1351 callClosure0, |
| 1348 callClosure1, | 1352 callClosure1, |
| 1349 callClosure2); | 1353 callClosure2); |
| 1354 JS('void', @'$0.$identity = $1', closure, function); | |
| 1355 return function; | |
| 1350 } | 1356 } |
| 1351 | 1357 |
| 1352 /** | 1358 /** |
| 1353 * Helper methods when converting a Dart closure to a JS closure. | 1359 * Helper methods when converting a Dart closure to a JS closure. |
| 1354 */ | 1360 */ |
| 1355 callClosure0(closure) => closure(); | 1361 callClosure0(closure) => closure(); |
| 1356 callClosure1(closure, arg1) => closure(arg1); | 1362 callClosure1(closure, arg1) => closure(arg1); |
| 1357 callClosure2(closure, arg1, arg2) => closure(arg1, arg2); | 1363 callClosure2(closure, arg1, arg2) => closure(arg1, arg2); |
| 1358 | 1364 |
| 1359 class StackTrace { | 1365 class StackTrace { |
| 1360 var stack; | 1366 var stack; |
| 1361 StackTrace(this.stack); | 1367 StackTrace(this.stack); |
| 1362 String toString() => stack != null ? stack : ''; | 1368 String toString() => stack != null ? stack : ''; |
| 1363 } | 1369 } |
| OLD | NEW |