Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Override naughty AS3 methods.

  • Loading branch information...
commit 3e9688fb73c1f328e5fa56236fe2fa1dc55a6336 1 parent 80b57bc
@mbebenita mbebenita authored
View
1  examples/inspector/inspector.html
@@ -125,6 +125,7 @@
<script src="../../src/avm2/compiler/c4/backend.js"></script>
<script src="../../src/avm2/domain.js"></script>
<script src="../../src/avm2/runtime.js"></script>
+ <script src="../../src/avm2/hacks.js"></script>
<script src="../../src/avm2/xml.js"></script>
<script src="../../src/avm2/amf.js"></script>
<script src="../../src/avm2/proxy.js"></script>
View
30 src/avm2/hacks.js
@@ -0,0 +1,30 @@
+/**
+ * Random collection of Hacks to get demos work, this file should be empty.
+ */
+
+/**
+ * This sets the static string fields of the |cls| to be equal to cls.name + "." + field.name.
+ */
+VM_METHOD_OVERRIDES[
+ Multiname.getQualifiedName(Multiname.fromSimpleName("com.google.youtube.model.registerMessages"))
+] = function (cls) {
+ var className = cls.classInfo.instanceInfo.name.name;
+ cls.classInfo.traits.forEach(function (trait) {
+ if (trait.isSlot() && trait.typeName.name === "String") {
+ cls[Multiname.getQualifiedName(trait.name)] = className + "." + trait.name.name;
+ }
+ });
+ warning("HACK: registerMessages(" + className + ")");
+};
+
+VM_METHOD_OVERRIDES[
+ Multiname.getQualifiedName(Multiname.fromSimpleName("com.google.youtube.event.registerEvents"))
+] = function (cls) {
+ var className = cls.classInfo.instanceInfo.name.name;
+ cls.classInfo.traits.forEach(function (trait) {
+ if (trait.isSlot() && trait.typeName.name === "String") {
+ cls[Multiname.getQualifiedName(trait.name)] = className + "." + trait.name.name;
+ }
+ });
+ warning("HACK: registerEvents(" + className + ")");
+};
View
17 src/avm2/runtime.js
@@ -46,6 +46,11 @@ var PARAMETER_PREFIX = "p";
var $M = [];
/**
+ * Overriden AS3 methods.
+ */
+var VM_METHOD_OVERRIDES = {};
+
+/**
* 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.
*/
@@ -1010,12 +1015,12 @@ var Runtime = (function () {
var mi = methodInfo;
release || assert(!mi.isNative(), "Method should have a builtin: ", mi.name);
- if (methodInfo.name &&
- (methodInfo.name.name === "registerMessages" ||
- methodInfo.name.name === "registerEvents")) {
- return function (cls) {
- warning("Stubbed out " + methodInfo.name.name);
- };
+
+ if (methodInfo.name) {
+ var qn = Multiname.getQualifiedName(methodInfo.name);
+ if (qn in VM_METHOD_OVERRIDES) {
+ return VM_METHOD_OVERRIDES[qn];
+ }
}
var hasDefaults = false;
Please sign in to comment.
Something went wrong with that request. Please try again.