2018-06-25 16:30:11 +02:00
|
|
|
// Copyright (C) 2016 Michael Ficarra. All rights reserved.
|
2017-07-14 17:37:24 +02:00
|
|
|
// This code is governed by the BSD license found in the LICENSE file.
|
|
|
|
/*---
|
2018-04-19 22:44:52 +02:00
|
|
|
description: Assert _NativeFunction_ Syntax
|
|
|
|
info: |
|
2017-07-14 17:37:24 +02:00
|
|
|
This regex makes a best-effort determination that the tested string matches
|
|
|
|
the NativeFunction grammar production without requiring a correct tokeniser.
|
2018-04-19 22:44:52 +02:00
|
|
|
|
|
|
|
NativeFunction :
|
|
|
|
function _IdentifierName_ opt ( _FormalParameters_ ) { [ native code ] }
|
|
|
|
|
2017-07-14 17:37:24 +02:00
|
|
|
---*/
|
2016-04-21 21:55:54 +02:00
|
|
|
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]*\}/;
|
2018-03-07 03:18:00 +01:00
|
|
|
|
|
|
|
const assertToStringOrNativeFunction = function(fn, expected) {
|
|
|
|
const actual = "" + fn;
|
|
|
|
try {
|
|
|
|
assert.sameValue(actual, expected);
|
|
|
|
} catch (unused) {
|
2018-04-19 22:44:52 +02:00
|
|
|
assertNativeFunction(fn, expected);
|
2018-03-07 03:18:00 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-04-19 22:44:52 +02:00
|
|
|
const assertNativeFunction = function(fn, special) {
|
2018-03-07 03:18:00 +01:00
|
|
|
const actual = "" + fn;
|
2018-04-19 22:44:52 +02:00
|
|
|
assert(
|
|
|
|
NATIVE_FUNCTION_RE.test(actual),
|
|
|
|
"Conforms to NativeFunction Syntax: '" + actual + "'." + (special ? "(" + special + ")" : "")
|
|
|
|
);
|
2018-03-07 03:18:00 +01:00
|
|
|
};
|