Skip to content

Instantly share code, notes, and snippets.

@syg
Created September 26, 2012 20:02
Show Gist options
  • Save syg/3790232 to your computer and use it in GitHub Desktop.
Save syg/3790232 to your computer and use it in GitHub Desktop.
diff --git a/src/avm2/bin/avm.js b/src/avm2/bin/avm.js
index 7a448a0..a9f2a59 100644
--- a/src/avm2/bin/avm.js
+++ b/src/avm2/bin/avm.js
@@ -53,6 +53,9 @@ load("../viz.js");
load("../interpreter.js");
load("../native.js");
load("../vm.js");
+
+load("../../glue/test/stubs.js");
+load("../../glue/test/test.js");
Timer.stop();
argumentParser.addBoundOptionSet(systemOptions);
@@ -90,18 +93,19 @@ function grabABC(abcname) {
return new AbcFile(stream, filename);
}
-var vm;
+var avm2;
if (execute.value) {
var sysMode = alwaysInterpret.value ? EXECUTION_MODE.INTERPRET : (compileSys.value ? null : EXECUTION_MODE.INTERPRET);
var appMode = alwaysInterpret.value ? EXECUTION_MODE.INTERPRET : null;
- vm = new AVM2(sysMode, appMode);
+ avm2 = new AVM2(sysMode, appMode);
Timer.start("Initialize");
- vm.systemDomain.executeAbc(grabABC("builtin"));
- vm.systemDomain.executeAbc(grabABC("shell"));
- vm.systemDomain.installNative("getArgv", function() {
+ avm2.systemDomain.executeAbc(grabABC("builtin"));
+ avm2.systemDomain.executeAbc(grabABC("shell"));
+ avm2.systemDomain.executeAbc(grabABC("test"));
+ avm2.systemDomain.installNative("getArgv", function() {
return argv;
});
- vm.systemDomain.executeAbc(grabABC("avmplus"));
+ avm2.systemDomain.executeAbc(grabABC("avmplus"));
Timer.stop();
}
@@ -116,7 +120,7 @@ if (file.value.endsWith(".swf")) {
} else if (tag.type === "symbols") {
for (var j = tag.references.length - 1; j >= 0; j--) {
if (tag.references[j].id === 0) {
- vm.applicationDomain.getProperty(
+ avm2.applicationDomain.getProperty(
Multiname.fromSimpleName(tag.references[j].name),
true, true
);
@@ -156,9 +160,9 @@ function processAbc(abc) {
}
if (execute.value) {
- assert(vm);
+ assert(avm2);
try {
- vm.applicationDomain.executeAbc(abc);
+ avm2.applicationDomain.executeAbc(abc);
} catch(e) {
print(e);
print("");
diff --git a/src/avm2/bin/shu.py b/src/avm2/bin/shu.py
index 382cd8f..03fe304 100755
--- a/src/avm2/bin/shu.py
+++ b/src/avm2/bin/shu.py
@@ -156,6 +156,8 @@ class Base:
if _global:
args.extend(["-import", self.global_abc])
+ args.extend(["-import", "../generated/test/test.abc"])
+
if playerGlobal:
playerGlobalAbcs = []
if not os.path.isdir(self.player_global_abc):
diff --git a/src/avm2/domain.js b/src/avm2/domain.js
index e57d0d7..bc7a8d1 100644
--- a/src/avm2/domain.js
+++ b/src/avm2/domain.js
@@ -86,14 +86,29 @@ var Domain = (function () {
defineNonEnumerableProperty(this.dynamicPrototype, "public$constructor", this);
},
- extend: function (baseClass, dynamicPrototype) {
+ extend: function (baseClass) {
this.baseClass = baseClass;
- this.dynamicPrototype = dynamicPrototype || Object.create(baseClass.dynamicPrototype);
+ this.dynamicPrototype = Object.create(baseClass.dynamicPrototype);
this.instance.prototype = Object.create(this.dynamicPrototype);
defineNonEnumerableProperty(this.dynamicPrototype, "public$constructor", this);
defineReadOnlyProperty(this.instance.prototype, "class", this);
},
+ mixin: function (impl) {
+ assert(this.dynamicPrototype);
+
+ // The implementation must have at least an initialize function.
+ assert(typeof impl.initialize === "function");
+
+ var dynamicProto = this.dynamicPrototype;
+ for (var p in impl) {
+ var desc = Object.getOwnPropertyDescriptor(impl, p);
+ if (desc) {
+ Object.defineProperty(dynamicProto, p, desc);
+ }
+ }
+ },
+
extendNative: function (baseClass, native) {
this.baseClass = baseClass;
this.dynamicPrototype = Object.getPrototypeOf(native.prototype);
diff --git a/src/avm2/generated/generate.py b/src/avm2/generated/generate.py
index df8ff69..f00fdf5 100755
--- a/src/avm2/generated/generate.py
+++ b/src/avm2/generated/generate.py
@@ -61,9 +61,10 @@ def main():
# Build without float suppot by default
configs = ['-config', 'CONFIG::VMCFG_FLOAT=false']
- compile_abc("builtin", ["builtin.as", "Math.as", "Error.as", "Date.as", "RegExp.as", "IDataInput.as", "IDataOutput.as", "ByteArray.as"], configs=configs)
- compile_abc("shell", ["Capabilities.as"], deps=["builtin"], configs=configs)
- compile_abc("avmplus", ["avmplus.as"], deps=["builtin"], configs=configs)
+ #compile_abc("builtin", ["builtin.as", "Math.as", "Error.as", "Date.as", "RegExp.as", "IDataInput.as", "IDataOutput.as", "ByteArray.as"], configs=configs)
+ #compile_abc("shell", ["Capabilities.as"], deps=["builtin"], configs=configs)
+ #compile_abc("avmplus", ["avmplus.as"], deps=["builtin"], configs=configs)
+ compile_abc("test", ["Test.as"], deps=["builtin"], configs=configs)
if __name__ == "__main__":
main()
diff --git a/src/avm2/vm.js b/src/avm2/vm.js
index c01a34f..500df48 100644
--- a/src/avm2/vm.js
+++ b/src/avm2/vm.js
@@ -9,14 +9,6 @@ var AVM2 = (function () {
this.onConstruct = undefined;
}
- /**
- * Returns the current VM context. This can be used to find out the VM execution context
- * when running in native code.
- */
- AVM2.currentVM = function () {
- return Runtime.stack.top().domain.system.vm;
- };
-
AVM2.prototype = {
notifyConstruct: function notifyConstruct (instance, args) {
return this.onConstruct ? this.onConstruct(instance, args) : undefined;
diff --git a/src/glue/avm2/flash.js b/src/glue/avm2/flash.js
index b5c5a97..618c8f3 100644
--- a/src/glue/avm2/flash.js
+++ b/src/glue/avm2/flash.js
@@ -1,3 +1,6 @@
+// The cached instance of AVM2.
+var avm2;
+
var BinaryFileReader = (function binaryFileReader() {
function constructor(url, responseType) {
this.url = url;
@@ -37,16 +40,17 @@ var BinaryFileReader = (function binaryFileReader() {
*/
function createAVM2(builtinPath, libraryPath, sysMode, appMode, next) {
assert (builtinPath);
+ assert (!avm2);
new BinaryFileReader(builtinPath).readAll(null, function (buffer) {
- var vm = new AVM2(sysMode, appMode);
- vm.systemDomain.executeAbc(new AbcFile(new Uint8Array(buffer), "builtin.abc"));
+ avm2 = new AVM2(sysMode, appMode);
+ avm2.systemDomain.executeAbc(new AbcFile(new Uint8Array(buffer), "builtin.abc"));
if (libraryPath) {
new BinaryFileReader(libraryPath).readAll(null, function (buffer) {
- vm.systemDomain.executeAbc(new AbcFile(new Uint8Array(buffer), libraryPath));
- next(vm);
+ avm2.systemDomain.executeAbc(new AbcFile(new Uint8Array(buffer), libraryPath));
+ next(avm2);
});
} else {
- next(vm);
+ next(avm2);
}
});
}
@@ -59,9 +63,9 @@ function createAVM2(builtinPath, libraryPath, sysMode, appMode, next) {
*/
function bindNativeObjectUsingAvm2(vm, obj) {
var scriptClass = vm.applicationDomain.getProperty(
- Multiname.fromSimpleName('public ' + obj.__class__),
+ Multiname.fromSimpleName(obj.__class__),
true,
true
);
return scriptClass.createInstanceWithBoundNative(obj, true);
-}
\ No newline at end of file
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment