Skip to content
This repository
Browse code

Override naughty AS3 methods.

  • Loading branch information...
commit 3e9688fb73c1f328e5fa56236fe2fa1dc55a6336 1 parent 80b57bc
Michael Bebenita mbebenita authored
1  examples/inspector/inspector.html
@@ -125,6 +125,7 @@
125 125 <script src="../../src/avm2/compiler/c4/backend.js"></script>
126 126 <script src="../../src/avm2/domain.js"></script>
127 127 <script src="../../src/avm2/runtime.js"></script>
  128 + <script src="../../src/avm2/hacks.js"></script>
128 129 <script src="../../src/avm2/xml.js"></script>
129 130 <script src="../../src/avm2/amf.js"></script>
130 131 <script src="../../src/avm2/proxy.js"></script>
30 src/avm2/hacks.js
... ... @@ -0,0 +1,30 @@
  1 +/**
  2 + * Random collection of Hacks to get demos work, this file should be empty.
  3 + */
  4 +
  5 +/**
  6 + * This sets the static string fields of the |cls| to be equal to cls.name + "." + field.name.
  7 + */
  8 +VM_METHOD_OVERRIDES[
  9 + Multiname.getQualifiedName(Multiname.fromSimpleName("com.google.youtube.model.registerMessages"))
  10 +] = function (cls) {
  11 + var className = cls.classInfo.instanceInfo.name.name;
  12 + cls.classInfo.traits.forEach(function (trait) {
  13 + if (trait.isSlot() && trait.typeName.name === "String") {
  14 + cls[Multiname.getQualifiedName(trait.name)] = className + "." + trait.name.name;
  15 + }
  16 + });
  17 + warning("HACK: registerMessages(" + className + ")");
  18 +};
  19 +
  20 +VM_METHOD_OVERRIDES[
  21 + Multiname.getQualifiedName(Multiname.fromSimpleName("com.google.youtube.event.registerEvents"))
  22 +] = function (cls) {
  23 + var className = cls.classInfo.instanceInfo.name.name;
  24 + cls.classInfo.traits.forEach(function (trait) {
  25 + if (trait.isSlot() && trait.typeName.name === "String") {
  26 + cls[Multiname.getQualifiedName(trait.name)] = className + "." + trait.name.name;
  27 + }
  28 + });
  29 + warning("HACK: registerEvents(" + className + ")");
  30 +};
17 src/avm2/runtime.js
@@ -46,6 +46,11 @@ var PARAMETER_PREFIX = "p";
46 46 var $M = [];
47 47
48 48 /**
  49 + * Overriden AS3 methods.
  50 + */
  51 +var VM_METHOD_OVERRIDES = {};
  52 +
  53 +/**
49 54 * This is used to keep track if we're in a runtime context. Proxies need to know
50 55 * if a proxied operation is triggered by AS3 code or VM code.
51 56 */
@@ -1010,12 +1015,12 @@ var Runtime = (function () {
1010 1015 var mi = methodInfo;
1011 1016 release || assert(!mi.isNative(), "Method should have a builtin: ", mi.name);
1012 1017
1013   - if (methodInfo.name &&
1014   - (methodInfo.name.name === "registerMessages" ||
1015   - methodInfo.name.name === "registerEvents")) {
1016   - return function (cls) {
1017   - warning("Stubbed out " + methodInfo.name.name);
1018   - };
  1018 +
  1019 + if (methodInfo.name) {
  1020 + var qn = Multiname.getQualifiedName(methodInfo.name);
  1021 + if (qn in VM_METHOD_OVERRIDES) {
  1022 + return VM_METHOD_OVERRIDES[qn];
  1023 + }
1019 1024 }
1020 1025
1021 1026 var hasDefaults = false;

0 comments on commit 3e9688f

Please sign in to comment.
Something went wrong with that request. Please try again.