Permalink
Browse files

Clean up VM variable names.

  • Loading branch information...
1 parent f059389 commit 73c27a222f016623c379c5de3855b99b840898a7 @mbebenita mbebenita committed Mar 5, 2014
Showing with 61 additions and 63 deletions.
  1. +5 −5 src/avm2/bindings.ts
  2. +3 −3 src/avm2/class.ts
  3. +1 −1 src/avm2/native.js
  4. +4 −6 src/avm2/proxy.js
  5. +4 −11 src/avm2/runtime-exports.js
  6. +44 −37 src/avm2/runtime.ts
View
@@ -169,19 +169,19 @@ module Shumway.AVM2.Runtime {
if (key !== qn) {
traitsWriter && traitsWriter.yellowLn("Binding Trait: " + key + " -> " + qn);
defineNonEnumerableGetter(object, key, makeForwardingGetter(qn));
- object[VM_BINDINGS].pushUnique(key);
+ object.asBindings.pushUnique(key);
} else {
traitsWriter && traitsWriter.greenLn("Applying Trait " + trait.kindName() + ": " + trait);
defineNonEnumerableProperty(object, qn, defaultValue);
- object[VM_BINDINGS].pushUnique(qn);
+ object.asBindings.pushUnique(qn);
var slotInfo = new SlotInfo(
qn,
trait.isConst(),
trait.typeName ? domain.getProperty(trait.typeName, false, false) : null,
trait
);
- object[VM_SLOTS].byID[trait.slotId] = slotInfo;
- object[VM_SLOTS].byQN[qn] = slotInfo;
+ object.asSlots.byID[trait.slotId] = slotInfo;
+ object.asSlots.byQN[qn] = slotInfo;
}
} else if (trait.isMethod() || trait.isGetter() || trait.isSetter()) {
if (trait.isGetter() || trait.isSetter()) {
@@ -192,7 +192,7 @@ module Shumway.AVM2.Runtime {
} else {
traitsWriter && traitsWriter.greenLn("Applying Trait " + trait.kindName() + ": " + trait);
}
- object[VM_BINDINGS].pushUnique(key);
+ object.asBindings.pushUnique(key);
if (this instanceof ScriptBindings) {
applyNonMemoizedMethodTrait(key, trait, object, binding.scope, binding.natives);
} else {
View
@@ -470,13 +470,13 @@ module Shumway.AVM2.Runtime {
writer.enter("traitsPrototype: ");
if (traitsPrototype) {
writer.enter("VM_SLOTS: ");
- writer.writeArray(traitsPrototype[VM_SLOTS].byID.map(function (slot) {
+ writer.writeArray((<any>traitsPrototype.asSlots.byID).map(function (slot) {
return slot.trait;
}));
writer.outdent();
writer.enter("VM_BINDINGS: ");
- writer.writeArray(traitsPrototype[VM_BINDINGS].map(function (binding) {
+ writer.writeArray(traitsPrototype.asBindings.map(function (binding) {
var pd = Object.getOwnPropertyDescriptor(traitsPrototype, binding);
var str = binding;
if (pd.get || pd.set) {
@@ -494,7 +494,7 @@ module Shumway.AVM2.Runtime {
writer.outdent();
writer.enter("VM_OPEN_METHODS: ");
- writer.writeArray(toKeyValueArray(traitsPrototype[VM_OPEN_METHODS]).map(function (pair) {
+ writer.writeArray(toKeyValueArray(traitsPrototype.asOpenMethods).map(function (pair) {
return pair[0] + ": " + debugName(pair[1]);
}));
writer.outdent();
View
@@ -344,7 +344,7 @@ var natives = (function () {
get: function () {
// Check if we're getting the length of a trampoline.
if (this.hasOwnProperty(VM_LENGTH)) {
- return this[VM_LENGTH];
+ return this.asLength;
}
return this.length;
}
View
@@ -39,8 +39,6 @@ for (var name in proxyTrapQns) {
proxyTrapQns[name] = VM_OPEN_METHOD_PREFIX + Multiname.getQualifiedName(new Multiname([ASNamespace.PROXY], name));
}
-var VM_IS_PROXY = "vm is proxy";
-var VM_CALL_PROXY = "vm call proxy";
function isProxyObject(obj) {
return obj[VM_IS_PROXY];
@@ -109,8 +107,8 @@ function installProxyClassWrapper(cls) {
if (TRACE_PROXY) {
TRACE_PROXY && print("> proxy pass through " + resolved);
}
- if (target[VM_OPEN_METHODS] && target[VM_OPEN_METHODS][qn]) {
- return target[VM_OPEN_METHODS][qn].apply(o, args);
+ if (target.asOpenMethods && target.asOpenMethods[qn]) {
+ return target.asOpenMethods[qn].apply(o, args);
}
// if (target[qn]) {
// return target[qn].apply(o, args);
@@ -127,8 +125,8 @@ function installProxyClassWrapper(cls) {
return target[proxyTrapQns.getProperty](name);
}
}
- if (target[VM_OPEN_METHODS] && target[VM_OPEN_METHODS][qn]) {
- return bindSafely(target[VM_OPEN_METHODS][qn], o);
+ if (target.asOpenMethods && target.asOpenMethods[qn]) {
+ return bindSafely(target.asOpenMethods[qn], o);
}
TRACE_PROXY && print("> proxy pass through " + qn);
return target[qn];
@@ -14,22 +14,15 @@
* limitations under the License.
*/
-
-
-var VM_SLOTS = "vm slots";
-var VM_LENGTH = "vm length";
-var VM_BINDINGS = "vm bindings";
-var VM_NATIVE_PROTOTYPE_FLAG = "vm native prototype";
-var VM_OPEN_METHODS = "vm open methods";
-var VM_IS_CLASS = "vm is class";
+var VM_LENGTH = Shumway.AVM2.Runtime.VM_LENGTH;
+var VM_IS_PROXY = Shumway.AVM2.Runtime.VM_IS_PROXY;
+var VM_CALL_PROXY = Shumway.AVM2.Runtime.VM_CALL_PROXY;
+var VM_NATIVE_BUILTIN_ORIGINALS = Shumway.AVM2.Runtime.VM_NATIVE_BUILTIN_ORIGINALS;
var VM_OPEN_METHOD_PREFIX = "m";
-var VM_MEMOIZER_PREFIX = "z";
var VM_OPEN_SET_METHOD_PREFIX = "s";
var VM_OPEN_GET_METHOD_PREFIX = "g";
-var VM_NATIVE_BUILTIN_ORIGINALS = "vm originals";
-
var SAVED_SCOPE_NAME = "$SS";
/**
View
@@ -49,10 +49,17 @@ interface Object {
asGetEnumerableKeys: () => any [];
class: any;
hasProperty: (namespaces: Namespace [], name: any, flags: number) => boolean; // TODO: What's this?
- enumerableKeys: any [];
-
- lazyInitializer: Shumway.AVM2.Runtime.LazyInitializer;
+ asEnumerableKeys: any [];
+ asLazyInitializer: Shumway.AVM2.Runtime.LazyInitializer;
+ asBindings: any [];
+ asLength: number;
+ asSlots: Shumway.AVM2.Runtime.SlotInfoMap;
+ asIsNativePrototype: boolean;
+ asOpenMethods: Shumway.Map<Function>;
+ asIsClass: boolean;
+ asIsProxy: boolean;
+ asCallProxy: any;
}
module Shumway.AVM2.Runtime {
@@ -147,21 +154,21 @@ module Shumway.AVM2.Runtime {
import TRAIT = Shumway.AVM2.ABC.TRAIT;
- export var VM_SLOTS = "vm slots";
- export var VM_LENGTH = "vm length";
- export var VM_BINDINGS = "vm bindings";
- export var VM_NATIVE_PROTOTYPE_FLAG = "vm native prototype";
- export var VM_OPEN_METHODS = "vm open methods";
- export var VM_IS_CLASS = "vm is class";
- export var VM_IS_PROXY = "vm is proxy";
- export var VM_CALL_PROXY = "vm call proxy";
+ export var VM_SLOTS = "asSlots";
+ export var VM_LENGTH = "asLength";
+ export var VM_BINDINGS = "asBindings";
+ export var VM_NATIVE_PROTOTYPE_FLAG = "asIsNative";
+ export var VM_OPEN_METHODS = "asOpenMethods";
+ export var VM_IS_CLASS = "asIsClass";
+ export var VM_IS_PROXY = "asIsProxy";
+ export var VM_CALL_PROXY = "asCallProxy";
export var VM_OPEN_METHOD_PREFIX = "m";
export var VM_MEMOIZER_PREFIX = "z";
export var VM_OPEN_SET_METHOD_PREFIX = "s";
export var VM_OPEN_GET_METHOD_PREFIX = "g";
- export var VM_NATIVE_BUILTIN_ORIGINALS = "vm originals";
+ export var VM_NATIVE_BUILTIN_ORIGINALS = "asOriginals";
/**
* Overriden AS3 methods (see hacks.js). This allows you to provide your own JS implementation
@@ -242,7 +249,7 @@ module Shumway.AVM2.Runtime {
{ object: object, name: VM_OPEN_METHOD_PREFIX + qn }
];
var closure = bindSafely(trampoline, object);
- defineReadOnlyProperty(closure, VM_LENGTH, trampoline[VM_LENGTH]);
+ defineReadOnlyProperty(closure, VM_LENGTH, trampoline.asLength);
defineReadOnlyProperty(closure, Multiname.getPublicQualifiedName("prototype"), null);
defineNonEnumerableProperty(object, qn, closure);
defineNonEnumerableProperty(object, VM_OPEN_METHOD_PREFIX + qn, closure);
@@ -278,7 +285,7 @@ module Shumway.AVM2.Runtime {
}, trait.methodInfo.parameters.length, String(trait.name));
memoizerTarget.value = trampoline;
- var openMethods = object[VM_OPEN_METHODS];
+ var openMethods = object.asOpenMethods;
openMethods[qn] = trampoline;
defineNonEnumerableProperty(object, VM_OPEN_METHOD_PREFIX + qn, trampoline);
// TODO: We make the |memoizeMethodClosure| configurable since it may be
@@ -439,7 +446,7 @@ module Shumway.AVM2.Runtime {
export function asCallResolvedStringProperty(resolved: any, isLex: boolean, args: any []) {
var self: Object = this;
var receiver = isLex ? null : this;
- var openMethods = self[VM_OPEN_METHODS];
+ var openMethods = self.asOpenMethods;
// TODO: Passing |null| as |this| doesn't work correctly for free methods. It just happens to work
// when using memoizers because the function gets bound to |this|.
var method;
@@ -471,10 +478,10 @@ module Shumway.AVM2.Runtime {
if (self.asSetNumericProperty && Multiname.isNumeric(resolved)) {
return self.asSetNumericProperty(resolved, value);
}
- var slotInfo = self[VM_SLOTS].byQN[resolved];
+ var slotInfo = self.asSlots.byQN[resolved];
if (slotInfo) {
- if (slotInfo.const) {
- return;
+ if (slotInfo.isConst) {
+ // TODO: Seal after first assignment. return;
}
var type = slotInfo.type;
if (type && type.coerce) {
@@ -528,7 +535,7 @@ module Shumway.AVM2.Runtime {
if (self.asGetNumericProperty && Multiname.isNumeric(resolved)) {
method = self.asGetNumericProperty(resolved);
} else {
- var openMethods = self[VM_OPEN_METHODS];
+ var openMethods = self.asOpenMethods;
// TODO: Passing |null| as |this| doesn't work correctly for free methods. It just happens to work
// when using memoizers because the function gets bound to |this|.
if (receiver && openMethods && openMethods[resolved]) {
@@ -551,7 +558,7 @@ module Shumway.AVM2.Runtime {
}
var baseClass = scope.object.baseClass;
var resolved = baseClass.traitsPrototype.resolveMultinameProperty(namespaces, name, flags);
- var openMethods = baseClass.traitsPrototype[VM_OPEN_METHODS];
+ var openMethods = baseClass.traitsPrototype.asOpenMethods;
assert (openMethods && openMethods[resolved]);
var method = openMethods[resolved];
var result = method.apply(this, args);
@@ -567,7 +574,7 @@ module Shumway.AVM2.Runtime {
}
var baseClass = scope.object.baseClass;
var resolved = baseClass.traitsPrototype.resolveMultinameProperty(namespaces, name, flags);
- if (self[VM_SLOTS].byQN[resolved]) {
+ if (self.asSlots.byQN[resolved]) {
this.asSetProperty(namespaces, name, flags, value);
} else {
baseClass.traitsPrototype[VM_OPEN_SET_METHOD_PREFIX + resolved].call(this, value);
@@ -584,7 +591,7 @@ module Shumway.AVM2.Runtime {
var baseClass = scope.object.baseClass;
var resolved = baseClass.traitsPrototype.resolveMultinameProperty(namespaces, name, flags);
var result;
- if (self[VM_SLOTS].byQN[resolved]) {
+ if (self.asSlots.byQN[resolved]) {
result = this.asGetProperty(namespaces, name, flags);
} else {
result = baseClass.traitsPrototype[VM_OPEN_GET_METHOD_PREFIX + resolved].call(this);
@@ -685,11 +692,11 @@ module Shumway.AVM2.Runtime {
var self: Object = this;
if (index === 0) {
// Gather all enumerable keys since we're starting a new iteration.
- defineNonEnumerableProperty(self, "enumerableKeys", self.asGetEnumerableKeys());
+ defineNonEnumerableProperty(self, "asEnumerableKeys", self.asGetEnumerableKeys());
}
- var enumerableKeys = self.enumerableKeys;
- while (index < enumerableKeys.length) {
- if (self.asHasProperty(undefined, enumerableKeys[index], 0)) {
+ var asEnumerableKeys = self.asEnumerableKeys;
+ while (index < asEnumerableKeys.length) {
+ if (self.asHasProperty(undefined, asEnumerableKeys[index], 0)) {
return index + 1;
}
index ++;
@@ -703,9 +710,9 @@ module Shumway.AVM2.Runtime {
*/
export function asNextName(index: number) {
var self: Object = this;
- var enumerableKeys = self.enumerableKeys;
- release || assert(enumerableKeys && index > 0 && index < enumerableKeys.length + 1);
- return enumerableKeys[index - 1];
+ var asEnumerableKeys = self.asEnumerableKeys;
+ release || assert(asEnumerableKeys && index > 0 && index < asEnumerableKeys.length + 1);
+ return asEnumerableKeys[index - 1];
}
export function asNextValue(index: number) {
@@ -769,11 +776,11 @@ module Shumway.AVM2.Runtime {
}
export function asGetSlot(object, index) {
- return object[object[VM_SLOTS].byID[index].name];
+ return object[object.asSlots.byID[index].name];
}
export function asSetSlot(object, index, value) {
- var slotInfo = object[VM_SLOTS].byID[index];
+ var slotInfo = object.asSlots.byID[index];
if (slotInfo.const) {
return;
}
@@ -1180,13 +1187,13 @@ module Shumway.AVM2.Runtime {
name: string;
private static _holder = jsGlobal;
static create(target): LazyInitializer {
- if (target.lazyInitializer) {
- return target.lazyInitializer;
+ if (target.asLazyInitializer) {
+ return target.asLazyInitializer;
}
- return target.lazyInitializer = new LazyInitializer(target);
+ return target.asLazyInitializer = new LazyInitializer(target);
}
constructor (target: Object) {
- assert (!target.lazyInitializer);
+ assert (!target.asLazyInitializer);
this.target = target;
}
public getName() {
@@ -1228,7 +1235,7 @@ module Shumway.AVM2.Runtime {
}
export function forEachPublicProperty(object, fn, self) {
- if (!object[VM_BINDINGS]) {
+ if (!object.asBindings) {
for (var key in object) {
fn.call(self, key, object[key]);
}
@@ -1238,7 +1245,7 @@ module Shumway.AVM2.Runtime {
for (var key in object) {
if (isNumeric(key)) {
fn.call(self, key, object[key]);
- } else if (Multiname.isPublicQualifiedName(key) && object[VM_BINDINGS].indexOf(key) < 0) {
+ } else if (Multiname.isPublicQualifiedName(key) && object.asBindings.indexOf(key) < 0) {
var name = Multiname.stripPublicQualifier(key);
fn.call(self, name, object[key]);
}

0 comments on commit 73c27a2

Please sign in to comment.