2012-04-16 19:23:25 +00:00
|
|
|
|
|
|
|
#include "qmljs_runtime.h"
|
|
|
|
#include "qmljs_objects.h"
|
2012-05-13 11:50:55 +00:00
|
|
|
#include "qv4ir_p.h"
|
2012-06-05 08:47:04 +00:00
|
|
|
#include "qv4ecmaobjects_p.h"
|
|
|
|
|
2012-05-18 13:28:59 +00:00
|
|
|
#include <QtCore/qmath.h>
|
|
|
|
#include <QtCore/qnumeric.h>
|
2012-05-07 14:05:05 +00:00
|
|
|
#include <QtCore/QDebug>
|
2012-04-16 19:23:25 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cassert>
|
2012-05-18 13:28:59 +00:00
|
|
|
#include <typeinfo>
|
2012-04-16 19:23:25 +00:00
|
|
|
|
2012-05-04 18:22:04 +00:00
|
|
|
namespace QQmlJS {
|
|
|
|
namespace VM {
|
2012-05-04 13:28:04 +00:00
|
|
|
|
2012-05-18 13:28:59 +00:00
|
|
|
QString numberToString(double num, int radix = 10)
|
|
|
|
{
|
|
|
|
if (qIsNaN(num)) {
|
2012-05-25 10:54:36 +00:00
|
|
|
return QStringLiteral("NaN");
|
2012-05-18 13:28:59 +00:00
|
|
|
} else if (qIsInf(num)) {
|
|
|
|
return QLatin1String(num < 0 ? "-Infinity" : "Infinity");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (radix == 10)
|
|
|
|
return QString::number(num, 'g', 16);
|
|
|
|
|
|
|
|
QString str;
|
|
|
|
bool negative = false;
|
|
|
|
|
|
|
|
if (num < 0) {
|
|
|
|
negative = true;
|
|
|
|
num = -num;
|
|
|
|
}
|
|
|
|
|
|
|
|
double frac = num - ::floor(num);
|
|
|
|
num = Value::toInteger(num);
|
|
|
|
|
|
|
|
do {
|
|
|
|
char c = (char)::fmod(num, radix);
|
|
|
|
c = (c < 10) ? (c + '0') : (c - 10 + 'a');
|
|
|
|
str.prepend(QLatin1Char(c));
|
|
|
|
num = ::floor(num / radix);
|
|
|
|
} while (num != 0);
|
|
|
|
|
|
|
|
if (frac != 0) {
|
|
|
|
str.append(QLatin1Char('.'));
|
|
|
|
do {
|
|
|
|
frac = frac * radix;
|
|
|
|
char c = (char)::floor(frac);
|
|
|
|
c = (c < 10) ? (c + '0') : (c - 10 + 'a');
|
|
|
|
str.append(QLatin1Char(c));
|
|
|
|
frac = frac - ::floor(frac);
|
|
|
|
} while (frac != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (negative)
|
|
|
|
str.prepend(QLatin1Char('-'));
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-15 08:53:20 +00:00
|
|
|
Value Value::fromString(Context *ctx, const QString &s)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-05-15 08:53:20 +00:00
|
|
|
return fromString(ctx->engine->newString(s));
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-05-14 14:03:10 +00:00
|
|
|
int Value::toInt32(double number)
|
|
|
|
{
|
|
|
|
if (! number || isnan(number) || isinf(number))
|
|
|
|
return +0;
|
|
|
|
return (int) trunc(number); // ###
|
|
|
|
}
|
|
|
|
|
2012-06-05 08:47:04 +00:00
|
|
|
unsigned int Value::toUInt32(double number)
|
2012-05-20 17:59:47 +00:00
|
|
|
{
|
|
|
|
if (! number || isnan(number) || isinf(number))
|
|
|
|
return +0;
|
|
|
|
return (uint) trunc(number); // ###
|
|
|
|
}
|
|
|
|
|
2012-05-14 14:03:10 +00:00
|
|
|
int Value::toInteger(double number)
|
|
|
|
{
|
|
|
|
if (isnan(number))
|
|
|
|
return +0;
|
|
|
|
else if (! number || isinf(number))
|
|
|
|
return number;
|
|
|
|
const double v = floor(fabs(number));
|
|
|
|
return signbit(number) ? -v : v;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Value::toUInt16(Context *ctx)
|
|
|
|
{
|
|
|
|
return __qmljs_to_uint16(ctx, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Value::toInt32(Context *ctx)
|
|
|
|
{
|
|
|
|
return __qmljs_to_int32(ctx, this);
|
|
|
|
}
|
|
|
|
|
2012-06-05 08:47:04 +00:00
|
|
|
unsigned int Value::toUInt32(Context *ctx)
|
2012-05-14 14:03:10 +00:00
|
|
|
{
|
|
|
|
return __qmljs_to_int32(ctx, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Value::toBoolean(Context *ctx) const
|
|
|
|
{
|
|
|
|
return __qmljs_to_boolean(ctx, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
double Value::toInteger(Context *ctx) const
|
|
|
|
{
|
|
|
|
return __qmljs_to_integer(ctx, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
double Value::toNumber(Context *ctx) const
|
|
|
|
{
|
|
|
|
return __qmljs_to_number(ctx, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
String *Value::toString(Context *ctx) const
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
__qmljs_to_string(ctx, &v, this);
|
2012-09-19 19:08:47 +00:00
|
|
|
assert(v.is(Value::String_Type));
|
|
|
|
return v.stringValue();
|
2012-05-14 14:03:10 +00:00
|
|
|
}
|
|
|
|
|
2012-06-04 13:57:39 +00:00
|
|
|
Value Value::toObject(Context *ctx) const
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
__qmljs_to_object(ctx, &v, this);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2012-05-18 12:10:02 +00:00
|
|
|
bool Value::isFunctionObject() const
|
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
return isObject() ? objectValue()->asFunctionObject() != 0 : false;
|
2012-05-18 12:10:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Value::isBooleanObject() const
|
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
return isObject() ? objectValue()->asBooleanObject() != 0 : false;
|
2012-05-18 12:10:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Value::isNumberObject() const
|
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
return isObject() ? objectValue()->asNumberObject() != 0 : false;
|
2012-05-18 12:10:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Value::isStringObject() const
|
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
return isObject() ? objectValue()->asStringObject() != 0 : false;
|
2012-05-18 12:10:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Value::isDateObject() const
|
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
return isObject() ? objectValue()->asDateObject() != 0 : false;
|
2012-05-18 12:10:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Value::isArrayObject() const
|
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
return isObject() ? objectValue()->asArrayObject() != 0 : false;
|
2012-05-18 12:10:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Value::isErrorObject() const
|
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
return isObject() ? objectValue()->asErrorObject() != 0 : false;
|
2012-05-18 12:10:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Value::isArgumentsObject() const
|
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
return isObject() ? objectValue()->asActivationObject() != 0 : false;
|
2012-05-18 12:10:02 +00:00
|
|
|
}
|
|
|
|
|
2012-05-18 13:28:59 +00:00
|
|
|
Object *Value::asObject() const
|
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
return isObject() ? objectValue() : 0;
|
2012-05-18 13:28:59 +00:00
|
|
|
}
|
|
|
|
|
2012-05-18 12:10:02 +00:00
|
|
|
FunctionObject *Value::asFunctionObject() const
|
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
return isObject() ? objectValue()->asFunctionObject() : 0;
|
2012-05-18 12:10:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BooleanObject *Value::asBooleanObject() const
|
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
return isObject() ? objectValue()->asBooleanObject() : 0;
|
2012-05-18 12:10:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NumberObject *Value::asNumberObject() const
|
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
return isObject() ? objectValue()->asNumberObject() : 0;
|
2012-05-18 12:10:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StringObject *Value::asStringObject() const
|
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
return isObject() ? objectValue()->asStringObject() : 0;
|
2012-05-18 12:10:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DateObject *Value::asDateObject() const
|
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
return isObject() ? objectValue()->asDateObject() : 0;
|
2012-05-18 12:10:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ArrayObject *Value::asArrayObject() const
|
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
return isObject() ? objectValue()->asArrayObject() : 0;
|
2012-05-18 12:10:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ErrorObject *Value::asErrorObject() const
|
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
return isObject() ? objectValue()->asErrorObject() : 0;
|
2012-05-18 12:10:02 +00:00
|
|
|
}
|
|
|
|
|
2012-06-04 14:36:00 +00:00
|
|
|
ActivationObject *Value::asArgumentsObject() const
|
2012-05-18 12:10:02 +00:00
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
return isObject() ? objectValue()->asActivationObject() : 0;
|
2012-05-18 12:10:02 +00:00
|
|
|
}
|
2012-05-14 14:03:10 +00:00
|
|
|
|
2012-05-25 10:54:36 +00:00
|
|
|
Value Value::property(Context *ctx, String *name) const
|
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
return isObject() ? objectValue()->getProperty(ctx, name) : undefinedValue();
|
2012-05-25 10:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Value *Value::getPropertyDescriptor(Context *ctx, String *name) const
|
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
return isObject() ? objectValue()->getPropertyDescriptor(ctx, name) : 0;
|
2012-05-25 10:54:36 +00:00
|
|
|
}
|
|
|
|
|
2012-06-05 08:47:04 +00:00
|
|
|
void Context::init(ExecutionEngine *eng)
|
|
|
|
{
|
|
|
|
engine = eng;
|
|
|
|
parent = 0;
|
|
|
|
arguments = 0;
|
|
|
|
argumentCount = 0;
|
|
|
|
locals = 0;
|
2012-09-19 19:08:47 +00:00
|
|
|
activation = Value::nullValue();
|
|
|
|
thisObject = Value::nullValue();
|
|
|
|
result = Value::undefinedValue();
|
2012-06-05 08:47:04 +00:00
|
|
|
formals = 0;
|
|
|
|
formalCount = 0;
|
|
|
|
vars = 0;
|
|
|
|
varCount = 0;
|
|
|
|
calledAsConstructor = false;
|
|
|
|
hasUncaughtException = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Value *Context::lookupPropertyDescriptor(String *name)
|
|
|
|
{
|
|
|
|
for (Context *ctx = this; ctx; ctx = ctx->parent) {
|
2012-09-19 19:08:47 +00:00
|
|
|
if (ctx->activation.is(Value::Object_Type)) {
|
|
|
|
if (Value *prop = ctx->activation.objectValue()->getPropertyDescriptor(this, name)) {
|
2012-06-05 08:47:04 +00:00
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Context::throwError(const Value &value)
|
|
|
|
{
|
|
|
|
result = value;
|
|
|
|
hasUncaughtException = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Context::throwError(const QString &message)
|
|
|
|
{
|
|
|
|
Value v = Value::fromString(this, message);
|
|
|
|
throwError(Value::fromObject(engine->newErrorObject(v)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Context::throwTypeError()
|
|
|
|
{
|
|
|
|
Value v = Value::fromString(this, QStringLiteral("Type error"));
|
|
|
|
throwError(Value::fromObject(engine->newErrorObject(v)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Context::throwUnimplemented(const QString &message)
|
|
|
|
{
|
|
|
|
Value v = Value::fromString(this, QStringLiteral("Unimplemented ") + message);
|
|
|
|
throwError(Value::fromObject(engine->newErrorObject(v)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Context::throwReferenceError(const Value &value)
|
|
|
|
{
|
|
|
|
String *s = value.toString(this);
|
|
|
|
QString msg = s->toQString() + QStringLiteral(" is not defined");
|
|
|
|
throwError(Value::fromObject(engine->newErrorObject(Value::fromString(this, msg))));
|
|
|
|
}
|
|
|
|
|
2012-06-11 07:38:52 +00:00
|
|
|
void Context::initCallContext(ExecutionEngine *e, const Value *object, FunctionObject *f, Value *args, unsigned argc)
|
2012-06-05 08:47:04 +00:00
|
|
|
{
|
|
|
|
engine = e;
|
|
|
|
parent = f->scope;
|
2012-06-13 09:02:23 +00:00
|
|
|
__qmljs_init_undefined(&result);
|
2012-06-05 08:47:04 +00:00
|
|
|
|
|
|
|
if (f->needsActivation)
|
|
|
|
__qmljs_init_object(&activation, engine->newActivationObject(this));
|
|
|
|
else
|
|
|
|
__qmljs_init_null(&activation);
|
|
|
|
|
|
|
|
if (object)
|
|
|
|
thisObject = *object;
|
|
|
|
else
|
|
|
|
__qmljs_init_null(&thisObject);
|
|
|
|
|
|
|
|
formals = f->formalParameterList;
|
|
|
|
formalCount = f->formalParameterCount;
|
|
|
|
arguments = args;
|
|
|
|
argumentCount = argc;
|
2012-06-11 07:38:52 +00:00
|
|
|
if (f->needsActivation || argc < formalCount){
|
|
|
|
arguments = new Value[qMax(argc, formalCount)];
|
|
|
|
if (argc)
|
|
|
|
std::copy(args, args + argc, arguments);
|
|
|
|
if (argc < formalCount)
|
|
|
|
std::fill(arguments + argc, arguments + formalCount, Value::undefinedValue());
|
2012-06-05 08:47:04 +00:00
|
|
|
}
|
|
|
|
vars = f->varList;
|
|
|
|
varCount = f->varCount;
|
|
|
|
locals = varCount ? new Value[varCount] : 0;
|
|
|
|
hasUncaughtException = false;
|
|
|
|
calledAsConstructor = false;
|
|
|
|
if (varCount)
|
|
|
|
std::fill(locals, locals + varCount, Value::undefinedValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Context::leaveCallContext(FunctionObject *f, Value *returnValue)
|
|
|
|
{
|
|
|
|
if (returnValue)
|
2012-10-10 11:46:12 +00:00
|
|
|
*returnValue = result;
|
2012-06-05 08:47:04 +00:00
|
|
|
|
|
|
|
if (! f->needsActivation) {
|
|
|
|
delete[] locals;
|
|
|
|
locals = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-11 07:38:52 +00:00
|
|
|
void Context::initConstructorContext(ExecutionEngine *e, const Value *object, FunctionObject *f, Value *args, unsigned argc)
|
2012-06-05 08:47:04 +00:00
|
|
|
{
|
|
|
|
initCallContext(e, object, f, args, argc);
|
|
|
|
calledAsConstructor = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Context::leaveConstructorContext(FunctionObject *f, Value *returnValue)
|
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
assert(thisObject.is(Value::Object_Type));
|
2012-06-05 08:47:04 +00:00
|
|
|
result = thisObject;
|
|
|
|
|
|
|
|
Value proto = f->getProperty(this, engine->id_prototype);
|
2012-09-19 19:08:47 +00:00
|
|
|
thisObject.objectValue()->prototype = proto.objectValue();
|
2012-06-05 08:47:04 +00:00
|
|
|
if (! thisObject.isObject())
|
2012-09-19 19:08:47 +00:00
|
|
|
thisObject.objectValue()->prototype = engine->objectPrototype;
|
2012-06-05 08:47:04 +00:00
|
|
|
|
|
|
|
leaveCallContext(f, returnValue);
|
|
|
|
}
|
|
|
|
|
2012-04-16 19:23:25 +00:00
|
|
|
extern "C" {
|
|
|
|
|
2012-05-09 11:51:44 +00:00
|
|
|
void __qmljs_init_closure(Context *ctx, Value *result, IR::Function *clos)
|
|
|
|
{
|
2012-05-15 08:53:20 +00:00
|
|
|
__qmljs_init_object(result, ctx->engine->newScriptFunction(ctx, clos));
|
2012-05-09 11:51:44 +00:00
|
|
|
}
|
|
|
|
|
2012-06-06 12:59:42 +00:00
|
|
|
void __qmljs_init_native_function(Context *ctx, Value *result, void (*code)(Context *))
|
|
|
|
{
|
|
|
|
__qmljs_init_object(result, ctx->engine->newNativeFunction(ctx, code));
|
|
|
|
}
|
|
|
|
|
2012-04-16 19:23:25 +00:00
|
|
|
void __qmljs_string_literal_undefined(Context *ctx, Value *result)
|
|
|
|
{
|
2012-05-25 10:54:36 +00:00
|
|
|
__qmljs_init_string(result, ctx->engine->identifier(QStringLiteral("undefined")));
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_string_literal_null(Context *ctx, Value *result)
|
|
|
|
{
|
2012-05-25 10:54:36 +00:00
|
|
|
__qmljs_init_string(result, ctx->engine->identifier(QStringLiteral("null")));
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_string_literal_true(Context *ctx, Value *result)
|
|
|
|
{
|
2012-05-25 10:54:36 +00:00
|
|
|
__qmljs_init_string(result, ctx->engine->identifier(QStringLiteral("true")));
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_string_literal_false(Context *ctx, Value *result)
|
|
|
|
{
|
2012-05-25 10:54:36 +00:00
|
|
|
__qmljs_init_string(result, ctx->engine->identifier(QStringLiteral("false")));
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_string_literal_object(Context *ctx, Value *result)
|
|
|
|
{
|
2012-05-25 10:54:36 +00:00
|
|
|
__qmljs_init_string(result, ctx->engine->identifier(QStringLiteral("object")));
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_string_literal_boolean(Context *ctx, Value *result)
|
|
|
|
{
|
2012-05-25 10:54:36 +00:00
|
|
|
__qmljs_init_string(result, ctx->engine->identifier(QStringLiteral("boolean")));
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_string_literal_number(Context *ctx, Value *result)
|
|
|
|
{
|
2012-05-25 10:54:36 +00:00
|
|
|
__qmljs_init_string(result, ctx->engine->identifier(QStringLiteral("number")));
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_string_literal_string(Context *ctx, Value *result)
|
|
|
|
{
|
2012-05-25 10:54:36 +00:00
|
|
|
__qmljs_init_string(result, ctx->engine->identifier(QStringLiteral("string")));
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_string_literal_function(Context *ctx, Value *result)
|
|
|
|
{
|
2012-05-25 10:54:36 +00:00
|
|
|
__qmljs_init_string(result, ctx->engine->identifier(QStringLiteral("function")));
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-06-07 12:28:42 +00:00
|
|
|
void __qmljs_delete_subscript(Context *ctx, Value *result, Value *base, Value *index)
|
|
|
|
{
|
|
|
|
if (ArrayObject *a = base->asArrayObject()) {
|
|
|
|
if (index->isNumber()) {
|
2012-09-19 19:08:47 +00:00
|
|
|
const quint32 n = index->doubleValue();
|
2012-06-07 12:28:42 +00:00
|
|
|
if (n < a->value.size()) {
|
|
|
|
a->value.assign(n, Value::undefinedValue());
|
|
|
|
__qmljs_init_boolean(result, true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String *name = index->toString(ctx);
|
|
|
|
__qmljs_delete_member(ctx, result, base, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_delete_member(Context *ctx, Value *result, Value *base, String *name)
|
|
|
|
{
|
|
|
|
Value obj = base->toObject(ctx);
|
2012-09-19 19:08:47 +00:00
|
|
|
__qmljs_init_boolean(result, obj.objectValue()->deleteProperty(ctx, name, true));
|
2012-06-07 12:28:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_delete_property(Context *ctx, Value *result, String *name)
|
|
|
|
{
|
|
|
|
Value obj = ctx->activation;
|
|
|
|
if (! obj.isObject())
|
|
|
|
obj = ctx->engine->globalObject;
|
2012-09-19 19:08:47 +00:00
|
|
|
__qmljs_init_boolean(result, obj.objectValue()->deleteProperty(ctx, name, true));
|
2012-06-07 12:28:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_delete_value(Context *ctx, Value *result, Value *value)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-06-07 12:28:42 +00:00
|
|
|
Q_UNUSED(value);
|
|
|
|
__qmljs_throw_type_error(ctx, result); // ### throw syntax error
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-06-06 08:58:49 +00:00
|
|
|
void __qmljs_add_helper(Context *ctx, Value *result, const Value *left, const Value *right)
|
|
|
|
{
|
|
|
|
Value pleft, pright;
|
|
|
|
__qmljs_to_primitive(ctx, &pleft, left, PREFERREDTYPE_HINT);
|
|
|
|
__qmljs_to_primitive(ctx, &pright, right, PREFERREDTYPE_HINT);
|
2012-09-19 19:08:47 +00:00
|
|
|
if (pleft.isString() || pright.isString()) {
|
|
|
|
if (!pleft.isString())
|
2012-06-06 08:58:49 +00:00
|
|
|
__qmljs_to_string(ctx, &pleft, &pleft);
|
2012-09-19 19:08:47 +00:00
|
|
|
if (!pright.isString())
|
2012-06-06 08:58:49 +00:00
|
|
|
__qmljs_to_string(ctx, &pright, &pright);
|
2012-09-19 19:08:47 +00:00
|
|
|
String *string = __qmljs_string_concat(ctx, pleft.stringValue(), pright.stringValue());
|
2012-06-06 08:58:49 +00:00
|
|
|
__qmljs_init_string(result, string);
|
|
|
|
} else {
|
|
|
|
double x = __qmljs_to_number(ctx, &pleft);
|
|
|
|
double y = __qmljs_to_number(ctx, &pright);
|
|
|
|
__qmljs_init_number(result, x + y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-16 19:23:25 +00:00
|
|
|
void __qmljs_instanceof(Context *ctx, Value *result, const Value *left, const Value *right)
|
|
|
|
{
|
2012-05-28 18:17:13 +00:00
|
|
|
if (FunctionObject *function = right->asFunctionObject()) {
|
|
|
|
bool r = function->hasInstance(ctx, *left);
|
|
|
|
__qmljs_init_boolean(result, r);
|
|
|
|
return;
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
__qmljs_throw_type_error(ctx, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_in(Context *ctx, Value *result, const Value *left, const Value *right)
|
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
if (right->isObject()) {
|
2012-04-16 19:23:25 +00:00
|
|
|
Value s;
|
|
|
|
__qmljs_to_string(ctx, &s, left);
|
2012-09-19 19:08:47 +00:00
|
|
|
bool r = right->objectValue()->hasProperty(ctx, s.stringValue());
|
2012-05-15 08:53:20 +00:00
|
|
|
__qmljs_init_boolean(result, r);
|
2012-04-16 19:23:25 +00:00
|
|
|
} else {
|
|
|
|
__qmljs_throw_type_error(ctx, result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-11 07:38:52 +00:00
|
|
|
void __qmljs_inplace_bit_and_name(Context *ctx, String *name, Value *value)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
2012-06-11 07:38:52 +00:00
|
|
|
void __qmljs_inplace_bit_or_name(Context *ctx, String *name, Value *value)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
2012-06-11 07:38:52 +00:00
|
|
|
void __qmljs_inplace_bit_xor_name(Context *ctx, String *name, Value *value)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
2012-06-11 07:38:52 +00:00
|
|
|
void __qmljs_inplace_add_name(Context *ctx, String *name, Value *value)
|
|
|
|
{
|
|
|
|
if (Value *prop = ctx->lookupPropertyDescriptor(name))
|
|
|
|
__qmljs_add(ctx, prop, prop, value);
|
|
|
|
else
|
|
|
|
ctx->throwReferenceError(Value::fromString(name));
|
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_inplace_sub_name(Context *ctx, String *name, Value *value)
|
|
|
|
{
|
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_inplace_mul_name(Context *ctx, String *name, Value *value)
|
|
|
|
{
|
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_inplace_div_name(Context *ctx, String *name, Value *value)
|
|
|
|
{
|
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_inplace_mod_name(Context *ctx, String *name, Value *value)
|
|
|
|
{
|
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_inplace_shl_name(Context *ctx, String *name, Value *value)
|
|
|
|
{
|
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_inplace_shr_name(Context *ctx, String *name, Value *value)
|
|
|
|
{
|
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_inplace_ushr_name(Context *ctx, String *name, Value *value)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
2012-06-11 07:38:52 +00:00
|
|
|
void __qmljs_inplace_bit_and_element(Context *ctx, Value *base, Value *index, Value *value)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
2012-06-11 07:38:52 +00:00
|
|
|
void __qmljs_inplace_bit_or_element(Context *ctx, Value *base, Value *index, Value *value)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
Object *obj = base->toObject(ctx).objectValue();
|
2012-06-11 07:38:52 +00:00
|
|
|
if (ArrayObject *a = obj->asArrayObject()) {
|
|
|
|
if (index->isNumber()) {
|
|
|
|
const quint32 idx = index->toUInt32(ctx);
|
|
|
|
Value v = a->value.at(idx);
|
|
|
|
__qmljs_bit_or(ctx, &v, &v, value);
|
|
|
|
a->value.assign(idx, v);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-06-07 14:21:21 +00:00
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
2012-06-11 07:38:52 +00:00
|
|
|
void __qmljs_inplace_bit_xor_element(Context *ctx, Value *base, Value *index, Value *value)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
Object *obj = base->toObject(ctx).objectValue();
|
2012-06-11 07:38:52 +00:00
|
|
|
if (ArrayObject *a = obj->asArrayObject()) {
|
|
|
|
if (index->isNumber()) {
|
|
|
|
const quint32 idx = index->toUInt32(ctx);
|
|
|
|
Value v = a->value.at(idx);
|
|
|
|
__qmljs_bit_xor(ctx, &v, &v, value);
|
|
|
|
a->value.assign(idx, v);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-06-07 14:21:21 +00:00
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
2012-06-11 07:38:52 +00:00
|
|
|
void __qmljs_inplace_add_element(Context *ctx, Value *base, Value *index, Value *value)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
Object *obj = base->toObject(ctx).objectValue();
|
2012-06-11 07:38:52 +00:00
|
|
|
if (ArrayObject *a = obj->asArrayObject()) {
|
|
|
|
if (index->isNumber()) {
|
|
|
|
const quint32 idx = index->toUInt32(ctx);
|
|
|
|
Value v = a->value.at(idx);
|
|
|
|
__qmljs_add(ctx, &v, &v, value);
|
|
|
|
a->value.assign(idx, v);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-06-07 14:21:21 +00:00
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
2012-06-11 07:38:52 +00:00
|
|
|
void __qmljs_inplace_sub_element(Context *ctx, Value *base, Value *index, Value *value)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
Object *obj = base->toObject(ctx).objectValue();
|
2012-06-11 07:38:52 +00:00
|
|
|
if (ArrayObject *a = obj->asArrayObject()) {
|
|
|
|
if (index->isNumber()) {
|
|
|
|
const quint32 idx = index->toUInt32(ctx);
|
|
|
|
Value v = a->value.at(idx);
|
|
|
|
__qmljs_sub(ctx, &v, &v, value);
|
|
|
|
a->value.assign(idx, v);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-06-07 14:21:21 +00:00
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
2012-06-11 07:38:52 +00:00
|
|
|
void __qmljs_inplace_mul_element(Context *ctx, Value *base, Value *index, Value *value)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
2012-06-11 07:38:52 +00:00
|
|
|
void __qmljs_inplace_div_element(Context *ctx, Value *base, Value *index, Value *value)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
2012-06-11 07:38:52 +00:00
|
|
|
void __qmljs_inplace_mod_element(Context *ctx, Value *base, Value *index, Value *value)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
2012-06-11 07:38:52 +00:00
|
|
|
void __qmljs_inplace_shl_element(Context *ctx, Value *base, Value *index, Value *value)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
2012-06-11 07:38:52 +00:00
|
|
|
void __qmljs_inplace_shr_element(Context *ctx, Value *base, Value *index, Value *value)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
2012-06-11 07:38:52 +00:00
|
|
|
void __qmljs_inplace_ushr_element(Context *ctx, Value *base, Value *index, Value *value)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
2012-06-11 07:38:52 +00:00
|
|
|
void __qmljs_inplace_bit_and_member(Context *ctx, Value *base, String *name, Value *value)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
2012-06-11 07:38:52 +00:00
|
|
|
void __qmljs_inplace_bit_or_member(Context *ctx, Value *base, String *name, Value *value)
|
|
|
|
{
|
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_inplace_bit_xor_member(Context *ctx, Value *base, String *name, Value *value)
|
|
|
|
{
|
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_inplace_add_member(Context *ctx, Value *base, String *name, Value *value)
|
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
Value prop = base->objectValue()->getProperty(ctx, name);
|
2012-06-11 07:38:52 +00:00
|
|
|
__qmljs_add(ctx, &prop, &prop, value);
|
2012-09-19 19:08:47 +00:00
|
|
|
base->objectValue()->setProperty(ctx, name, prop);
|
2012-06-11 07:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_inplace_sub_member(Context *ctx, Value *base, String *name, Value *value)
|
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
Value prop = base->objectValue()->getProperty(ctx, name);
|
2012-06-11 07:38:52 +00:00
|
|
|
__qmljs_sub(ctx, &prop, &prop, value);
|
2012-09-19 19:08:47 +00:00
|
|
|
base->objectValue()->setProperty(ctx, name, prop);
|
2012-06-11 07:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_inplace_mul_member(Context *ctx, Value *base, String *name, Value *value)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
2012-06-11 07:38:52 +00:00
|
|
|
void __qmljs_inplace_div_member(Context *ctx, Value *base, String *name, Value *value)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
2012-06-11 07:38:52 +00:00
|
|
|
void __qmljs_inplace_mod_member(Context *ctx, Value *base, String *name, Value *value)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
2012-06-11 07:38:52 +00:00
|
|
|
void __qmljs_inplace_shl_member(Context *ctx, Value *base, String *name, Value *value)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
2012-06-11 07:38:52 +00:00
|
|
|
void __qmljs_inplace_shr_member(Context *ctx, Value *base, String *name, Value *value)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
2012-06-11 07:38:52 +00:00
|
|
|
void __qmljs_inplace_ushr_member(Context *ctx, Value *base, String *name, Value *value)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
2012-06-05 10:15:41 +00:00
|
|
|
String *__qmljs_string_from_utf8(Context *ctx, const char *s)
|
|
|
|
{
|
|
|
|
return ctx->engine->newString(QString::fromUtf8(s));
|
|
|
|
}
|
|
|
|
|
2012-06-07 13:28:45 +00:00
|
|
|
String *__qmljs_identifier_from_utf8(Context *ctx, const char *s)
|
|
|
|
{
|
|
|
|
return ctx->engine->identifier(QString::fromUtf8(s));
|
|
|
|
}
|
|
|
|
|
2012-04-16 19:23:25 +00:00
|
|
|
int __qmljs_string_length(Context *, String *string)
|
|
|
|
{
|
2012-05-14 14:03:10 +00:00
|
|
|
return string->toQString().length();
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double __qmljs_string_to_number(Context *, String *string)
|
|
|
|
{
|
2012-06-11 07:38:52 +00:00
|
|
|
const QString s = string->toQString();
|
|
|
|
if (s.startsWith(QLatin1String("0x")) || s.startsWith(QLatin1String("0X")))
|
|
|
|
return s.toLong(0, 16);
|
|
|
|
bool ok = false;
|
2012-05-14 14:03:10 +00:00
|
|
|
return string->toQString().toDouble(&ok); // ### TODO
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_string_from_number(Context *ctx, Value *result, double number)
|
|
|
|
{
|
2012-05-18 13:28:59 +00:00
|
|
|
String *string = ctx->engine->newString(numberToString(number, 10));
|
2012-05-15 08:53:20 +00:00
|
|
|
__qmljs_init_string(result, string);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool __qmljs_string_compare(Context *, String *left, String *right)
|
|
|
|
{
|
2012-05-14 14:03:10 +00:00
|
|
|
return left->toQString() < right->toQString();
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool __qmljs_string_equal(Context *, String *left, String *right)
|
|
|
|
{
|
2012-06-11 07:38:52 +00:00
|
|
|
return left == right || left->isEqualTo(right);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String *__qmljs_string_concat(Context *ctx, String *first, String *second)
|
|
|
|
{
|
2012-05-15 08:58:22 +00:00
|
|
|
return ctx->engine->newString(first->toQString() + second->toQString());
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool __qmljs_is_function(Context *, const Value *value)
|
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
return value->objectValue()->asFunctionObject() != 0;
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-05-18 13:28:59 +00:00
|
|
|
void __qmljs_object_default_value(Context *ctx, Value *result, const Value *object, int typeHint)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-05-18 13:28:59 +00:00
|
|
|
if (typeHint == PREFERREDTYPE_HINT) {
|
|
|
|
if (object->isDateObject())
|
|
|
|
typeHint = STRING_HINT;
|
|
|
|
else
|
|
|
|
typeHint = NUMBER_HINT;
|
|
|
|
}
|
|
|
|
|
|
|
|
String *meth1 = ctx->engine->identifier("toString");
|
|
|
|
String *meth2 = ctx->engine->identifier("valueOf");
|
|
|
|
|
|
|
|
if (typeHint == NUMBER_HINT)
|
|
|
|
qSwap(meth1, meth2);
|
|
|
|
|
2012-05-20 17:59:47 +00:00
|
|
|
Object *oo = object->asObject();
|
|
|
|
assert(oo != 0);
|
2012-05-25 15:45:15 +00:00
|
|
|
|
2012-05-25 10:54:36 +00:00
|
|
|
Value conv = oo->getProperty(ctx, meth1);
|
|
|
|
if (!conv.isUndefined() && conv.isFunctionObject()) {
|
2012-05-18 13:28:59 +00:00
|
|
|
Value r;
|
2012-05-25 10:54:36 +00:00
|
|
|
__qmljs_call_value(ctx, &r, object, &conv, 0, 0);
|
2012-05-18 13:28:59 +00:00
|
|
|
if (r.isPrimitive()) {
|
|
|
|
*result = r;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-25 10:54:36 +00:00
|
|
|
conv = oo->getProperty(ctx, meth2);
|
|
|
|
if (!conv.isUndefined() && conv.isFunctionObject()) {
|
2012-05-18 13:28:59 +00:00
|
|
|
Value r;
|
2012-05-25 10:54:36 +00:00
|
|
|
__qmljs_call_value(ctx, &r, object, &conv, 0, 0);
|
2012-05-18 13:28:59 +00:00
|
|
|
if (r.isPrimitive()) {
|
|
|
|
*result = r;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-20 17:59:47 +00:00
|
|
|
__qmljs_init_undefined(result);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_throw_type_error(Context *ctx, Value *result)
|
|
|
|
{
|
2012-05-24 08:01:17 +00:00
|
|
|
ctx->throwTypeError();
|
|
|
|
if (result)
|
|
|
|
*result = ctx->result;
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-06-07 13:28:45 +00:00
|
|
|
void __qmljs_new_object(Context *ctx, Value *result)
|
|
|
|
{
|
|
|
|
__qmljs_init_object(result, ctx->engine->newObject());
|
|
|
|
}
|
|
|
|
|
2012-04-16 19:23:25 +00:00
|
|
|
void __qmljs_new_boolean_object(Context *ctx, Value *result, bool boolean)
|
|
|
|
{
|
|
|
|
Value value;
|
2012-05-15 08:53:20 +00:00
|
|
|
__qmljs_init_boolean(&value, boolean);
|
|
|
|
__qmljs_init_object(result, ctx->engine->newBooleanObject(value));
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_new_number_object(Context *ctx, Value *result, double number)
|
|
|
|
{
|
|
|
|
Value value;
|
2012-05-15 08:53:20 +00:00
|
|
|
__qmljs_init_number(&value, number);
|
|
|
|
__qmljs_init_object(result, ctx->engine->newNumberObject(value));
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_new_string_object(Context *ctx, Value *result, String *string)
|
|
|
|
{
|
|
|
|
Value value;
|
2012-05-15 08:53:20 +00:00
|
|
|
__qmljs_init_string(&value, string);
|
|
|
|
__qmljs_init_object(result, ctx->engine->newStringObject(value));
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_set_property(Context *ctx, Value *object, String *name, Value *value)
|
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
object->objectValue()->setProperty(ctx, name, *value, /*flags*/ 0);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-05-03 16:06:23 +00:00
|
|
|
void __qmljs_set_property_boolean(Context *ctx, Value *object, String *name, bool number)
|
|
|
|
{
|
|
|
|
Value value;
|
2012-05-15 08:53:20 +00:00
|
|
|
__qmljs_init_boolean(&value, number);
|
2012-09-19 19:08:47 +00:00
|
|
|
object->objectValue()->setProperty(ctx, name, value, /*flag*/ 0);
|
2012-05-03 16:06:23 +00:00
|
|
|
}
|
|
|
|
|
2012-04-16 19:23:25 +00:00
|
|
|
void __qmljs_set_property_number(Context *ctx, Value *object, String *name, double number)
|
|
|
|
{
|
2012-05-16 14:19:55 +00:00
|
|
|
Q_UNUSED(ctx);
|
2012-04-16 19:23:25 +00:00
|
|
|
Value value;
|
2012-05-15 08:53:20 +00:00
|
|
|
__qmljs_init_number(&value, number);
|
2012-09-19 19:08:47 +00:00
|
|
|
object->objectValue()->setProperty(ctx, name, value, /*flag*/ 0);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_set_property_string(Context *ctx, Value *object, String *name, String *s)
|
|
|
|
{
|
2012-05-16 14:19:55 +00:00
|
|
|
Q_UNUSED(ctx);
|
2012-04-16 19:23:25 +00:00
|
|
|
Value value;
|
2012-05-15 08:53:20 +00:00
|
|
|
__qmljs_init_string(&value, s);
|
2012-09-19 19:08:47 +00:00
|
|
|
object->objectValue()->setProperty(ctx, name, value, /*flag*/ 0);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-05-09 09:28:57 +00:00
|
|
|
void __qmljs_set_property_closure(Context *ctx, Value *object, String *name, IR::Function *function)
|
|
|
|
{
|
|
|
|
Value value;
|
2012-05-13 11:50:55 +00:00
|
|
|
__qmljs_init_closure(ctx, &value, function);
|
2012-09-19 19:08:47 +00:00
|
|
|
object->objectValue()->setProperty(ctx, name, value, /*flag*/ 0);
|
2012-05-09 09:28:57 +00:00
|
|
|
}
|
|
|
|
|
2012-05-20 17:59:47 +00:00
|
|
|
void __qmljs_get_element(Context *ctx, Value *result, Value *object, Value *index)
|
|
|
|
{
|
|
|
|
if (object->isString() && index->isNumber()) {
|
2012-09-19 19:08:47 +00:00
|
|
|
const QString s = object->stringValue()->toQString().mid(Value::toUInt32(index->doubleValue()), 1);
|
2012-05-20 17:59:47 +00:00
|
|
|
if (s.isNull())
|
|
|
|
__qmljs_init_undefined(result);
|
|
|
|
else
|
|
|
|
*result = Value::fromString(ctx, s);
|
|
|
|
} else if (object->isArrayObject() && index->isNumber()) {
|
2012-09-19 19:08:47 +00:00
|
|
|
*result = object->asArrayObject()->value.at(Value::toUInt32(index->doubleValue()));
|
2012-05-20 17:59:47 +00:00
|
|
|
} else {
|
|
|
|
String *name = index->toString(ctx);
|
|
|
|
|
|
|
|
if (! object->isObject())
|
|
|
|
__qmljs_to_object(ctx, object, object);
|
|
|
|
|
2012-05-25 10:54:36 +00:00
|
|
|
*result = object->property(ctx, name);
|
2012-05-20 17:59:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_set_element(Context *ctx, Value *object, Value *index, Value *value)
|
|
|
|
{
|
|
|
|
if (object->isArrayObject() && index->isNumber()) {
|
2012-09-19 19:08:47 +00:00
|
|
|
object->asArrayObject()->value.assign(Value::toUInt32(index->doubleValue()), *value);
|
2012-05-20 17:59:47 +00:00
|
|
|
} else {
|
|
|
|
String *name = index->toString(ctx);
|
|
|
|
|
|
|
|
if (! object->isObject())
|
|
|
|
__qmljs_to_object(ctx, object, object);
|
|
|
|
|
2012-09-19 19:08:47 +00:00
|
|
|
object->objectValue()->setProperty(ctx, name, *value, /*flags*/ 0);
|
2012-05-20 17:59:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_set_element_number(Context *ctx, Value *object, Value *index, double number)
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
__qmljs_init_number(&v, number);
|
|
|
|
__qmljs_set_element(ctx, object, index, &v);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_set_activation_element(Context *ctx, String *name, Value *index, Value *value)
|
|
|
|
{
|
2012-05-25 10:54:36 +00:00
|
|
|
if (Value *base = ctx->lookupPropertyDescriptor(name)) {
|
2012-05-20 17:59:47 +00:00
|
|
|
__qmljs_set_element(ctx, base, index, value);
|
|
|
|
} else {
|
2012-05-25 09:55:50 +00:00
|
|
|
ctx->throwReferenceError(Value::fromString(name));
|
2012-05-20 17:59:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-16 19:23:25 +00:00
|
|
|
void __qmljs_set_activation_property(Context *ctx, String *name, Value *value)
|
|
|
|
{
|
2012-05-25 10:54:36 +00:00
|
|
|
if (Value *prop = ctx->lookupPropertyDescriptor(name)) {
|
2012-05-16 14:19:55 +00:00
|
|
|
*prop = *value;
|
|
|
|
} else
|
2012-09-19 19:08:47 +00:00
|
|
|
ctx->engine->globalObject.objectValue()->setProperty(ctx, name, *value);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-05-04 11:03:14 +00:00
|
|
|
void __qmljs_copy_activation_property(Context *ctx, String *name, String *other)
|
|
|
|
{
|
2012-05-25 10:54:36 +00:00
|
|
|
if (Value *source = ctx->lookupPropertyDescriptor(other))
|
2012-05-13 11:50:55 +00:00
|
|
|
__qmljs_set_activation_property(ctx, name, source);
|
|
|
|
else
|
2012-05-25 09:55:50 +00:00
|
|
|
ctx->throwReferenceError(Value::fromString(name));
|
2012-05-04 11:03:14 +00:00
|
|
|
}
|
|
|
|
|
2012-05-13 11:50:55 +00:00
|
|
|
void __qmljs_set_activation_property_boolean(Context *ctx, String *name, bool b)
|
2012-05-03 16:06:23 +00:00
|
|
|
{
|
2012-05-13 11:50:55 +00:00
|
|
|
Value value;
|
2012-05-15 08:53:20 +00:00
|
|
|
__qmljs_init_boolean(&value, b);
|
2012-05-13 11:50:55 +00:00
|
|
|
__qmljs_set_activation_property(ctx, name, &value);
|
2012-05-03 16:06:23 +00:00
|
|
|
}
|
|
|
|
|
2012-05-13 11:50:55 +00:00
|
|
|
void __qmljs_set_activation_property_number(Context *ctx, String *name, double number)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-05-13 11:50:55 +00:00
|
|
|
Value value;
|
2012-05-15 08:53:20 +00:00
|
|
|
__qmljs_init_number(&value, number);
|
2012-05-13 11:50:55 +00:00
|
|
|
__qmljs_set_activation_property(ctx, name, &value);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-05-13 11:50:55 +00:00
|
|
|
void __qmljs_set_activation_property_string(Context *ctx, String *name, String *string)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-05-13 11:50:55 +00:00
|
|
|
Value value;
|
2012-05-15 08:53:20 +00:00
|
|
|
__qmljs_init_string(&value, string);
|
2012-05-13 11:50:55 +00:00
|
|
|
__qmljs_set_activation_property(ctx, name, &value);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-05-13 11:50:55 +00:00
|
|
|
void __qmljs_set_activation_property_closure(Context *ctx, String *name, IR::Function *clos)
|
2012-05-09 09:28:57 +00:00
|
|
|
{
|
2012-05-13 11:50:55 +00:00
|
|
|
Value value;
|
|
|
|
__qmljs_init_closure(ctx, &value, clos);
|
|
|
|
__qmljs_set_activation_property(ctx, name, &value);
|
2012-05-09 09:28:57 +00:00
|
|
|
}
|
|
|
|
|
2012-04-16 19:23:25 +00:00
|
|
|
void __qmljs_get_property(Context *ctx, Value *result, Value *object, String *name)
|
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
if (object->isObject()) {
|
2012-05-25 10:54:36 +00:00
|
|
|
*result = object->property(ctx, name);
|
2012-09-19 19:08:47 +00:00
|
|
|
} else if (object->isString() && name->isEqualTo(ctx->engine->id_length)) {
|
|
|
|
__qmljs_init_number(result, object->stringValue()->toQString().length());
|
2012-05-09 09:04:57 +00:00
|
|
|
} else {
|
|
|
|
Value o;
|
|
|
|
__qmljs_to_object(ctx, &o, object);
|
2012-05-28 19:49:20 +00:00
|
|
|
|
2012-05-25 09:55:50 +00:00
|
|
|
if (o.isObject())
|
|
|
|
__qmljs_get_property(ctx, result, &o, name);
|
|
|
|
else
|
2012-05-28 19:49:20 +00:00
|
|
|
ctx->throwTypeError(); // ### not necessary.
|
2012-05-09 09:04:57 +00:00
|
|
|
}
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_get_activation_property(Context *ctx, Value *result, String *name)
|
|
|
|
{
|
2012-05-25 10:54:36 +00:00
|
|
|
if (Value *prop = ctx->lookupPropertyDescriptor(name))
|
2012-05-13 11:50:55 +00:00
|
|
|
*result = *prop;
|
|
|
|
else
|
2012-05-25 09:55:50 +00:00
|
|
|
ctx->throwReferenceError(Value::fromString(name));
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_get_activation(Context *ctx, Value *result)
|
|
|
|
{
|
|
|
|
*result = ctx->activation;
|
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_get_thisObject(Context *ctx, Value *result)
|
|
|
|
{
|
2012-05-28 19:49:20 +00:00
|
|
|
if (ctx->thisObject.isObject())
|
|
|
|
*result = ctx->thisObject;
|
|
|
|
else
|
|
|
|
*result = ctx->engine->globalObject;
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_compare(Context *ctx, Value *result, const Value *x, const Value *y, bool leftFirst)
|
|
|
|
{
|
|
|
|
Value px, py;
|
|
|
|
|
|
|
|
if (leftFirst) {
|
|
|
|
__qmljs_to_primitive(ctx, &px, x, NUMBER_HINT);
|
|
|
|
__qmljs_to_primitive(ctx, &py, y, NUMBER_HINT);
|
|
|
|
} else {
|
|
|
|
__qmljs_to_primitive(ctx, &py, x, NUMBER_HINT);
|
|
|
|
__qmljs_to_primitive(ctx, &px, y, NUMBER_HINT);
|
|
|
|
}
|
|
|
|
|
2012-09-19 19:08:47 +00:00
|
|
|
if (px.isString() && py.isString()) {
|
|
|
|
bool r = __qmljs_string_compare(ctx, px.stringValue(), py.stringValue());
|
2012-05-15 08:53:20 +00:00
|
|
|
__qmljs_init_boolean(result, r);
|
2012-04-16 19:23:25 +00:00
|
|
|
} else {
|
|
|
|
double nx = __qmljs_to_number(ctx, &px);
|
|
|
|
double ny = __qmljs_to_number(ctx, &py);
|
|
|
|
if (isnan(nx) || isnan(ny)) {
|
2012-05-15 08:53:20 +00:00
|
|
|
__qmljs_init_undefined(result);
|
2012-04-16 19:23:25 +00:00
|
|
|
} else {
|
2012-05-15 08:53:20 +00:00
|
|
|
__qmljs_init_boolean(result, nx < ny);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool __qmljs_equal(Context *ctx, const Value *x, const Value *y)
|
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
if (x->type() == y->type()) {
|
|
|
|
switch (x->type()) {
|
|
|
|
case Value::Undefined_Type:
|
2012-04-16 19:23:25 +00:00
|
|
|
return true;
|
2012-09-19 19:08:47 +00:00
|
|
|
case Value::Null_Type:
|
2012-04-16 19:23:25 +00:00
|
|
|
return true;
|
2012-09-19 19:08:47 +00:00
|
|
|
case Value::Boolean_Type:
|
|
|
|
return x->booleanValue() == y->booleanValue();
|
2012-04-16 19:23:25 +00:00
|
|
|
break;
|
2012-09-19 19:08:47 +00:00
|
|
|
case Value::String_Type:
|
|
|
|
return __qmljs_string_equal(ctx, x->stringValue(), y->stringValue());
|
|
|
|
case Value::Object_Type:
|
|
|
|
return x->objectValue() == y->objectValue();
|
|
|
|
default: // double
|
|
|
|
return x->doubleValue() == y->doubleValue();
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
// unreachable
|
|
|
|
} else {
|
2012-09-19 19:08:47 +00:00
|
|
|
if (x->isNumber() && y->isNumber())
|
|
|
|
return x == y;
|
|
|
|
if (x->isNull() && y->isUndefined()) {
|
2012-04-16 19:23:25 +00:00
|
|
|
return true;
|
2012-09-19 19:08:47 +00:00
|
|
|
} else if (x->isUndefined() && y->isNull()) {
|
2012-04-16 19:23:25 +00:00
|
|
|
return true;
|
2012-09-19 19:08:47 +00:00
|
|
|
} else if (x->isNumber() && y->isString()) {
|
2012-04-16 19:23:25 +00:00
|
|
|
Value ny;
|
2012-05-15 08:53:20 +00:00
|
|
|
__qmljs_init_number(&ny, __qmljs_to_number(ctx, y));
|
2012-04-16 19:23:25 +00:00
|
|
|
return __qmljs_equal(ctx, x, &ny);
|
2012-09-19 19:08:47 +00:00
|
|
|
} else if (x->isString() && y->isNumber()) {
|
2012-04-16 19:23:25 +00:00
|
|
|
Value nx;
|
2012-05-15 08:53:20 +00:00
|
|
|
__qmljs_init_number(&nx, __qmljs_to_number(ctx, x));
|
2012-04-16 19:23:25 +00:00
|
|
|
return __qmljs_equal(ctx, &nx, y);
|
2012-09-19 19:08:47 +00:00
|
|
|
} else if (x->isBoolean()) {
|
2012-04-16 19:23:25 +00:00
|
|
|
Value nx;
|
2012-09-19 19:08:47 +00:00
|
|
|
__qmljs_init_number(&nx, (double) x->booleanValue());
|
2012-04-16 19:23:25 +00:00
|
|
|
return __qmljs_equal(ctx, &nx, y);
|
2012-09-19 19:08:47 +00:00
|
|
|
} else if (y->isBoolean()) {
|
2012-04-16 19:23:25 +00:00
|
|
|
Value ny;
|
2012-09-19 19:08:47 +00:00
|
|
|
__qmljs_init_number(&ny, (double) y->booleanValue());
|
2012-04-16 19:23:25 +00:00
|
|
|
return __qmljs_equal(ctx, x, &ny);
|
2012-09-19 19:08:47 +00:00
|
|
|
} else if ((x->isNumber() || x->isString()) && y->isObject()) {
|
2012-04-16 19:23:25 +00:00
|
|
|
Value py;
|
|
|
|
__qmljs_to_primitive(ctx, &py, y, PREFERREDTYPE_HINT);
|
|
|
|
return __qmljs_equal(ctx, x, &py);
|
2012-09-19 19:08:47 +00:00
|
|
|
} else if (x->isObject() && (y->isNumber() || y->isString())) {
|
2012-04-16 19:23:25 +00:00
|
|
|
Value px;
|
|
|
|
__qmljs_to_primitive(ctx, &px, x, PREFERREDTYPE_HINT);
|
|
|
|
return __qmljs_equal(ctx, &px, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-05-13 11:50:55 +00:00
|
|
|
void __qmljs_call_activation_property(Context *context, Value *result, String *name, Value *args, int argc)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-05-25 10:54:36 +00:00
|
|
|
Value *func = context->lookupPropertyDescriptor(name);
|
2012-05-13 11:50:55 +00:00
|
|
|
if (! func)
|
2012-05-25 09:55:50 +00:00
|
|
|
context->throwReferenceError(Value::fromString(name));
|
|
|
|
else
|
|
|
|
__qmljs_call_value(context, result, /*thisObject=*/ 0, func, args, argc);
|
2012-05-09 10:00:30 +00:00
|
|
|
}
|
|
|
|
|
2012-05-13 11:50:55 +00:00
|
|
|
void __qmljs_call_property(Context *context, Value *result, const Value *base, String *name, Value *args, int argc)
|
2012-05-07 14:05:05 +00:00
|
|
|
{
|
2012-05-09 15:04:25 +00:00
|
|
|
Value baseObject;
|
|
|
|
Value thisObject;
|
|
|
|
if (base) {
|
2012-05-09 15:28:55 +00:00
|
|
|
baseObject = *base;
|
2012-09-19 19:08:47 +00:00
|
|
|
if (!baseObject.isObject())
|
2012-05-09 15:28:55 +00:00
|
|
|
__qmljs_to_object(context, &baseObject, &baseObject);
|
2012-09-19 19:08:47 +00:00
|
|
|
assert(baseObject.isObject());
|
2012-05-09 15:04:25 +00:00
|
|
|
thisObject = baseObject;
|
|
|
|
} else {
|
|
|
|
baseObject = context->activation;
|
2012-05-15 08:53:20 +00:00
|
|
|
__qmljs_init_null(&thisObject);
|
2012-05-09 15:04:25 +00:00
|
|
|
}
|
2012-05-25 10:54:36 +00:00
|
|
|
Value func = baseObject.property(context, name);
|
|
|
|
if (FunctionObject *f = func.asFunctionObject()) {
|
|
|
|
Context k;
|
|
|
|
Context *ctx = f->needsActivation ? context->engine->newContext() : &k;
|
|
|
|
ctx->initCallContext(context->engine, &thisObject, f, args, argc);
|
|
|
|
f->call(ctx);
|
|
|
|
if (ctx->hasUncaughtException) {
|
|
|
|
context->hasUncaughtException = ctx->hasUncaughtException; // propagate the exception
|
|
|
|
context->result = ctx->result;
|
2012-05-09 13:47:55 +00:00
|
|
|
}
|
2012-05-25 10:54:36 +00:00
|
|
|
ctx->leaveCallContext(f, result);
|
2012-05-09 13:47:55 +00:00
|
|
|
} else {
|
2012-05-25 09:55:50 +00:00
|
|
|
context->throwTypeError();
|
2012-05-09 13:47:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-18 13:28:59 +00:00
|
|
|
void __qmljs_call_value(Context *context, Value *result, const Value *thisObject, const Value *func, Value *args, int argc)
|
2012-05-09 13:47:55 +00:00
|
|
|
{
|
2012-05-25 10:54:36 +00:00
|
|
|
if (FunctionObject *f = func->asFunctionObject()) {
|
|
|
|
Context k;
|
|
|
|
Context *ctx = f->needsActivation ? context->engine->newContext() : &k;
|
|
|
|
ctx->initCallContext(context->engine, thisObject, f, args, argc);
|
|
|
|
f->call(ctx);
|
|
|
|
if (ctx->hasUncaughtException) {
|
|
|
|
context->hasUncaughtException = ctx->hasUncaughtException; // propagate the exception
|
|
|
|
context->result = ctx->result;
|
2012-05-09 09:04:57 +00:00
|
|
|
}
|
2012-05-25 10:54:36 +00:00
|
|
|
ctx->leaveCallContext(f, result);
|
2012-05-09 09:04:57 +00:00
|
|
|
} else {
|
2012-05-25 09:55:50 +00:00
|
|
|
context->throwTypeError();
|
2012-05-09 09:04:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-13 11:50:55 +00:00
|
|
|
void __qmljs_construct_activation_property(Context *context, Value *result, String *name, Value *args, int argc)
|
2012-05-09 13:06:30 +00:00
|
|
|
{
|
2012-05-25 10:54:36 +00:00
|
|
|
Value *func = context->lookupPropertyDescriptor(name);
|
2012-05-13 11:50:55 +00:00
|
|
|
if (! func)
|
2012-05-25 09:55:50 +00:00
|
|
|
context->throwReferenceError(Value::fromString(name));
|
|
|
|
else
|
|
|
|
__qmljs_construct_value(context, result, func, args, argc);
|
2012-05-13 11:50:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_construct_value(Context *context, Value *result, const Value *func, Value *args, int argc)
|
|
|
|
{
|
2012-05-25 10:54:36 +00:00
|
|
|
if (FunctionObject *f = func->asFunctionObject()) {
|
|
|
|
Context k;
|
|
|
|
Context *ctx = f->needsActivation ? context->engine->newContext() : &k;
|
|
|
|
ctx->initConstructorContext(context->engine, 0, f, args, argc);
|
|
|
|
f->construct(ctx);
|
|
|
|
if (ctx->hasUncaughtException) {
|
|
|
|
context->hasUncaughtException = ctx->hasUncaughtException; // propagate the exception
|
|
|
|
context->result = ctx->result;
|
2012-05-13 11:50:55 +00:00
|
|
|
}
|
2012-05-25 10:54:36 +00:00
|
|
|
ctx->leaveConstructorContext(f, result);
|
2012-05-13 11:50:55 +00:00
|
|
|
} else {
|
2012-05-25 09:55:50 +00:00
|
|
|
context->throwTypeError();
|
2012-05-13 11:50:55 +00:00
|
|
|
}
|
2012-05-09 13:06:30 +00:00
|
|
|
}
|
|
|
|
|
2012-05-13 11:50:55 +00:00
|
|
|
void __qmljs_construct_property(Context *context, Value *result, const Value *base, String *name, Value *args, int argc)
|
2012-05-09 09:04:57 +00:00
|
|
|
{
|
2012-05-09 13:06:30 +00:00
|
|
|
Value thisObject = *base;
|
2012-09-19 19:08:47 +00:00
|
|
|
if (!thisObject.isObject())
|
2012-05-09 13:06:30 +00:00
|
|
|
__qmljs_to_object(context, &thisObject, base);
|
|
|
|
|
2012-09-19 19:08:47 +00:00
|
|
|
assert(thisObject.isObject());
|
2012-05-25 10:54:36 +00:00
|
|
|
Value func = thisObject.property(context, name);
|
|
|
|
if (FunctionObject *f = func.asFunctionObject()) {
|
|
|
|
Context k;
|
|
|
|
Context *ctx = f->needsActivation ? context->engine->newContext() : &k;
|
|
|
|
ctx->initConstructorContext(context->engine, 0, f, args, argc);
|
|
|
|
ctx->calledAsConstructor = true;
|
|
|
|
f->construct(ctx);
|
|
|
|
if (ctx->hasUncaughtException) {
|
|
|
|
context->hasUncaughtException = ctx->hasUncaughtException; // propagate the exception
|
|
|
|
context->result = ctx->result;
|
2012-05-07 14:05:05 +00:00
|
|
|
}
|
2012-05-25 10:54:36 +00:00
|
|
|
ctx->leaveConstructorContext(f, result);
|
2012-05-07 14:05:05 +00:00
|
|
|
} else {
|
2012-05-25 09:55:50 +00:00
|
|
|
context->throwTypeError();
|
2012-05-07 14:05:05 +00:00
|
|
|
}
|
|
|
|
}
|
2012-04-16 19:23:25 +00:00
|
|
|
|
2012-06-06 13:30:50 +00:00
|
|
|
void __qmljs_throw(Context *context, Value *value)
|
|
|
|
{
|
|
|
|
context->hasUncaughtException = true;
|
|
|
|
context->result = *value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_rethrow(Context *context, Value *result)
|
|
|
|
{
|
|
|
|
*result = context->result;
|
|
|
|
}
|
|
|
|
|
2012-05-23 16:48:48 +00:00
|
|
|
void __qmljs_builtin_typeof(Context *context, Value *result, Value *args, int argc)
|
|
|
|
{
|
|
|
|
Q_UNUSED(argc);
|
|
|
|
__qmljs_typeof(context, result, &args[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_builtin_throw(Context *context, Value *result, Value *args, int argc)
|
|
|
|
{
|
|
|
|
Q_UNUSED(argc);
|
2012-05-25 09:55:50 +00:00
|
|
|
Q_UNUSED(result);
|
2012-06-06 13:30:50 +00:00
|
|
|
__qmljs_throw(context, &args[0]);
|
2012-05-23 16:48:48 +00:00
|
|
|
}
|
|
|
|
|
2012-05-25 09:55:50 +00:00
|
|
|
void __qmljs_builtin_rethrow(Context *context, Value *result, Value *, int)
|
|
|
|
{
|
2012-06-06 13:30:50 +00:00
|
|
|
__qmljs_rethrow(context, result);
|
2012-05-25 09:55:50 +00:00
|
|
|
}
|
2012-05-23 16:48:48 +00:00
|
|
|
|
2012-04-16 19:23:25 +00:00
|
|
|
} // extern "C"
|
2012-05-04 18:22:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace VM
|
|
|
|
} // namespace QQmlJS
|