Skip to content

Commit

Permalink
Smaller imrovements
Browse files Browse the repository at this point in the history
  • Loading branch information
XmiliaH committed Feb 24, 2022
1 parent 9bc1baa commit 48a93e5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
3 changes: 2 additions & 1 deletion lib/setup-sandbox.js
Expand Up @@ -308,7 +308,8 @@ const withProxy = localObjectFreeze({
const interanState = localObjectFreeze({
__proto__: null,
wrapWith(x) {
return new LocalProxy(x, withProxy);
if (x === null || x === undefined) return x;
return new LocalProxy(localObject(x), withProxy);
},
handleException: ensureThis,
import(what) {
Expand Down
17 changes: 10 additions & 7 deletions lib/transformer.js
Expand Up @@ -16,7 +16,7 @@ function makeNiceSyntaxError(message, code, filename, location, tokenizer) {
while (end < code.length && !acornIsNewLine(code.charCodeAt(end))) {
end++;
}
let markerEnd = tokenizer.end;
let markerEnd = tokenizer.start === location ? tokenizer.end : location + 1;
if (!markerEnd || markerEnd > end) markerEnd = end;
let markerLen = markerEnd - location;
if (markerLen <= 0) markerLen = 1;
Expand Down Expand Up @@ -101,7 +101,11 @@ function transformer(args, body, isAsync, isGenerator, filename) {
let internStateValiable = undefined;

acornWalkFull(ast, (node, state, type) => {
if (type === 'CatchClause') {
if (type === 'Function') {
if (node.async) hasAsync = true;
}
const nodeType = node.type;
if (nodeType === 'CatchClause') {
const param = node.param;
if (param) {
const name = assertType(param, 'Identifier').name;
Expand All @@ -115,7 +119,7 @@ function transformer(args, body, isAsync, isGenerator, filename) {
});
}
}
} else if (type === 'WithStatement') {
} else if (nodeType === 'WithStatement') {
insertions.push({
__proto__: null,
pos: node.object.start,
Expand All @@ -128,27 +132,26 @@ function transformer(args, body, isAsync, isGenerator, filename) {
order: TO_RIGHT,
code: ')'
});
} else if (type === 'Identifier') {
} else if (nodeType === 'Identifier') {
if (node.name === INTERNAL_STATE_NAME) {
if (internStateValiable === undefined || internStateValiable.start > node.start) {
internStateValiable = node;
}
}
} else if (type === 'ImportExpression') {
} else if (nodeType === 'ImportExpression') {
insertions.push({
__proto__: null,
pos: node.start,
order: TO_RIGHT,
code: INTERNAL_STATE_NAME + '.'
});
} else if (type === 'Function') {
if (node.async) hasAsync = true;
}
});

if (internStateValiable) {
throw makeNiceSyntaxError('Use of internal vm2 state variable', code, filename, internStateValiable.start, {
__proto__: null,
start: internStateValiable.start,
end: internStateValiable.end
});
}
Expand Down

0 comments on commit 48a93e5

Please sign in to comment.