Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 // TODO(jimhug): Completeness - see tests/corelib | 5 // TODO(jimhug): Completeness - see tests/corelib |
| 6 | 6 |
| 7 /** Implements extends for dart classes on javascript prototypes. */ | 7 /** Implements extends for dart classes on javascript prototypes. */ |
| 8 function $inherits(child, parent) { | 8 function $inherits(child, parent) { |
| 9 if (child.prototype.__proto__) { | 9 if (child.prototype.__proto__) { |
| 10 child.prototype.__proto__ = parent.prototype; | 10 child.prototype.__proto__ = parent.prototype; |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 ret.$setindex(items[i++], items[i++]); | 167 ret.$setindex(items[i++], items[i++]); |
| 168 } | 168 } |
| 169 return ret; | 169 return ret; |
| 170 } | 170 } |
| 171 | 171 |
| 172 function $assert(test, text, url, line, column) { | 172 function $assert(test, text, url, line, column) { |
| 173 if (typeof test == 'function') test = test(); | 173 if (typeof test == 'function') test = test(); |
| 174 if (!test) $throw(new AssertError(text, url, line, column)); | 174 if (!test) $throw(new AssertError(text, url, line, column)); |
| 175 } | 175 } |
| 176 | 176 |
| 177 function $notnull_bool(test) { | |
| 178 if (test == null || typeof(test) != 'boolean') { | |
| 179 $throw(new TypeError('must be "true" or "false"')); | |
| 180 } | |
| 181 return test === true; | |
|
jimhug
2011/11/07 16:41:26
I wonder if this would be better?
(possibly inlin
Jennifer Messerly
2011/11/08 03:56:16
I was mostly trying to keep checked mode relativel
| |
| 182 } | |
| 183 | |
| 177 function $throw(e) { | 184 function $throw(e) { |
| 178 // If e is not a value, we can use V8's captureStackTrace utility method. | 185 // If e is not a value, we can use V8's captureStackTrace utility method. |
| 179 // TODO(jmesserly): capture the stack trace on other JS engines. | 186 // TODO(jmesserly): capture the stack trace on other JS engines. |
| 180 if (e && (typeof e == "object") && Error.captureStackTrace) { | 187 if (e && (typeof e == "object") && Error.captureStackTrace) { |
| 181 // TODO(jmesserly): this will clobber the e.stack property | 188 // TODO(jmesserly): this will clobber the e.stack property |
| 182 Error.captureStackTrace(e, $throw); | 189 Error.captureStackTrace(e, $throw); |
| 183 } | 190 } |
| 184 throw e; | 191 throw e; |
| 185 } | 192 } |
| 186 | 193 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 322 // Get the prototype to patch. | 329 // Get the prototype to patch. |
| 323 // Don't overwrite an existing stub, like the one on Object.prototype | 330 // Don't overwrite an existing stub, like the one on Object.prototype |
| 324 var proto = Object.getPrototypeOf(obj); | 331 var proto = Object.getPrototypeOf(obj); |
| 325 if (!proto || proto.hasOwnProperty(name)) proto = obj; | 332 if (!proto || proto.hasOwnProperty(name)) proto = obj; |
| 326 var method; | 333 var method; |
| 327 while (obj && !(method = methods[obj.get$typeName()])) { | 334 while (obj && !(method = methods[obj.get$typeName()])) { |
| 328 obj = Object.getPrototypeOf(obj); | 335 obj = Object.getPrototypeOf(obj); |
| 329 } | 336 } |
| 330 Object.defineProperty(proto, name, {value: method || methods['Object']}); | 337 Object.defineProperty(proto, name, {value: method || methods['Object']}); |
| 331 } | 338 } |
| OLD | NEW |