Add delete opcode (#869)

This commit is contained in:
jberg 2019-08-19 14:43:06 -07:00 committed by GitHub
parent 59689fa827
commit ceb85fa4be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View file

@ -323,6 +323,12 @@ export function* interpret(start, program, stack = []) {
stack.push(klassInst);
break;
}
// delete
case 97: {
const aValue = popStackValue();
aValue.js_delete();
break;
}
default:
throw new Error(`Unhandled opcode ${command.opcode}`);
}

View file

@ -34,6 +34,11 @@ class MakiObject {
this.children = this.children.filter(item => item !== child);
}
js_delete() {
this.parent.js_removeChild(this);
this.parent.js_trigger("js_update");
}
js_trigger(eventName, ...args) {
this._emitter.trigger(eventName.toLowerCase(), ...args);
}