Skip to content
This repository
Browse code

Add missing files.

  • Loading branch information...
commit 4ec2b89cf31a4c582274dfd77acb0e5c65a7171d 1 parent 6f25d4f
Michael Bebenita mbebenita authored

Showing 1 changed file with 81 additions and 0 deletions. Show diff stats Hide diff stats

  1. +81 0 src/avm2/proxy.js
81 src/avm2/proxy.js
... ... @@ -0,0 +1,81 @@
  1 +/**
  2 + * Proxy.as
  3 + */
  4 +function ProxyClass(runtime, scope, instance, baseClass) {
  5 + function ProxyConstructor() {
  6 + somewhatImplemented("Proxy");
  7 + }
  8 + var c = new runtime.domain.system.Class("Proxy", ProxyConstructor, Domain.coerceCallable(ProxyConstructor));
  9 + c.extendBuiltin(baseClass);
  10 + return c;
  11 +}
  12 +
  13 +var proxyTrapQns = {
  14 + "getProperty": null,
  15 + "setProperty": null,
  16 + "hasProperty": null
  17 +};
  18 +
  19 +for (var name in proxyTrapQns) {
  20 + proxyTrapQns[name] = Multiname.getQualifiedName(new Multiname([ShumwayNamespace.PROXY], name));
  21 +}
  22 +
  23 +console.info(proxyTrapQns.getProperty);
  24 +
  25 +function extractActionScriptName(name) {
  26 + if (name.indexOf("public$") === 0) {
  27 + return name.substr(7);
  28 + }
  29 + return false;
  30 + // return name.indexOf("public$") >= 0 || name.indexOf("private$") >= 0;
  31 +}
  32 +
  33 +function installProxyClass(cls) {
  34 + var instance = cls.instance;
  35 + function construct() {
  36 + var target = Object.create(instance.prototype);
  37 + var proxy = Proxy.create({
  38 + get: function(o, name) {
  39 + if (inRuntime()) {
  40 + return target[name];
  41 + }
  42 + var externalName = extractActionScriptName(name);
  43 + if (externalName) {
  44 + return target[proxyTrapQns.getProperty](externalName);
  45 + }
  46 + return target[name];
  47 + },
  48 + set: function(o, name, value) {
  49 + target[name] = value;
  50 + // notImplemented("set");
  51 + },
  52 + has: function(name) {
  53 + if (inRuntime()) {
  54 + return name in target;
  55 + }
  56 + var externalName = extractActionScriptName(name);
  57 + if (externalName) {
  58 + return target[proxyTrapQns.hasProperty](externalName);
  59 + }
  60 + return name in target;
  61 + },
  62 + hasOwn: function(name) {
  63 + if (extractActionScriptName(name)) {
  64 +
  65 + }
  66 + return !!Object.getOwnPropertyDescriptor(target, name);
  67 + },
  68 + enumerate: function() {
  69 + notImplemented("enumerate");
  70 + },
  71 + keys: function() {
  72 + notImplemented("keys");
  73 + }
  74 + }, instance.prototype);
  75 + // The derived proxy constructor needs to have a reference to the proxy object itself.
  76 + instance.apply(proxy, sliceArguments(arguments, 0));
  77 + return proxy;
  78 + }
  79 +
  80 + cls.instance = construct;
  81 +}

0 comments on commit 4ec2b89

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