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

Side by Side Diff: frog/frogsh

Issue 8574066: Add a test for "is Object", fix try-catch of null (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: frogsh, status Created 9 years, 1 month 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
« no previous file with comments | « frog/corejs.dart ('k') | tests/co19/co19-frog.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env node 1 #!/usr/bin/env node
2 // ********** Library dart:core ************** 2 // ********** Library dart:core **************
3 // ********** Natives dart:core ************** 3 // ********** Natives dart:core **************
4 /** 4 /**
5 * Generates a dynamic call stub for a function. 5 * Generates a dynamic call stub for a function.
6 * Our goal is to create a stub method like this on-the-fly: 6 * Our goal is to create a stub method like this on-the-fly:
7 * function($0, $1, capture) { this($0, $1, true, capture); } 7 * function($0, $1, capture) { this($0, $1, true, capture); }
8 * 8 *
9 * This stub then replaces the dynamic one on Function, with one that is 9 * This stub then replaces the dynamic one on Function, with one that is
10 * specialized for that particular function, taking into account its default 10 * specialized for that particular function, taking into account its default
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 // TODO(jmesserly): can this ever happen? 95 // TODO(jmesserly): can this ever happen?
96 res = new NoSuchMethodException('', e.arguments[0], []); 96 res = new NoSuchMethodException('', e.arguments[0], []);
97 } 97 }
98 break; 98 break;
99 } 99 }
100 } else if (e instanceof RangeError) { 100 } else if (e instanceof RangeError) {
101 if (e.message.indexOf('call stack') >= 0) { 101 if (e.message.indexOf('call stack') >= 0) {
102 res = new StackOverflowException(); 102 res = new StackOverflowException();
103 } 103 }
104 } 104 }
105 // TODO(jmesserly): setting the stack property is not a long term solution. 105 if (res) {
106 // Also it causes the exception to print as if it were a TypeError or 106 // TODO(jmesserly): setting the stack property is not a long term solution.
107 // RangeError, instead of using the proper toString. 107 // Also it causes the exception to print as if it were a JS TypeError or
108 res.stack = e.stack; 108 // RangeError, instead of using the proper toString.
109 res.stack = e.stack;
110 }
109 return res; 111 return res;
110 } 112 }
111 function $notnull_bool(test) { 113 function $notnull_bool(test) {
112 return (test === true || test === false) ? test : test.is$bool(); // TypeError 114 return (test === true || test === false) ? test : test.is$bool(); // TypeError
113 } 115 }
114 function $assert(test, text, url, line, column) { 116 function $assert(test, text, url, line, column) {
115 if (typeof test == 'function') test = test(); 117 if (typeof test == 'function') test = test();
116 if (!test) $throw(new AssertError(text, url, line, column)); 118 if (!test) $throw(new AssertError(text, url, line, column));
117 } 119 }
118 function $throw(e) { 120 function $throw(e) {
(...skipping 10434 matching lines...) Expand 10 before | Expand all | Expand 10 after
10553 CoreJs.prototype.generate = function(w) { 10555 CoreJs.prototype.generate = function(w) {
10554 if ($notnull_bool(this.useVarMethod)) { 10556 if ($notnull_bool(this.useVarMethod)) {
10555 this.useTypeNameOf = true; 10557 this.useTypeNameOf = true;
10556 w.writeln("function $varMethod(name, methods) {\n Object.prototype[name] = function() {\n $patchMethod(this, name, methods);\n return this[name].appl y(this, Array.prototype.slice.call(arguments));\n };\n}\nfunction $patchMethod( obj, name, methods) {\n // Get the prototype to patch.\n // Don't overwrite an existing stub, like the one on Object.prototype\n var proto = Object.getProtot ypeOf(obj);\n if (!proto || proto.hasOwnProperty(name)) proto = obj;\n var met hod;\n while (obj && !(method = methods[obj.$typeNameOf()])) {\n obj = Objec t.getPrototypeOf(obj);\n }\n obj[name] = method || methods['Object'];\n}"); 10558 w.writeln("function $varMethod(name, methods) {\n Object.prototype[name] = function() {\n $patchMethod(this, name, methods);\n return this[name].appl y(this, Array.prototype.slice.call(arguments));\n };\n}\nfunction $patchMethod( obj, name, methods) {\n // Get the prototype to patch.\n // Don't overwrite an existing stub, like the one on Object.prototype\n var proto = Object.getProtot ypeOf(obj);\n if (!proto || proto.hasOwnProperty(name)) proto = obj;\n var met hod;\n while (obj && !(method = methods[obj.$typeNameOf()])) {\n obj = Objec t.getPrototypeOf(obj);\n }\n obj[name] = method || methods['Object'];\n}");
10557 } 10559 }
10558 if ($notnull_bool(this.useGenStub)) { 10560 if ($notnull_bool(this.useGenStub)) {
10559 this.useThrow = true; 10561 this.useThrow = true;
10560 w.writeln("/**\n * Generates a dynamic call stub for a function.\n * Our goa l is to create a stub method like this on-the-fly:\n * function($0, $1, captur e) { this($0, $1, true, capture); }\n *\n * This stub then replaces the dynamic one on Function, with one that is\n * specialized for that particular function, taking into account its default\n * arguments.\n */\nFunction.prototype.$genStub = function(argsLength, names) {\n // TODO(jmesserly): only emit $genStub if ac tually needed\n\n // Fast path: if no named arguments and arg count matches\n if (this.length == argsLength && !names) {\n return this;\n }\n\n function $throwArgMismatch() {\n // TODO(jmesserly): better error message\n $throw( new ClosureArgumentMismatchException());\n }\n\n var paramsNamed = this.$optio nal ? (this.$optional.length / 2) : 0;\n var paramsBare = this.length - paramsN amed;\n var argsNamed = names ? names.length : 0;\n var argsBare = argsLength - argsNamed;\n\n // Check we got the right number of arguments\n if (argsBare < paramsBare || argsLength > this.length ||\n argsNamed > paramsNamed) {\n return $throwArgMismatch;\n }\n\n // First, fill in all of the default valu es\n var p = new Array(paramsBare);\n if (paramsNamed) {\n p = p.concat(thi s.$optional.slice(paramsNamed));\n }\n // Fill in positional args\n var a = n ew Array(argsLength);\n for (var i = 0; i < argsBare; i++) {\n p[i] = a[i] = '$' + i;\n }\n // Then overwrite with supplied values for optional args\n va r lastParameterIndex;\n var namesInOrder = true;\n for (var i = 0; i < argsNam ed; i++) {\n var name = names[i];\n a[i + argsBare] = name;\n var j = t his.$optional.indexOf(name, 0);\n if (j < 0 || j >= paramsNamed) {\n ret urn $throwArgMismatch;\n } else if (lastParameterIndex && lastParameterIndex > j) {\n namesInOrder = false;\n }\n p[j + paramsBare] = name;\n l astParameterIndex = j;\n }\n\n if (this.length == argsLength && namesInOrder) {\n // Fast path #2: named arguments, but they're in order.\n return this; \n }\n\n // Note: using Function instead of 'eval' to get a clean scope.\n // TODO(jmesserly): evaluate the performance of these stubs.\n var f = 'function( ' + a.join(',') + '){return $f(' + p.join(',') + ');}';\n return new Function(' $f', 'return ' + f + '').call(null, this);\n}"); 10562 w.writeln("/**\n * Generates a dynamic call stub for a function.\n * Our goa l is to create a stub method like this on-the-fly:\n * function($0, $1, captur e) { this($0, $1, true, capture); }\n *\n * This stub then replaces the dynamic one on Function, with one that is\n * specialized for that particular function, taking into account its default\n * arguments.\n */\nFunction.prototype.$genStub = function(argsLength, names) {\n // TODO(jmesserly): only emit $genStub if ac tually needed\n\n // Fast path: if no named arguments and arg count matches\n if (this.length == argsLength && !names) {\n return this;\n }\n\n function $throwArgMismatch() {\n // TODO(jmesserly): better error message\n $throw( new ClosureArgumentMismatchException());\n }\n\n var paramsNamed = this.$optio nal ? (this.$optional.length / 2) : 0;\n var paramsBare = this.length - paramsN amed;\n var argsNamed = names ? names.length : 0;\n var argsBare = argsLength - argsNamed;\n\n // Check we got the right number of arguments\n if (argsBare < paramsBare || argsLength > this.length ||\n argsNamed > paramsNamed) {\n return $throwArgMismatch;\n }\n\n // First, fill in all of the default valu es\n var p = new Array(paramsBare);\n if (paramsNamed) {\n p = p.concat(thi s.$optional.slice(paramsNamed));\n }\n // Fill in positional args\n var a = n ew Array(argsLength);\n for (var i = 0; i < argsBare; i++) {\n p[i] = a[i] = '$' + i;\n }\n // Then overwrite with supplied values for optional args\n va r lastParameterIndex;\n var namesInOrder = true;\n for (var i = 0; i < argsNam ed; i++) {\n var name = names[i];\n a[i + argsBare] = name;\n var j = t his.$optional.indexOf(name, 0);\n if (j < 0 || j >= paramsNamed) {\n ret urn $throwArgMismatch;\n } else if (lastParameterIndex && lastParameterIndex > j) {\n namesInOrder = false;\n }\n p[j + paramsBare] = name;\n l astParameterIndex = j;\n }\n\n if (this.length == argsLength && namesInOrder) {\n // Fast path #2: named arguments, but they're in order.\n return this; \n }\n\n // Note: using Function instead of 'eval' to get a clean scope.\n // TODO(jmesserly): evaluate the performance of these stubs.\n var f = 'function( ' + a.join(',') + '){return $f(' + p.join(',') + ');}';\n return new Function(' $f', 'return ' + f + '').call(null, this);\n}");
10561 } 10563 }
10562 if ($notnull_bool(this.useStackTraceOf)) { 10564 if ($notnull_bool(this.useStackTraceOf)) {
10563 w.writeln("function $stackTraceOf(e) {\n // TODO(jmesserly): we shouldn't b e relying on the e.stack property.\n // Need to mangle it.\n return e.stack ? e.stack : null;\n}"); 10565 w.writeln("function $stackTraceOf(e) {\n // TODO(jmesserly): we shouldn't b e relying on the e.stack property.\n // Need to mangle it.\n return (e && e.s tack) ? e.stack : null;\n}");
10564 } 10566 }
10565 if ($notnull_bool(this.useToDartException)) { 10567 if ($notnull_bool(this.useToDartException)) {
10566 w.writeln("// Translate a JavaScript exception to a Dart exception\n// TODO( jmesserly): cross browser support. This is Chrome specific.\nfunction $toDartExc eption(e) {\n var res = e;\n if (e instanceof TypeError) {\n switch(e.type) {\n case 'property_not_function':\n case 'called_non_callable':\n if (e.arguments[0] == null) {\n res = new NullPointerException();\n } else {\n res = new ObjectNotClosureException();\n }\n break;\n case 'non_object_property_call':\n case 'non_object_pr operty_load':\n res = new NullPointerException();\n break;\n case 'undefined_method':\n if (e.arguments[0] == 'call' || e.arguments[0] == 'apply') {\n res = new ObjectNotClosureException();\n } else {\n // TODO(jmesserly): can this ever happen?\n res = new NoS uchMethodException('', e.arguments[0], []);\n }\n break;\n }\n } else if (e instanceof RangeError) {\n if (e.message.indexOf('call stack') >= 0) {\n res = new StackOverflowException();\n }\n }\n // TODO(jmesse rly): setting the stack property is not a long term solution.\n // Also it caus es the exception to print as if it were a TypeError or\n // RangeError, instead of using the proper toString.\n res.stack = e.stack;\n return res;\n}"); 10568 w.writeln("// Translate a JavaScript exception to a Dart exception\n// TODO( jmesserly): cross browser support. This is Chrome specific.\nfunction $toDartExc eption(e) {\n var res = e;\n if (e instanceof TypeError) {\n switch(e.type) {\n case 'property_not_function':\n case 'called_non_callable':\n if (e.arguments[0] == null) {\n res = new NullPointerException();\n } else {\n res = new ObjectNotClosureException();\n }\n break;\n case 'non_object_property_call':\n case 'non_object_pr operty_load':\n res = new NullPointerException();\n break;\n case 'undefined_method':\n if (e.arguments[0] == 'call' || e.arguments[0] == 'apply') {\n res = new ObjectNotClosureException();\n } else {\n // TODO(jmesserly): can this ever happen?\n res = new NoS uchMethodException('', e.arguments[0], []);\n }\n break;\n }\n } else if (e instanceof RangeError) {\n if (e.message.indexOf('call stack') >= 0) {\n res = new StackOverflowException();\n }\n }\n if (res) {\n // TODO(jmesserly): setting the stack property is not a long term solution.\n // Also it causes the exception to print as if it were a JS TypeError or\n // RangeError, instead of using the proper toString.\n res.stack = e.stack;\ n }\n return res;\n}");
10567 } 10569 }
10568 if ($notnull_bool(this.useNotNullBool)) { 10570 if ($notnull_bool(this.useNotNullBool)) {
10569 this.useThrow = true; 10571 this.useThrow = true;
10570 w.writeln("function $notnull_bool(test) {\n return (test === true || test = == false) ? test : test.is$bool(); // TypeError\n}"); 10572 w.writeln("function $notnull_bool(test) {\n return (test === true || test = == false) ? test : test.is$bool(); // TypeError\n}");
10571 } 10573 }
10572 if ($notnull_bool(this.useAssert)) { 10574 if ($notnull_bool(this.useAssert)) {
10573 this.useThrow = true; 10575 this.useThrow = true;
10574 w.writeln("function $assert(test, text, url, line, column) {\n if (typeof t est == 'function') test = test();\n if (!test) $throw(new AssertError(text, url , line, column));\n}"); 10576 w.writeln("function $assert(test, text, url, line, column) {\n if (typeof t est == 'function') test = test();\n if (!test) $throw(new AssertError(text, url , line, column));\n}");
10575 } 10577 }
10576 if ($notnull_bool(this.useThrow)) { 10578 if ($notnull_bool(this.useThrow)) {
(...skipping 11208 matching lines...) Expand 10 before | Expand all | Expand 10 after
21785 INTERFACE, 21787 INTERFACE,
21786 LIBRARY, 21788 LIBRARY,
21787 NATIVE, 21789 NATIVE,
21788 NEGATE, 21790 NEGATE,
21789 OPERATOR, 21791 OPERATOR,
21790 SET, 21792 SET,
21791 SOURCE, 21793 SOURCE,
21792 STATIC, 21794 STATIC,
21793 TYPEDEF ]*/; 21795 TYPEDEF ]*/;
21794 main(); 21796 main();
OLDNEW
« no previous file with comments | « frog/corejs.dart ('k') | tests/co19/co19-frog.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698