Skip to content

Instantly share code, notes, and snippets.

@syg
Created September 26, 2012 20:07
Show Gist options
  • Save syg/3790265 to your computer and use it in GitHub Desktop.
Save syg/3790265 to your computer and use it in GitHub Desktop.
["Test"].forEach(function makeStub(className) {
const global = this;
global[className] = function () {
if (!avm2) {
throw new Error("AVM2 not initialized");
}
var c = avm2.systemDomain.getClass(className);
assert(c.instance);
global[className] = c.instance;
return c.createInstance.apply(c, arguments);
};
});
var TestImpl = {
initialize: function (x) {
print("native constructor");
this.x_ = x;
},
getX: function() {
return this.x_;
}
};
natives.TestClass = function TestClass(runtime, scope, instance, baseClass) {
function TestInstance() {
this.initialize(arguments[0]);
instance.apply(this, arguments);
}
var c = new runtime.domain.system.Class("Test", TestInstance);
c.extend(baseClass);
c.mixin(TestImpl);
c.nativeStatics = {
spawn: function (arg) {
var o = new Test(arg);
print(o.getX());
return o;
}
};
c.nativeMethods = {
"get x": TestImpl.getX
};
return c;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment