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

Side by Side Diff: frog/leg/lib/js_helper.dart

Issue 9750003: Write our JS blobs for handling native classes in Dart. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 8 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 (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('constant_map.dart'); 9 #source('constant_map.dart');
10 #source('native_helper.dart');
10 #source('regexp_helper.dart'); 11 #source('regexp_helper.dart');
11 #source('string_helper.dart'); 12 #source('string_helper.dart');
12 13
13 /** 14 /**
14 * Returns true if both arguments are numbers. 15 * Returns true if both arguments are numbers.
15 * 16 *
16 * If only the first argument is a number, an 17 * If only the first argument is a number, an
17 * [IllegalArgumentException] with the other argument is thrown. 18 * [IllegalArgumentException] with the other argument is thrown.
18 */ 19 */
19 bool checkNumbers(var a, var b) { 20 bool checkNumbers(var a, var b) {
(...skipping 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 // TODO(ahe): Dynamic may be overridden. 1181 // TODO(ahe): Dynamic may be overridden.
1181 builtin$get$dynamic(receiver) => receiver; 1182 builtin$get$dynamic(receiver) => receiver;
1182 1183
1183 /** 1184 /**
1184 * Called by generated code to capture the stacktrace before throwing 1185 * Called by generated code to capture the stacktrace before throwing
1185 * an exception. 1186 * an exception.
1186 */ 1187 */
1187 captureStackTrace(ex) { 1188 captureStackTrace(ex) {
1188 var jsError = JS('Object', @'new Error()'); 1189 var jsError = JS('Object', @'new Error()');
1189 JS('void', @'#.dartException = #', jsError, ex); 1190 JS('void', @'#.dartException = #', jsError, ex);
1190 JS('void', @'''#.toString = #''', jsError, toStringWrapper); 1191 JS('void', @'''#.toString = #''', jsError, DART_CLOSURE_TO_JS(toStringWrapper) );
floitsch 2012/03/28 23:36:33 80 chars.
ngeoffray 2012/03/29 11:38:40 Done.
1191 return jsError; 1192 return jsError;
1192 } 1193 }
1193 1194
1194 /** 1195 /**
1195 * This method is installed as JavaScript toString method on exception 1196 * This method is installed as JavaScript toString method on exception
1196 * objects in [captureStackTrace]. So JavaScript 'this' binds to an 1197 * objects in [captureStackTrace]. So JavaScript 'this' binds to an
1197 * instance of JavaScript Error to which we have added a property 1198 * instance of JavaScript Error to which we have added a property
1198 * 'dartException' which holds a Dart object. 1199 * 'dartException' which holds a Dart object.
1199 */ 1200 */
1200 toStringWrapper() => JS('Object', @'this.dartException').toString(); 1201 toStringWrapper() => JS('Object', @'this.dartException').toString();
(...skipping 18 matching lines...) Expand all
1219 * Called from catch blocks in generated code to extract the Dart 1220 * Called from catch blocks in generated code to extract the Dart
1220 * exception from the thrown value. The thrown value may have been 1221 * exception from the thrown value. The thrown value may have been
1221 * created by [captureStackTrace] or it may be a 'native' JS 1222 * created by [captureStackTrace] or it may be a 'native' JS
1222 * exception. 1223 * exception.
1223 * 1224 *
1224 * Some native exceptions are mapped to new Dart instances, others are 1225 * Some native exceptions are mapped to new Dart instances, others are
1225 * returned unmodified. 1226 * returned unmodified.
1226 */ 1227 */
1227 unwrapException(ex) { 1228 unwrapException(ex) {
1228 // Note that we are checking if the object has the property. If it 1229 // Note that we are checking if the object has the property. If it
1229 // has, it could be set null if the thrown value is null. 1230 // has, it could be set to null if the thrown value is null.
1230 if (JS('bool', @'"dartException" in #', ex)) { 1231 if (JS('bool', @'"dartException" in #', ex)) {
1231 return JS('Object', @'#.dartException', ex); 1232 return JS('Object', @'#.dartException', ex);
1232 } else if (JS('bool', @'# instanceof TypeError', ex)) { 1233 } else if (JS('bool', @'# instanceof TypeError', ex)) {
1233 // TODO(ahe): ex.type is Chrome specific. 1234 // TODO(ahe): ex.type is Chrome specific.
1234 var type = JS('String', @'#.type', ex); 1235 var type = JS('String', @'#.type', ex);
1235 var jsArguments = JS('Object', @'#.arguments', ex); 1236 var jsArguments = JS('Object', @'#.arguments', ex);
1236 var name = jsArguments[0]; 1237 var name = jsArguments[0];
1237 if (type == 'property_not_function' || 1238 if (type == 'property_not_function' ||
1238 type == 'called_non_callable' || 1239 type == 'called_non_callable' ||
1239 type == 'non_object_property_call' || 1240 type == 'non_object_property_call' ||
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1311 * closure when the Dart closure is passed to the DOM. 1312 * closure when the Dart closure is passed to the DOM.
1312 */ 1313 */
1313 convertDartClosureToJS(closure) { 1314 convertDartClosureToJS(closure) {
1314 if (closure === null) return null; 1315 if (closure === null) return null;
1315 var function = JS('var', @'#.$identity', closure); 1316 var function = JS('var', @'#.$identity', closure);
1316 if (JS('bool', @'!!#', function)) return function; 1317 if (JS('bool', @'!!#', function)) return function;
1317 1318
1318 function = JS("var", @"""function() { 1319 function = JS("var", @"""function() {
1319 return #(#, #, arguments.length, arguments[0], arguments[1]); 1320 return #(#, #, arguments.length, arguments[0], arguments[1]);
1320 }""", 1321 }""",
1321 invokeClosure, 1322 DART_CLOSURE_TO_JS(invokeClosure),
1322 closure, 1323 closure,
1323 JS_CURRENT_ISOLATE()); 1324 JS_CURRENT_ISOLATE());
1324 1325
1325 JS('void', @'#.$identity = #', closure, function); 1326 JS('void', @'#.$identity = #', closure, function);
1326 return function; 1327 return function;
1327 } 1328 }
1328 1329
1329 /** 1330 /**
1330 * Super class for Dart closures. 1331 * Super class for Dart closures.
1331 */ 1332 */
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1366 /** 1367 /**
1367 * Represents the type of Null. The compiler treats this specially. 1368 * Represents the type of Null. The compiler treats this specially.
1368 */ 1369 */
1369 class Null { 1370 class Null {
1370 factory Null() { 1371 factory Null() {
1371 throw new UnsupportedOperationException('new Null()'); 1372 throw new UnsupportedOperationException('new Null()');
1372 } 1373 }
1373 } 1374 }
1374 1375
1375 builtin$get$toString(receiver) => () => builtin$toString$0(receiver); 1376 builtin$get$toString(receiver) => () => builtin$toString$0(receiver);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698