Skip to content

Commit 3f51274

Browse files
committed
Simplify stack overflow test case by removing unrelated functions from php.js
1 parent de0b3ad commit 3f51274

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

tests/jsroot/ExactKeysUnitTest.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

22
let php = require('./../unv/grect/backend/Transpiled/php.js');
3+
let php2 = require('../php.js');
34
const ApoPnrParser = require("../unv/grect/backend/Transpiled/Gds/Parsers/Apollo/Pnr/PnrParser");
45
const SabPnrParser = require("../unv/grect/backend/Transpiled/Gds/Parsers/Sabre/Pnr/PnrParser");
56
const AmaPnrParser = require("../unv/grect/backend/Transpiled/Gds/Parsers/Amadeus/Pnr/PnrParser");
67
const GalPnrParser = require("../unv/grect/backend/Transpiled/Gds/Parsers/Galileo/Pnr/PnrParser");
7-
const Fp = require('../unv/grect/backend/Transpiled/Lib/Utils/Fp.js');
88

99
exports.provideAsyncPromise = async () => {
1010
return Promise.resolve({
@@ -46,6 +46,13 @@ exports.provideParseGalPnr = () => {
4646
return parsed;
4747
};
4848

49+
50+
class Fp {
51+
static map($function, $arr) {
52+
return php2.array_map($function, $arr);
53+
}
54+
}
55+
4956
exports.provideFfInfoStackOverflow = () => {
5057
// taken from Sabre PNR parser
5158
let $result, $sections;

tests/php.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
let php = {};
3+
4+
php.array_combine = (keys, values) => {
5+
keys = Object.values(keys);
6+
values = Object.values(values);
7+
if (keys.length !== values.length) {
8+
throw new Error('array_combine passed key count ' + keys.length +
9+
' does not match value count ' + values.length);
10+
}
11+
let result = {};
12+
for (let i = 0; i < keys.length; ++i) {
13+
result[keys[i]] = values[i];
14+
}
15+
return result;
16+
};
17+
18+
let normFunc = (func) => {
19+
if (typeof func === 'string') {
20+
if (func in php) {
21+
func = php[func];
22+
} else {
23+
throw Error('Unsupported built-in function - ' + func);
24+
}
25+
}
26+
return func;
27+
};
28+
php.array_map = (func, obj, additionalValues = []) => {
29+
func = normFunc(func);
30+
let newObj = Array.isArray(obj) ? [] : {};
31+
for (let [key, val] of Object.entries(obj)) {
32+
newObj[key] = func(val, additionalValues[key]);
33+
}
34+
return newObj;
35+
};
36+
37+
module.exports = php;

0 commit comments

Comments
 (0)