core/class.rb in opal-0.3.16 vs core/class.rb in opal-0.3.17
- old
+ new
@@ -1,33 +1,37 @@
class Class
def self.new(sup = Object, &block)
%x{
- var klass = boot_class(sup);
- klass.$name = "AnonClass";
+ var klass = boot_class(sup);
+ klass._name = "AnonClass";
- make_metaclass(klass, sup.$klass);
+ make_metaclass(klass, sup._klass);
#{sup.inherited `klass`};
- return block !== nil ? block.call(klass, null) : klass;
+ if (block !== null) {
+ block.call(klass, null);
+ }
+
+ return klass;
}
end
def bridge_class(constructor)
%x{
var prototype = constructor.prototype,
klass = this;
- klass.$allocator = constructor;
- klass.$proto = prototype;
+ klass._alloc = constructor;
+ klass._proto = prototype;
bridged_classes.push(klass);
- prototype.$klass = klass;
- prototype.$flags = T_OBJECT;
+ prototype._klass = klass;
+ prototype._flags = T_OBJECT;
- var donator = RubyObject.$proto;
+ var donator = RubyObject._proto;
for (var method in donator) {
if (donator.hasOwnProperty(method)) {
if (!prototype[method]) {
prototype[method] = donator[method];
}
@@ -37,11 +41,11 @@
return klass;
}
end
def allocate
- `new this.$allocator()`
+ `new this._alloc()`
end
def new(*args, &block)
obj = allocate()
obj.initialize *args, &block
@@ -51,17 +55,25 @@
def inherited(cls)
end
def superclass
%x{
- var sup = this.$s;
+ var sup = this._super;
if (!sup) {
if (this === RubyObject) {
- return nil;
+ return null;
}
- raise(RubyRuntimeError, 'uninitialized class');
+ throw RubyRuntimeError.$new('uninitialized class');
+ }
+
+ while (sup && (sup._flags & T_ICLASS)) {
+ sup = sup._super;
+ }
+
+ if (!sup) {
+ return null;
}
return sup;
}
end