mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 590036 - Optimize cases where we probably eval an array, that would be parsable by JSON. r=jorendorff a=SpiderMonkey
This commit is contained in:
parent
fca18ee593
commit
3facd97a02
13
js/src/jit-test/tests/basic/bug590036.js
Normal file
13
js/src/jit-test/tests/basic/bug590036.js
Normal file
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/licenses/publicdomain/
|
||||
*/
|
||||
|
||||
load(libdir + 'eqArrayHelper.js');
|
||||
|
||||
assertEqArray(eval('[]'), []);
|
||||
assertEqArray(eval('[,]'), [,]);
|
||||
assertEqArray(eval('[,,]'), [,,]);
|
||||
assertEqArray(eval('[1, 1, ]'), [1,1, ]);
|
||||
assertEqArray(eval('[1, 1, true]'), [1, 1, true]);
|
||||
assertEqArray(eval('[1, false, true]'), [1, false, true]);
|
@ -1191,7 +1191,7 @@ EvalKernel(JSContext *cx, const CallArgs &args, EvalType evalType, StackFrame *c
|
||||
size_t length = linearStr->length();
|
||||
|
||||
/*
|
||||
* If the eval string starts with '(' and ends with ')', it may be JSON.
|
||||
* If the eval string starts with '(' or '[' and ends with ')' or ']', it may be JSON.
|
||||
* Try the JSON parser first because it's much faster. If the eval string
|
||||
* isn't JSON, JSON parsing will probably fail quickly, so little time
|
||||
* will be lost.
|
||||
@ -1202,7 +1202,8 @@ EvalKernel(JSContext *cx, const CallArgs &args, EvalType evalType, StackFrame *c
|
||||
* JSON with eval and using strict mode, you deserve to be slow.
|
||||
*/
|
||||
if (length > 2 &&
|
||||
chars[0] == '(' && chars[length - 1] == ')' &&
|
||||
((chars[0] == '[' && chars[length - 1] == ']') ||
|
||||
(chars[0] == '(' && chars[length - 1] == ')')) &&
|
||||
(!caller || !caller->script()->strictModeCode))
|
||||
{
|
||||
/*
|
||||
@ -1218,7 +1219,8 @@ EvalKernel(JSContext *cx, const CallArgs &args, EvalType evalType, StackFrame *c
|
||||
break;
|
||||
|
||||
if (cp == end) {
|
||||
JSONParser parser(cx, chars + 1, length - 2,
|
||||
bool isArray = (chars[0] == '[');
|
||||
JSONParser parser(cx, isArray ? chars : chars + 1, isArray ? length : length - 2,
|
||||
JSONParser::StrictJSON, JSONParser::NoError);
|
||||
Value tmp;
|
||||
if (!parser.parse(&tmp))
|
||||
|
Loading…
Reference in New Issue
Block a user