From 83ffb4bbf2a7a2f68075c8e611525b55ea5cfecc Mon Sep 17 00:00:00 2001 From: Michael Ficarra Date: Tue, 6 Mar 2018 18:18:00 -0800 Subject: allow any function to report its toString as a NativeFunction related: https://github.com/tc39/Function-prototype-toString-revision/pull/26 --- harness/nativeFunctionMatcher.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'harness') diff --git a/harness/nativeFunctionMatcher.js b/harness/nativeFunctionMatcher.js index 0a2d248a3..52120ea48 100644 --- a/harness/nativeFunctionMatcher.js +++ b/harness/nativeFunctionMatcher.js @@ -6,3 +6,17 @@ description: | the NativeFunction grammar production without requiring a correct tokeniser. ---*/ const NATIVE_FUNCTION_RE = /\bfunction\b[\s\S]*\([\s\S]*\)[\s\S]*\{[\s\S]*\[[\s\S]*\bnative\b[\s\S]+\bcode\b[\s\S]*\][\s\S]*\}/; + +const assertToStringOrNativeFunction = function(fn, expected) { + const actual = "" + fn; + try { + assert.sameValue(actual, expected); + } catch (unused) { + assertNativeFunction(fn); + } +}; + +const assertNativeFunction = function(fn) { + const actual = "" + fn; + assert(NATIVE_FUNCTION_RE.test(actual), "looks pretty much like a NativeFunction"); +}; -- cgit v1.2.1