mirror of
https://github.com/facebookarchive/prepack.git
synced 2024-11-10 14:09:42 +03:00
Memomize reference for global properties like RegExp, Symbol and Proxy
This commit is contained in:
parent
9e9525983a
commit
0275271500
@ -837,7 +837,7 @@ export class Serializer {
|
||||
let flags = val.$OriginalFlags;
|
||||
invariant(typeof source === "string");
|
||||
invariant(typeof flags === "string");
|
||||
result = t.callExpression(t.identifier("RegExp"), [t.stringLiteral(source), t.stringLiteral(flags)]);
|
||||
result = t.callExpression(this.preludeGenerator.memoizeReference("RegExp"), [t.stringLiteral(source), t.stringLiteral(flags)]);
|
||||
} else if (val.$NumberData !== undefined) {
|
||||
let num = val.$NumberData.value;
|
||||
result = t.newExpression(t.identifier("Number"), [t.numericLiteral(num)]);
|
||||
@ -850,11 +850,11 @@ export class Serializer {
|
||||
_serializeValueSymbol(val: SymbolValue): BabelNodeExpression {
|
||||
let args = [];
|
||||
if (val.$Description) args.push(t.stringLiteral(val.$Description));
|
||||
return t.callExpression(t.identifier("Symbol"), args);
|
||||
return t.callExpression(this.preludeGenerator.memoizeReference("Symbol"), args);
|
||||
}
|
||||
|
||||
_serializeValueProxy(name: string, val: ProxyValue, reasons: Array<string>): BabelNodeExpression {
|
||||
return t.newExpression(t.identifier("Proxy"), [
|
||||
return t.newExpression(this.preludeGenerator.memoizeReference("Proxy"), [
|
||||
this.serializeValue(val.$ProxyTarget, reasons.concat(`Proxy target of ${name}`)),
|
||||
this.serializeValue(val.$ProxyHandler, reasons.concat(`Proxy handler of ${name}`))
|
||||
]);
|
||||
|
7
test/serializer/basic/MemoizeGlobalPropertiesRegExp.js
Normal file
7
test/serializer/basic/MemoizeGlobalPropertiesRegExp.js
Normal file
@ -0,0 +1,7 @@
|
||||
(function() {
|
||||
let re = RegExp;
|
||||
RegExp = function() { throw new Error(); }
|
||||
RegExp = new re('ab+c');
|
||||
})();
|
||||
|
||||
inspect = function() { return RegExp; }
|
Loading…
Reference in New Issue
Block a user