feat: delete
This commit is contained in:
parent
62eaa16b28
commit
443797017f
|
@ -150,7 +150,6 @@ export default class Sandbox {
|
||||||
case 'ObjectExpression':
|
case 'ObjectExpression':
|
||||||
case 'Identifier':
|
case 'Identifier':
|
||||||
case 'MemberExpression':
|
case 'MemberExpression':
|
||||||
case 'UnaryExpression':
|
|
||||||
case 'UpdateExpression': {
|
case 'UpdateExpression': {
|
||||||
result = this.evaluateToResult(node);
|
result = this.evaluateToResult(node);
|
||||||
if (result.yield) {
|
if (result.yield) {
|
||||||
|
@ -523,6 +522,31 @@ export default class Sandbox {
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 'UnaryExpression': {
|
||||||
|
if ('delete' === node.operator) {
|
||||||
|
let property;
|
||||||
|
if (node.argument.computed) {
|
||||||
|
property = this.executeSync(node.argument.property, depth + 1);
|
||||||
|
if (property.yield) {
|
||||||
|
return property;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
property = {value: node.argument.property.name, yield: YIELD_NONE};
|
||||||
|
}
|
||||||
|
const scope = this.scopes.get(node);
|
||||||
|
const object = scope.get(node.argument.object.name, undefined);
|
||||||
|
delete object[property.value];
|
||||||
|
result = {value: true, yield: YIELD_NONE};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
result = this.evaluateToResult(node);
|
||||||
|
if (result.yield) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case 'VariableDeclaration': {
|
case 'VariableDeclaration': {
|
||||||
let skipping = isReplaying;
|
let skipping = isReplaying;
|
||||||
for (const child of node.declarations) {
|
for (const child of node.declarations) {
|
||||||
|
|
|
@ -121,6 +121,36 @@ test('runs arbitrary number of ops', async () => {
|
||||||
.to.equal(150);
|
.to.equal(150);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('deletes', async () => {
|
||||||
|
const sandbox = new Sandbox(
|
||||||
|
await parse(`
|
||||||
|
delete foo.one;
|
||||||
|
delete foo['two'];
|
||||||
|
const x = 'three';
|
||||||
|
delete foo[x];
|
||||||
|
const y = 'four';
|
||||||
|
delete foo[await y];
|
||||||
|
`),
|
||||||
|
{
|
||||||
|
foo: {
|
||||||
|
one: 1,
|
||||||
|
two: 2,
|
||||||
|
three: 3,
|
||||||
|
four: 4,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
await finish(sandbox);
|
||||||
|
expect(sandbox.context.foo.one)
|
||||||
|
.to.be.undefined;
|
||||||
|
expect(sandbox.context.foo.two)
|
||||||
|
.to.be.undefined;
|
||||||
|
expect(sandbox.context.foo.three)
|
||||||
|
.to.be.undefined;
|
||||||
|
expect(sandbox.context.foo.four)
|
||||||
|
.to.be.undefined;
|
||||||
|
});
|
||||||
|
|
||||||
test('evaluates conditional branches', async () => {
|
test('evaluates conditional branches', async () => {
|
||||||
const sandbox = new Sandbox(
|
const sandbox = new Sandbox(
|
||||||
await parse(`
|
await parse(`
|
||||||
|
|
Loading…
Reference in New Issue
Block a user