void __qmljs_instanceof(ExecutionContext *ctx, Value *result, const Value *left, const Value *right)
{
- FunctionObject *function = right->asFunctionObject();
- if (!function)
+ Object *o = right->asObject();
+ if (!o)
__qmljs_throw_type_error(ctx);
- bool r = function->hasInstance(ctx, *left);
+ bool r = o->hasInstance(ctx, left);
*result = Value::fromBoolean(r);
}
return Value::undefinedValue();
}
+const ManagedVTable ArgumentsObject::static_vtbl =
+{
+ ArgumentsObject::markObjects,
+ Managed::hasInstance,
+ ManagedVTable::EndOfVTable
+};
+
ArgumentsObject::ArgumentsObject(ExecutionContext *context, int formalParameterCount, int actualParameterCount)
: Object(context->engine), context(context)
{
Object::markObjects(that);
}
-
-const ManagedVTable ArgumentsObject::static_vtbl =
-{
- ArgumentsObject::markObjects
-};
-
-
-
}
}
strictMode = false;
}
-bool FunctionObject::hasInstance(ExecutionContext *ctx, const Value &value)
+bool FunctionObject::hasInstance(Managed *that, ExecutionContext *ctx, const Value *value)
{
- if (! value.isObject())
+ FunctionObject *f = static_cast<FunctionObject *>(that);
+
+ Object *v = value->asObject();
+ if (!v)
return false;
- Value o = __get__(ctx, ctx->engine->id_prototype);
- if (! o.isObject()) {
+ Object *o = f->__get__(ctx, ctx->engine->id_prototype).asObject();
+ if (!o)
ctx->throwTypeError();
- return false;
- }
- Object *v = value.objectValue();
while (v) {
v = v->prototype;
if (! v)
break;
- else if (o.objectValue() == v)
+ else if (o == v)
return true;
}
const ManagedVTable FunctionObject::static_vtbl =
{
- FunctionObject::markObjects
+ FunctionObject::markObjects,
+ FunctionObject::hasInstance,
+ ManagedVTable::EndOfVTable
};
return Value::undefinedValue();
}
+const ManagedVTable BoundFunction::static_vtbl =
+{
+ BoundFunction::markObjects,
+ BoundFunction::hasInstance,
+ ManagedVTable::EndOfVTable
+};
BoundFunction::BoundFunction(ExecutionContext *scope, FunctionObject *target, Value boundThis, const QVector<Value> &boundArgs)
: FunctionObject(scope)
return target->construct(context, newArgs, boundArgs.size() + argc);
}
-bool BoundFunction::hasInstance(ExecutionContext *ctx, const Value &value)
+bool BoundFunction::hasInstance(Managed *that, ExecutionContext *ctx, const Value *value)
{
- return target->hasInstance(ctx, value);
+ BoundFunction *f = static_cast<BoundFunction *>(that);
+ return FunctionObject::hasInstance(f->target, ctx, value);
}
void BoundFunction::markObjects(Managed *that)
m->mark();
FunctionObject::markObjects(that);
}
-
-const ManagedVTable BoundFunction::static_vtbl =
-{
- BoundFunction::markObjects
-};
FunctionObject(ExecutionContext *scope);
- virtual bool hasInstance(ExecutionContext *ctx, const Value &value);
-
virtual Value construct(ExecutionContext *context, Value *args, int argc);
virtual Value call(ExecutionContext *context, Value thisObject, Value *args, int argc);
static const ManagedVTable static_vtbl;
static void markObjects(Managed *that);
+ static bool hasInstance(Managed *that, ExecutionContext *ctx, const Value *value);
};
struct FunctionCtor: FunctionObject
virtual Value call(ExecutionContext *context, Value thisObject, Value *args, int argc);
virtual Value construct(ExecutionContext *context, Value *args, int argc);
- virtual bool hasInstance(ExecutionContext *ctx, const Value &value);
static const ManagedVTable static_vtbl;
static void markObjects(Managed *that);
+ static bool hasInstance(Managed *that, ExecutionContext *ctx, const Value *value);
};
} // namespace VM
const ManagedVTable Managed::static_vtbl =
{
- 0 // markObjects
+ 0 /*markObjects*/,
+ Managed::hasInstance,
+ ManagedVTable::EndOfVTable
};
}
return QString::fromLatin1(s);
}
+
+bool Managed::hasInstance(Managed *, ExecutionContext *ctx, const Value *)
+{
+ ctx->throwTypeError();
+}
struct JSONObject;
struct ForeachIteratorObject;
struct Managed;
+struct Value;
+
struct ManagedVTable
{
+ enum _EndOfVTable {
+ EndOfVTable
+ };
void (*markObjects)(Managed *);
+ bool (*hasInstance)(Managed *, ExecutionContext *ctx, const Value *value);
+ _EndOfVTable endofVTable;
};
struct Q_V4_EXPORT Managed
*reinterpret_cast<Managed **>(this) = m;
}
+ inline bool hasInstance(ExecutionContext *ctx, const Value *v) {
+ return vtbl->hasInstance(this, ctx, v);
+ }
+
+ static bool hasInstance(Managed *that, ExecutionContext *ctx, const Value *value);
+
protected:
static const ManagedVTable static_vtbl;
const ManagedVTable *vtbl;
+
union {
uint _data;
struct {
const ManagedVTable Object::static_vtbl =
{
- Object::markObjects
+ Object::markObjects,
+ Managed::hasInstance,
+ ManagedVTable::EndOfVTable
};
void ArrayObject::init(ExecutionContext *context)
const ManagedVTable ForEachIteratorObject::static_vtbl =
{
- ForEachIteratorObject::markObjects
+ ForEachIteratorObject::markObjects,
+ Managed::hasInstance,
+ ManagedVTable::EndOfVTable
};