Permalink
Browse files

Very brittle Proxy support.

  • Loading branch information...
1 parent 8d6dadd commit e3031fb5233a94af6962642d2eea8a363cba55b9 @mbebenita committed Apr 6, 2013
@@ -127,6 +127,7 @@
<script src="../../src/avm2/runtime.js"></script>
<script src="../../src/avm2/xml.js"></script>
<script src="../../src/avm2/amf.js"></script>
+ <script src="../../src/avm2/proxy.js"></script>
<script src="../../src/avm2/native.js"></script>
<script src="../../src/avm2/disassembler.js"></script>
<script src="../../src/avm2/interpreter.js"></script>
@@ -68,6 +68,7 @@ load($SHUMWAY_ROOT + "src/avm2/domain.js");
load($SHUMWAY_ROOT + "src/avm2/runtime.js");
load($SHUMWAY_ROOT + "src/avm2/xml.js");
load($SHUMWAY_ROOT + "src/avm2/amf.js");
+load($SHUMWAY_ROOT + "src/avm2/proxy.js");
load($SHUMWAY_ROOT + "src/avm2/native.js");
load($SHUMWAY_ROOT + "src/avm2/disassembler.js");
load($SHUMWAY_ROOT + "src/avm2/interpreter.js");
View
@@ -81,6 +81,7 @@ load(homePath + "src/avm2/runtime.js");
load(homePath + "src/avm2/viz.js");
load(homePath + "src/avm2/interpreter.js");
load(homePath + "src/avm2/xml.js");
+load(homePath + "src/avm2/proxy.js");
load(homePath + "src/avm2/native.js");
load(homePath + "src/avm2/vm.js");
Timer.stop();
View
@@ -1231,18 +1231,6 @@ var natives = (function () {
}
/**
- * Proxy.as
- */
- function ProxyClass(runtime, scope, instance, baseClass) {
- function Proxy() {
- somewhatImplemented("Proxy");
- }
- var c = new runtime.domain.system.Class("Proxy", Proxy, C(Proxy));
- c.extendBuiltin(baseClass);
- return c;
- }
-
- /**
* ApplicationDomain.as
*/
function ApplicationDomainClass(runtime, scope, instance, baseClass) {
View
@@ -422,6 +422,7 @@ var ShumwayNamespace = (function () {
namespace.PUBLIC = new namespace(CONSTANT_Namespace);
namespace.PROTECTED = new namespace(CONSTANT_ProtectedNamespace);
+ namespace.PROXY = new namespace(CONSTANT_Namespace, "http://www.adobe.com/2006/actionscript/flash/proxy");
var simpleNameCache = {};
View
@@ -46,6 +46,26 @@ var PARAMETER_PREFIX = "p";
var $M = [];
/**
+ * This is used to keep track if we're in a runtime context. Proxies need to know
+ * if a proxied operation is triggered by AS3 code or VM code.
+ */
+
+var RUNTIME_ENTER_LEAVE_STACK = [false];
+
+function enter(runtime) {
+ RUNTIME_ENTER_LEAVE_STACK.push(runtime);
+}
+
+function leave(runtime) {
+ var top = RUNTIME_ENTER_LEAVE_STACK.pop();
+ assert (top === runtime);
+}
+
+function inRuntime() {
+ return RUNTIME_ENTER_LEAVE_STACK.top();
+}
+
+/**
* To embed object references in compiled code we index into globally accessible constant table [$C].
* This table maintains an unique set of object references, each of which holds its own position in
* the constant table, thus providing for fast lookup. We can also define constants in the JS global
@@ -546,14 +566,14 @@ function resolveMultinameInTraits(obj, mn) {
return undefined;
}
+
/**
* Resolving a multiname on an object using linear search.
*/
function resolveMultiname(obj, mn, traitsOnly) {
assert(!Multiname.isQName(mn), mn, " already resolved");
-
obj = Object(obj);
-
+ enter(true);
var publicQn;
// Check if the object that we are resolving the multiname on is a JavaScript native prototype
@@ -566,6 +586,7 @@ function resolveMultiname(obj, mn, traitsOnly) {
var qn = mn.getQName(i);
if (traitsOnly) {
if (nameInTraits(obj, Multiname.getQualifiedName(qn))) {
+ leave(true);
return qn;
}
continue;
@@ -578,14 +599,17 @@ function resolveMultiname(obj, mn, traitsOnly) {
}
} else if (!isNative) {
if (Multiname.getQualifiedName(qn) in obj) {
+ leave(true);
return qn;
}
}
}
if (publicQn && !traitsOnly && (Multiname.getQualifiedName(publicQn) in obj)) {
+ leave(true);
return publicQn;
}
+ leave(true);
return undefined;
}
@@ -621,6 +645,8 @@ function getProperty(obj, mn) {
} else {
value = obj[Multiname.getQualifiedName(resolved)];
}
+ } else {
+ value = obj[Multiname.getPublicQualifiedName(mn.name)];
}
if (tracePropertyAccess.value) {
@@ -634,6 +660,7 @@ function hasProperty(obj, mn) {
release || assert(obj !== undefined, "hasProperty(", mn, ") on undefined");
var resolved = Multiname.isQName(mn) ? mn : resolveMultiname(obj, mn);
if (!resolved) {
+ Multiname.getPublicQualifiedName(mn.name) in obj;
return false;
}
return Multiname.getQualifiedName(resolved) in obj;
@@ -1148,6 +1175,11 @@ var Runtime = (function () {
this.applyTraits(cls.instance.prototype, scope, baseBindings, ii.traits, null, true);
this.applyTraits(cls, scope, null, ci.traits, null, true);
instance = cls.instance;
+
+ if (Multiname.getQualifiedName(baseClass.classInfo.instanceInfo.name.name) === "Proxy") {
+ // TODO: This is very hackish.
+ installProxyClass(cls);
+ }
}
// Deal with the protected namespace bullshit. In AS3, if you have the following code:
View
@@ -87,6 +87,7 @@
<script src="../../src/avm2/runtime.js"></script>
<script src="../../src/avm2/xml.js"></script>
<script src="../../src/avm2/amf.js"></script>
+ <script src="../../src/avm2/proxy.js"></script>
<script src="../../src/avm2/native.js"></script>
<script src="../../src/avm2/disassembler.js"></script>
<script src="../../src/avm2/interpreter.js"></script>

2 comments on commit e3031fb

You didn't add proxy.js?

Owner

mbebenita replied Apr 6, 2013

Thx, I missed it.

Please sign in to comment.