From 1ad26524f5b2a8b7d087b6c092eb3ac66fd72e35 Mon Sep 17 00:00:00 2001 From: Shu-yu Guo Date: Mon, 2 Jul 2012 21:32:59 -0700 Subject: [PATCH] Remove playerglue and move ApplicationDomain into native --- src/avm2/bin/avm.js | 1 - src/avm2/native.js | 137 ++++++++++++++++++++--------------------- src/avm2/playerglue.js | 68 -------------------- 3 files changed, 68 insertions(+), 138 deletions(-) delete mode 100644 src/avm2/playerglue.js diff --git a/src/avm2/bin/avm.js b/src/avm2/bin/avm.js index cc0a0b316..a3d1f97aa 100644 --- a/src/avm2/bin/avm.js +++ b/src/avm2/bin/avm.js @@ -61,7 +61,6 @@ load("../compiler/lljs/src/escodegen.js"); load("../compiler/compiler.js"); load("../native.js"); -load("../playerglue.js"); load("../domain.js"); load("../runtime.js"); diff --git a/src/avm2/native.js b/src/avm2/native.js index 86b6af3b6..48889cd1b 100644 --- a/src/avm2/native.js +++ b/src/avm2/native.js @@ -125,10 +125,6 @@ * * return c; * }; - * - * There is an automatic convenience method |Class.lift| that takes an - * existing JavaScript constructor, clobbers its prototype, then mixes the - * original prototype back in. */ var original = {}; @@ -252,71 +248,6 @@ var Class = (function () { }; }; - /** - * Convenience functions to export all the enumerable properties of a simple - * JavaScript constructor as an AVM2 class. This clones the instance - * constructor and hooks up the prototype according to AS inheritance. - * - * Warning: language-level classes like Object, Function, etc, should not - * use this. - */ - - function exportProperties(obj, isStatic) { - var natives = {}; - var desc; - for (var prop in obj) { - if (!(desc = Object.getOwnPropertyDescriptor(obj, prop))) { - continue; - } - - var value = desc.value; - if (!desc.get && !desc.set) { - if (typeof value === "function") { - natives[prop] = value; - } else { - var access = "this." + (isStatic ? "instance." : "") + prop; - natives["get " + prop] = new Function("return " + access + ";"); - natives["set " + prop] = new Function("v", access + " = v;"); - } - } else { - if (desc.get) { - natives["get " + prop] = desc.get; - } - - if (desc.set) { - natives["set " + prop] = desc.set; - } - } - } - return natives; - } - - function mixin(into, obj) { - var desc; - for (var prop in obj) { - if (desc = Object.getOwnPropertyDescriptor(obj, prop)) { - Object.defineProperty(into, prop, desc); - } - } - } - - Class.lift = function (name, instance) { - const C = Class.passthroughCallable; - const originalProto = instance.prototype; - const nativeMethods = exportProperties(originalProto); - const nativeStatics = exportProperties(instance, true); - - // Ignore the AS constructor. - return function ClassMaker(scope, _, baseClass) { - var c = new Class(name, instance, C(instance)); - c.extend(baseClass); - mixin(c.instance.prototype, originalProto); - c.nativeMethods = nativeMethods; - c.nativeStatics = nativeStatics; - return c; - }; - }; - Class.nativeMethods = { "get prototype": function () { return this.instance.prototype; } }; @@ -345,6 +276,12 @@ var MethodClosure = (function () { const natives = (function () { + function glue(inner, proxy) { + inner.p = proxy; + proxy.d = inner; + return proxy; + } + const C = Class.passthroughCallable; const CC = Class.constructingCallable; @@ -958,6 +895,67 @@ const natives = (function () { return c; } + /** + * ApplicationDomain.as + */ + function ApplicationDomainClass(runtime, scope, instance, baseClass) { + var c = new Class("ApplicationDomain", instance, C(instance)); + c.extend(baseClass); + + c.nativeMethods = { + ctor: function (parentDomain) { + // If no parent domain is passed in, get the current system domain. + var parent; + if (!parentDomain) { + parent = Runtime.stack.top().domain; + while (parent.base) { + parent = parent.base; + } + } else { + parent = parentDomain.d; + } + + glue(new Domain(parent), this); + }, + + "get parentDomain": function () { + var base = this.d.base; + + if (!base) { + return undefined; + } + + if (base.p) { + return base.p; + } + + return glue(base, new instance()); + }, + + getDefinition: function (name) { + return this.d.getProperty(Multiname.fromSimpleName(name), false, true); + }, + + hasDefinition: function (name) { + return !!this.d.findProperty(Multiname.fromSimpleName(name), false, false); + } + }; + + c.nativeStatics = { + "get currentDomain": function () { + var domain = Runtime.stack.top().domain; + + if (domain.p) { + return domain.p; + } + + return glue(domain, new instance()); + } + }; + + return c; + } + function debugBreak(message) { // TODO: Set Breakpoint Here return message; @@ -1041,6 +1039,7 @@ const natives = (function () { RegExpClass: RegExpClass, CapabilitiesClass: CapabilitiesClass, + ApplicationDomainClass: ApplicationDomainClass, /** * DescribeType.as diff --git a/src/avm2/playerglue.js b/src/avm2/playerglue.js deleted file mode 100644 index b9015fa71..000000000 --- a/src/avm2/playerglue.js +++ /dev/null @@ -1,68 +0,0 @@ -(function () { - - function ensureGlued(inner, proxyConstructor) { - if (!inner) { - return undefined; - } - - if (inner.p) { - return inner.p; - } - - var proxy = new proxyConstructor(); - proxy.d = inner; - inner.p = proxy; - return proxy; - } - - const C = Class.passthroughCallable; - const CC = Class.constructingCallable; - - /** - * ApplicationDomain.as - */ - function ApplicationDomainClass(runtime, scope, instance, baseClass) { - var c = new Class("ApplicationDomain", instance, C(instance)); - c.extend(baseClass); - - c.nativeMethods = { - ctor: function (parentDomain) { - // If no parent domain is passed in, get the current system domain. - var parent; - if (!parentDomain) { - parent = Runtime.stack.top().domain; - while (parent.base) { - parent = parent.base; - } - } else { - parent = parentDomain.d; - } - - this.d = new Domain(parent); - }, - - "get parentDomain": function () { - return ensureGlued(this.d.base, ApplicationDomain); - }, - - getDefinition: function (name) { - return this.d.getProperty(Multiname.fromSimpleName(name), false, true); - }, - - hasDefinition: function (name) { - return !!this.d.findProperty(Multiname.fromSimpleName(name), false, false); - } - }; - - c.nativeStatics = { - "get currentDomain": function () { - return ensureGlued(Runtime.stack.top().domain, ApplicationDomain); - } - }; - - return c; - } - - natives.ApplicationDomainClass = ApplicationDomainClass; - -})();