mirror of https://github.com/adamdruppe/arsd.git
opIndex overload bug fix
This commit is contained in:
parent
7912025ec4
commit
97ee3385c9
24
jsvar.d
24
jsvar.d
|
@ -768,11 +768,25 @@ struct var {
|
||||||
case Type.Object:
|
case Type.Object:
|
||||||
static if(isAssociativeArray!T) {
|
static if(isAssociativeArray!T) {
|
||||||
T ret;
|
T ret;
|
||||||
|
if(this._payload._object !is null)
|
||||||
foreach(k, v; this._payload._object._properties)
|
foreach(k, v; this._payload._object._properties)
|
||||||
ret[to!(KeyType!T)(k)] = v.get!(ValueType!T);
|
ret[to!(KeyType!T)(k)] = v.get!(ValueType!T);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
} else static if(is(T : PrototypeObject)) {
|
||||||
|
// they are requesting an implementation object, just give it to them
|
||||||
|
return cast(T) this._payload._object;
|
||||||
} else static if(is(T == struct) || is(T == class)) {
|
} else static if(is(T == struct) || is(T == class)) {
|
||||||
|
// first, we'll try to give them back the native object we have, if we have one
|
||||||
|
static if(is(T : Object)) {
|
||||||
|
if(auto wno = cast(WrappedNativeObject) this._payload._object) {
|
||||||
|
auto no = cast(T) wno.getObject();
|
||||||
|
if(no !is null)
|
||||||
|
return no;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// failing that, generic struct or class getting: try to fill in the fields by name
|
||||||
T t;
|
T t;
|
||||||
static if(is(T == class))
|
static if(is(T == class))
|
||||||
t = new T();
|
t = new T();
|
||||||
|
@ -1076,6 +1090,11 @@ struct var {
|
||||||
auto arr = this._payload._array;
|
auto arr = this._payload._array;
|
||||||
if(idx < arr.length)
|
if(idx < arr.length)
|
||||||
return arr[idx];
|
return arr[idx];
|
||||||
|
} else if(_type == Type.Object) {
|
||||||
|
// objects might overload opIndex
|
||||||
|
var* n = new var();
|
||||||
|
*n = this["opIndex"](idx);
|
||||||
|
return *n;
|
||||||
}
|
}
|
||||||
version(jsvar_throw)
|
version(jsvar_throw)
|
||||||
throw new DynamicTypeException(this, Type.Array, file, line);
|
throw new DynamicTypeException(this, Type.Array, file, line);
|
||||||
|
@ -1549,6 +1568,7 @@ template makeAscii() {
|
||||||
// just a base class we can reference when looking for native objects
|
// just a base class we can reference when looking for native objects
|
||||||
class WrappedNativeObject : PrototypeObject {
|
class WrappedNativeObject : PrototypeObject {
|
||||||
TypeInfo wrappedType;
|
TypeInfo wrappedType;
|
||||||
|
abstract Object getObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
template helper(alias T) { alias helper = T; }
|
template helper(alias T) { alias helper = T; }
|
||||||
|
@ -1562,6 +1582,10 @@ template helper(alias T) { alias helper = T; }
|
||||||
/// That may be done automatically with opAssign in the future.
|
/// That may be done automatically with opAssign in the future.
|
||||||
WrappedNativeObject wrapNativeObject(Class)(Class obj) if(is(Class == class)) {
|
WrappedNativeObject wrapNativeObject(Class)(Class obj) if(is(Class == class)) {
|
||||||
return new class WrappedNativeObject {
|
return new class WrappedNativeObject {
|
||||||
|
override Object getObject() {
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
this() {
|
this() {
|
||||||
wrappedType = typeid(obj);
|
wrappedType = typeid(obj);
|
||||||
// wrap the other methods
|
// wrap the other methods
|
||||||
|
|
Loading…
Reference in New Issue