nativeFunctionMatcher.js (1743B)
1 // Copyright (C) 2016 Michael Ficarra. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 description: > 6 Ensure that the regular expression generally distinguishes between valid 7 and invalid forms of the NativeFunction grammar production. 8 includes: [nativeFunctionMatcher.js] 9 ---*/ 10 11 [ 12 'function(){[native code]}', 13 'function(){ [native code] }', 14 'function ( ) { [ native code ] }', 15 'function a(){ [native code] }', 16 'function a(){ /* } */ [native code] }', 17 `function a() { 18 // test 19 [native code] 20 /* test */ 21 }`, 22 'function(a, b = function() { []; }) { [native code] }', 23 'function [Symbol.xyz]() { [native code] }', 24 'function [x[y][z[d]()]]() { [native code] }', 25 'function ["]"] () { [native code] }', 26 'function [\']\'] () { [native code] }', 27 '/* test */ function() { [native code] }', 28 'function() { [native code] } /* test */', 29 'function() { [native code] } // test', 30 ].forEach((s) => { 31 try { 32 validateNativeFunctionSource(s); 33 } catch (unused) { 34 throw new Error(`${JSON.stringify(s)} should pass`); 35 } 36 }); 37 38 [ 39 'native code', 40 'function() {}', 41 'function(){ "native code" }', 42 'function(){ [] native code }', 43 'function()) { [native code] }', 44 'function(() { [native code] }', 45 'function []] () { [native code] }', 46 'function [[] () { [native code] }', 47 'function ["]] () { [native code] }', 48 'function [\']] () { [native code] }', 49 'function() { [native code] /* }', 50 '// function() { [native code] }', 51 ].forEach((s) => { 52 let fail = false; 53 try { 54 validateNativeFunctionSource(s); 55 fail = true; 56 } catch (unused) {} 57 if (fail) { 58 throw new Error(`${JSON.stringify(s)} should fail`); 59 } 60 }); 61 62 reportCompare(0, 0);