| OLD | NEW |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 // Assert that the function code is (not) optimized. If "no sync" is passed | 110 // Assert that the function code is (not) optimized. If "no sync" is passed |
| 111 // as second argument, we do not wait for the concurrent optimization thread to | 111 // as second argument, we do not wait for the concurrent optimization thread to |
| 112 // finish when polling for optimization status. | 112 // finish when polling for optimization status. |
| 113 // Only works with --allow-natives-syntax. | 113 // Only works with --allow-natives-syntax. |
| 114 var assertOptimized; | 114 var assertOptimized; |
| 115 var assertUnoptimized; | 115 var assertUnoptimized; |
| 116 | 116 |
| 117 // Assert that a string contains another expected substring. | 117 // Assert that a string contains another expected substring. |
| 118 var assertContains; | 118 var assertContains; |
| 119 | 119 |
| 120 // Assert that a string matches a given regex. |
| 121 var assertMatches; |
| 122 |
| 120 | 123 |
| 121 (function () { // Scope for utility functions. | 124 (function () { // Scope for utility functions. |
| 122 | 125 |
| 123 var ObjectPrototypeToString = Object.prototype.toString; | 126 var ObjectPrototypeToString = Object.prototype.toString; |
| 124 var NumberPrototypeValueOf = Number.prototype.valueOf; | 127 var NumberPrototypeValueOf = Number.prototype.valueOf; |
| 125 var BooleanPrototypeValueOf = Boolean.prototype.valueOf; | 128 var BooleanPrototypeValueOf = Boolean.prototype.valueOf; |
| 126 var StringPrototypeValueOf = String.prototype.valueOf; | 129 var StringPrototypeValueOf = String.prototype.valueOf; |
| 127 var DatePrototypeValueOf = Date.prototype.valueOf; | 130 var DatePrototypeValueOf = Date.prototype.valueOf; |
| 128 var RegExpPrototypeToString = RegExp.prototype.toString; | 131 var RegExpPrototypeToString = RegExp.prototype.toString; |
| 129 var ArrayPrototypeMap = Array.prototype.map; | 132 var ArrayPrototypeMap = Array.prototype.map; |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 } | 421 } |
| 419 throw new MjsUnitAssertionError(message); | 422 throw new MjsUnitAssertionError(message); |
| 420 }; | 423 }; |
| 421 | 424 |
| 422 assertContains = function(sub, value, name_opt) { | 425 assertContains = function(sub, value, name_opt) { |
| 423 if (value == null ? (sub != null) : value.indexOf(sub) == -1) { | 426 if (value == null ? (sub != null) : value.indexOf(sub) == -1) { |
| 424 fail("contains '" + String(sub) + "'", value, name_opt); | 427 fail("contains '" + String(sub) + "'", value, name_opt); |
| 425 } | 428 } |
| 426 }; | 429 }; |
| 427 | 430 |
| 431 assertMatches = function(regexp, str, name_opt) { |
| 432 if (!(regexp instanceof RegExp)) { |
| 433 regexp = new RegExp(regexp); |
| 434 } |
| 435 if (!str.match(regexp)) { |
| 436 fail("should match '" + regexp + "'", str, name_opt); |
| 437 } |
| 438 }; |
| 439 |
| 428 var OptimizationStatusImpl = undefined; | 440 var OptimizationStatusImpl = undefined; |
| 429 | 441 |
| 430 var OptimizationStatus = function(fun, sync_opt) { | 442 var OptimizationStatus = function(fun, sync_opt) { |
| 431 if (OptimizationStatusImpl === undefined) { | 443 if (OptimizationStatusImpl === undefined) { |
| 432 try { | 444 try { |
| 433 OptimizationStatusImpl = new Function( | 445 OptimizationStatusImpl = new Function( |
| 434 "fun", "sync", "return %GetOptimizationStatus(fun, sync);"); | 446 "fun", "sync", "return %GetOptimizationStatus(fun, sync);"); |
| 435 } catch (e) { | 447 } catch (e) { |
| 436 throw new Error("natives syntax not allowed"); | 448 throw new Error("natives syntax not allowed"); |
| 437 } | 449 } |
| 438 } | 450 } |
| 439 return OptimizationStatusImpl(fun, sync_opt); | 451 return OptimizationStatusImpl(fun, sync_opt); |
| 440 } | 452 } |
| 441 | 453 |
| 442 assertUnoptimized = function assertUnoptimized(fun, sync_opt, name_opt) { | 454 assertUnoptimized = function assertUnoptimized(fun, sync_opt, name_opt) { |
| 443 if (sync_opt === undefined) sync_opt = ""; | 455 if (sync_opt === undefined) sync_opt = ""; |
| 444 assertTrue(OptimizationStatus(fun, sync_opt) !== 1, name_opt); | 456 assertTrue(OptimizationStatus(fun, sync_opt) !== 1, name_opt); |
| 445 } | 457 } |
| 446 | 458 |
| 447 assertOptimized = function assertOptimized(fun, sync_opt, name_opt) { | 459 assertOptimized = function assertOptimized(fun, sync_opt, name_opt) { |
| 448 if (sync_opt === undefined) sync_opt = ""; | 460 if (sync_opt === undefined) sync_opt = ""; |
| 449 assertTrue(OptimizationStatus(fun, sync_opt) !== 2, name_opt); | 461 assertTrue(OptimizationStatus(fun, sync_opt) !== 2, name_opt); |
| 450 } | 462 } |
| 451 | 463 |
| 452 })(); | 464 })(); |
| OLD | NEW |