VM::Context *ctx = vm->rootContext;
globalObject->put(vm->identifier(QLatin1String("print")),
- VM::Value::object(ctx, new builtins::Print(ctx)));
+ VM::Value::fromObject(new builtins::Print(ctx)));
foreach (IR::Function *function, module.functions) {
if (function->name && ! function->name->isEmpty()) {
globalObject->put(vm->identifier(*function->name),
- VM::Value::object(ctx, ctx->engine->newScriptFunction(ctx, function)));
+ VM::Value::fromObject(ctx->engine->newScriptFunction(ctx, function)));
}
}
codeByName.value(QLatin1String("%entry"))->code(ctx);
void Object::setProperty(Context *ctx, const QString &name, void (*code)(Context *), int count)
{
Q_UNUSED(count);
- setProperty(ctx, name, Value::object(ctx, ctx->engine->newNativeFunction(ctx, code)));
+ setProperty(ctx, name, Value::fromObject(ctx->engine->newNativeFunction(ctx, code)));
}
bool Object::get(String *name, Value *result)
return true;
}
- __qmljs_init_undefined(0, result);
+ __qmljs_init_undefined(result);
return false;
}
{
if (typeHint == STRING_HINT) {
if (asFunctionObject() != 0)
- __qmljs_init_string(ctx, result, ctx->engine->identifier(QLatin1String("function")));
+ __qmljs_init_string(result, ctx->engine->identifier(QLatin1String("function")));
else
- __qmljs_init_string(ctx, result, ctx->engine->identifier(QLatin1String("object")));
+ __qmljs_init_string(result, ctx->engine->identifier(QLatin1String("object")));
} else {
- __qmljs_init_undefined(ctx, result);
+ __qmljs_init_undefined(result);
}
}
void FunctionObject::construct(Context *ctx)
{
- __qmljs_init_object(ctx, &ctx->thisObject, ctx->engine->newObject());
+ __qmljs_init_object(&ctx->thisObject, ctx->engine->newObject());
call(ctx);
}
void ScriptFunction::construct(VM::Context *ctx)
{
- __qmljs_init_object(ctx, &ctx->thisObject, ctx->engine->newObject());
+ __qmljs_init_object(&ctx->thisObject, ctx->engine->newObject());
function->code(ctx);
}
// set up the global object
//
VM::Object *glo = newArgumentsObject(rootContext);
- __qmljs_init_object(rootContext, &globalObject, glo);
- __qmljs_init_object(rootContext, &rootContext->activation, glo);
+ __qmljs_init_object(&globalObject, glo);
+ __qmljs_init_object(&rootContext->activation, glo);
objectCtor = ObjectCtor::create(this);
stringCtor = StringCtor::create(this);
stringCtor.objectValue->get(prototype, &stringPrototype);
numberCtor.objectValue->get(prototype, &numberPrototype);
- glo->put(VM::String::get(rootContext, QLatin1String("Object")), objectCtor);
- glo->put(VM::String::get(rootContext, QLatin1String("String")), stringCtor);
- glo->put(VM::String::get(rootContext, QLatin1String("Number")), numberCtor);
- glo->put(VM::String::get(rootContext, QLatin1String("Math")), Value::object(rootContext, newMathObject(rootContext)));
+ glo->put(identifier(QLatin1String("Object")), objectCtor);
+ glo->put(identifier(QLatin1String("String")), stringCtor);
+ glo->put(identifier(QLatin1String("Number")), numberCtor);
+ glo->put(identifier(QLatin1String("Math")), Value::fromObject(newMathObject(rootContext)));
}
Context *ExecutionEngine::newContext()
if (index < argumentCount)
*result = arguments[index];
else
- __qmljs_init_undefined(this, result);
+ __qmljs_init_undefined(result);
}
void init(ExecutionEngine *eng)
namespace QQmlJS {
namespace VM {
-Value Value::string(Context *ctx, const QString &s)
+Value Value::fromString(Context *ctx, const QString &s)
{
- return string(ctx, String::get(ctx, s));
+ return fromString(ctx->engine->newString(s));
}
int Value::toInt32(double number)
void __qmljs_init_closure(Context *ctx, Value *result, IR::Function *clos)
{
- __qmljs_init_object(ctx, result, ctx->engine->newScriptFunction(ctx, clos));
+ __qmljs_init_object(result, ctx->engine->newScriptFunction(ctx, clos));
}
void __qmljs_string_literal_undefined(Context *ctx, Value *result)
{
- __qmljs_init_string(ctx, result, ctx->engine->identifier(QLatin1String("undefined")));
+ __qmljs_init_string(result, ctx->engine->identifier(QLatin1String("undefined")));
}
void __qmljs_string_literal_null(Context *ctx, Value *result)
{
- __qmljs_init_string(ctx, result, ctx->engine->identifier(QLatin1String("null")));
+ __qmljs_init_string(result, ctx->engine->identifier(QLatin1String("null")));
}
void __qmljs_string_literal_true(Context *ctx, Value *result)
{
- __qmljs_init_string(ctx, result, ctx->engine->identifier(QLatin1String("true")));
+ __qmljs_init_string(result, ctx->engine->identifier(QLatin1String("true")));
}
void __qmljs_string_literal_false(Context *ctx, Value *result)
{
- __qmljs_init_string(ctx, result, ctx->engine->identifier(QLatin1String("false")));
+ __qmljs_init_string(result, ctx->engine->identifier(QLatin1String("false")));
}
void __qmljs_string_literal_object(Context *ctx, Value *result)
{
- __qmljs_init_string(ctx, result, ctx->engine->identifier(QLatin1String("object")));
+ __qmljs_init_string(result, ctx->engine->identifier(QLatin1String("object")));
}
void __qmljs_string_literal_boolean(Context *ctx, Value *result)
{
- __qmljs_init_string(ctx, result, ctx->engine->identifier(QLatin1String("boolean")));
+ __qmljs_init_string(result, ctx->engine->identifier(QLatin1String("boolean")));
}
void __qmljs_string_literal_number(Context *ctx, Value *result)
{
- __qmljs_init_string(ctx, result, ctx->engine->identifier(QLatin1String("number")));
+ __qmljs_init_string(result, ctx->engine->identifier(QLatin1String("number")));
}
void __qmljs_string_literal_string(Context *ctx, Value *result)
{
- __qmljs_init_string(ctx, result, ctx->engine->identifier(QLatin1String("string")));
+ __qmljs_init_string(result, ctx->engine->identifier(QLatin1String("string")));
}
void __qmljs_string_literal_function(Context *ctx, Value *result)
{
- __qmljs_init_string(ctx, result, ctx->engine->identifier(QLatin1String("function")));
+ __qmljs_init_string(result, ctx->engine->identifier(QLatin1String("function")));
}
void __qmljs_delete(Context *ctx, Value *result, const Value *value)
if (right->type == OBJECT_TYPE) {
if (FunctionObject *function = right->objectValue->asFunctionObject()) {
bool r = function->hasInstance(*left);
- __qmljs_init_boolean(ctx, result, r);
+ __qmljs_init_boolean(result, r);
return;
}
}
Value s;
__qmljs_to_string(ctx, &s, left);
bool r = right->objectValue->hasProperty(s.stringValue);
- __qmljs_init_boolean(ctx, result, r);
+ __qmljs_init_boolean(result, r);
} else {
__qmljs_throw_type_error(ctx, result);
}
void __qmljs_string_from_number(Context *ctx, Value *result, double number)
{
String *string = String::get(ctx, QString::number(number, 'g', 16));
- __qmljs_init_string(ctx, result, string);
+ __qmljs_init_string(result, string);
}
bool __qmljs_string_compare(Context *, String *left, String *right)
void __qmljs_throw_type_error(Context *ctx, Value *result)
{
- __qmljs_init_object(ctx, result, ctx->engine->newErrorObject(Value::string(ctx, QLatin1String("type error"))));
+ __qmljs_init_object(result, ctx->engine->newErrorObject(Value::fromString(ctx, QLatin1String("type error"))));
}
void __qmljs_new_boolean_object(Context *ctx, Value *result, bool boolean)
{
Value value;
- __qmljs_init_boolean(ctx, &value, boolean);
- __qmljs_init_object(ctx, result, ctx->engine->newBooleanObject(value));
+ __qmljs_init_boolean(&value, boolean);
+ __qmljs_init_object(result, ctx->engine->newBooleanObject(value));
}
void __qmljs_new_number_object(Context *ctx, Value *result, double number)
{
Value value;
- __qmljs_init_number(ctx, &value, number);
- __qmljs_init_object(ctx, result, ctx->engine->newNumberObject(value));
+ __qmljs_init_number(&value, number);
+ __qmljs_init_object(result, ctx->engine->newNumberObject(value));
result->objectValue->prototype = ctx->engine->numberPrototype.objectValue;
}
void __qmljs_new_string_object(Context *ctx, Value *result, String *string)
{
Value value;
- __qmljs_init_string(ctx, &value, string);
- __qmljs_init_object(ctx, result, ctx->engine->newStringObject(value));
+ __qmljs_init_string(&value, string);
+ __qmljs_init_object(result, ctx->engine->newStringObject(value));
result->objectValue->prototype = ctx->engine->stringPrototype.objectValue;
}
void __qmljs_set_property_boolean(Context *ctx, Value *object, String *name, bool number)
{
Value value;
- __qmljs_init_boolean(ctx, &value, number);
+ __qmljs_init_boolean(&value, number);
object->objectValue->put(name, value, /*flag*/ 0);
}
void __qmljs_set_property_number(Context *ctx, Value *object, String *name, double number)
{
Value value;
- __qmljs_init_number(ctx, &value, number);
+ __qmljs_init_number(&value, number);
object->objectValue->put(name, value, /*flag*/ 0);
}
void __qmljs_set_property_string(Context *ctx, Value *object, String *name, String *s)
{
Value value;
- __qmljs_init_string(ctx, &value, s);
+ __qmljs_init_string(&value, s);
object->objectValue->put(name, value, /*flag*/ 0);
}
void __qmljs_set_activation_property_boolean(Context *ctx, String *name, bool b)
{
Value value;
- __qmljs_init_boolean(ctx, &value, b);
+ __qmljs_init_boolean(&value, b);
__qmljs_set_activation_property(ctx, name, &value);
}
void __qmljs_set_activation_property_number(Context *ctx, String *name, double number)
{
Value value;
- __qmljs_init_number(ctx, &value, number);
+ __qmljs_init_number(&value, number);
__qmljs_set_activation_property(ctx, name, &value);
}
void __qmljs_set_activation_property_string(Context *ctx, String *name, String *string)
{
Value value;
- __qmljs_init_string(ctx, &value, string);
+ __qmljs_init_string(&value, string);
__qmljs_set_activation_property(ctx, name, &value);
}
if (px.type == STRING_TYPE && py.type == STRING_TYPE) {
bool r = __qmljs_string_compare(ctx, px.stringValue, py.stringValue);
- __qmljs_init_boolean(ctx, result, r);
+ __qmljs_init_boolean(result, r);
} else {
double nx = __qmljs_to_number(ctx, &px);
double ny = __qmljs_to_number(ctx, &py);
if (isnan(nx) || isnan(ny)) {
- __qmljs_init_undefined(ctx, result);
+ __qmljs_init_undefined(result);
} else {
- __qmljs_init_boolean(ctx, result, nx < ny);
+ __qmljs_init_boolean(result, nx < ny);
}
}
}
return true;
} else if (x->type == NUMBER_TYPE && y->type == STRING_TYPE) {
Value ny;
- __qmljs_init_number(ctx, &ny, __qmljs_to_number(ctx, y));
+ __qmljs_init_number(&ny, __qmljs_to_number(ctx, y));
return __qmljs_equal(ctx, x, &ny);
} else if (x->type == STRING_TYPE && y->type == NUMBER_TYPE) {
Value nx;
- __qmljs_init_number(ctx, &nx, __qmljs_to_number(ctx, x));
+ __qmljs_init_number(&nx, __qmljs_to_number(ctx, x));
return __qmljs_equal(ctx, &nx, y);
} else if (x->type == BOOLEAN_TYPE) {
Value nx;
- __qmljs_init_number(ctx, &nx, (double) x->booleanValue);
+ __qmljs_init_number(&nx, (double) x->booleanValue);
return __qmljs_equal(ctx, &nx, y);
} else if (y->type == BOOLEAN_TYPE) {
Value ny;
- __qmljs_init_number(ctx, &ny, (double) y->booleanValue);
+ __qmljs_init_number(&ny, (double) y->booleanValue);
return __qmljs_equal(ctx, x, &ny);
} else if ((x->type == NUMBER_TYPE || x->type == STRING_TYPE) && y->type == OBJECT_TYPE) {
Value py;
thisObject = baseObject;
} else {
baseObject = context->activation;
- __qmljs_init_null(context, &thisObject);
+ __qmljs_init_null(&thisObject);
}
Value func;
baseObject.objectValue->get(name, &func);
ctx->init(context->engine);
ctx->parent = f->scope;
if (f->needsActivation)
- __qmljs_init_object(ctx, &ctx->activation, ctx->engine->newArgumentsObject(ctx));
+ __qmljs_init_object(&ctx->activation, ctx->engine->newArgumentsObject(ctx));
else
- __qmljs_init_null(ctx, &ctx->activation);
+ __qmljs_init_null(&ctx->activation);
ctx->thisObject = thisObject;
ctx->formals = f->formalParameterList;
ctx->formalCount = f->formalParameterCount;
ctx->init(context->engine);
ctx->parent = f->scope;
if (f->needsActivation)
- __qmljs_init_object(ctx, &ctx->activation, ctx->engine->newArgumentsObject(ctx));
+ __qmljs_init_object(&ctx->activation, ctx->engine->newArgumentsObject(ctx));
else
- __qmljs_init_null(ctx, &ctx->activation);
- __qmljs_init_null(ctx, &ctx->thisObject);
+ __qmljs_init_null(&ctx->activation);
+ __qmljs_init_null(&ctx->thisObject);
ctx->formals = f->formalParameterList;
ctx->formalCount = f->formalParameterCount;
ctx->arguments = args;
ctx->init(context->engine);
ctx->parent = f->scope;
if (f->needsActivation)
- __qmljs_init_object(ctx, &ctx->activation, ctx->engine->newArgumentsObject(ctx));
+ __qmljs_init_object(&ctx->activation, ctx->engine->newArgumentsObject(ctx));
else
- __qmljs_init_null(ctx, &ctx->activation);
- __qmljs_init_null(ctx, &ctx->thisObject);
+ __qmljs_init_null(&ctx->activation);
+ __qmljs_init_null(&ctx->thisObject);
ctx->formals = f->formalParameterList;
ctx->formalCount = f->formalParameterCount;
ctx->arguments = args;
ctx->init(context->engine);
ctx->parent = f->scope;
if (f->needsActivation)
- __qmljs_init_object(ctx, &ctx->activation, ctx->engine->newArgumentsObject(ctx));
+ __qmljs_init_object(&ctx->activation, ctx->engine->newArgumentsObject(ctx));
else
- __qmljs_init_null(ctx, &ctx->activation);
+ __qmljs_init_null(&ctx->activation);
ctx->thisObject = thisObject;
ctx->formals = f->formalParameterList;
ctx->formalCount = f->formalParameterCount;
void __qmljs_construct_value(Context *context, Value *result, const Value *func, Value *args, int argc);
// constructors
-void __qmljs_init_undefined(Context *ctx, Value *result);
-void __qmljs_init_null(Context *ctx, Value *result);
-void __qmljs_init_boolean(Context *ctx, Value *result, bool value);
-void __qmljs_init_number(Context *ctx, Value *result, double number);
-void __qmljs_init_string(Context *ctx, Value *result, String *string);
-void __qmljs_init_object(Context *ctx, Value *result, Object *object);
-void __qmljs_init_closure(Context *, Value *result, IR::Function *clos);
+void __qmljs_init_undefined(Value *result);
+void __qmljs_init_null(Value *result);
+void __qmljs_init_boolean(Value *result, bool value);
+void __qmljs_init_number(Value *result, double number);
+void __qmljs_init_string(Value *result, String *string);
+void __qmljs_init_object(Value *result, Object *object);
+void __qmljs_init_closure(Context *ctx, Value *result, IR::Function *clos);
bool __qmljs_is_function(Context *ctx, const Value *value);
inline bool is(ValueType t) const { return type == t; }
inline bool isNot(ValueType t) const { return type != t; }
- static inline Value boolean(Context *ctx, bool value) {
+ static inline Value fromBoolean(bool value) {
Value v;
- __qmljs_init_boolean(ctx, &v, value);
+ __qmljs_init_boolean(&v, value);
return v;
}
- static inline Value number(Context *ctx, double value) {
+ static inline Value fromNumber(double value) {
Value v;
- __qmljs_init_number(ctx, &v, value);
+ __qmljs_init_number(&v, value);
return v;
}
- static inline Value object(Context *ctx, Object *value) {
+ static inline Value fromObject(Object *value) {
Value v;
- __qmljs_init_object(ctx, &v, value);
+ __qmljs_init_object(&v, value);
return v;
}
- static inline Value string(Context *ctx, String *value) {
+ static inline Value fromString(String *value) {
Value v;
- __qmljs_init_string(ctx, &v, value);
+ __qmljs_init_string(&v, value);
return v;
}
- static Value string(Context *ctx, const QString &string);
+ static Value fromString(Context *ctx, const QString &fromString);
- static int toInteger(double number);
+ static int toInteger(double fromNumber);
static int toInt32(double value);
int toUInt16(Context *ctx);
int toInt32(Context *ctx);
extern "C" {
// constructors
-inline void __qmljs_init_undefined(Context *, Value *result)
+inline void __qmljs_init_undefined(Value *result)
{
result->type = UNDEFINED_TYPE;
}
-inline void __qmljs_init_null(Context *, Value *result)
+inline void __qmljs_init_null(Value *result)
{
result->type = NULL_TYPE;
}
-inline void __qmljs_init_boolean(Context *, Value *result, bool value)
+inline void __qmljs_init_boolean(Value *result, bool value)
{
result->type = BOOLEAN_TYPE;
result->booleanValue = value;
}
-inline void __qmljs_init_number(Context *, Value *result, double value)
+inline void __qmljs_init_number(Value *result, double value)
{
result->type = NUMBER_TYPE;
result->numberValue = value;
}
-inline void __qmljs_init_string(Context *, Value *result, String *value)
+inline void __qmljs_init_string(Value *result, String *value)
{
result->type = STRING_TYPE;
result->stringValue = value;
}
-inline void __qmljs_init_object(Context *, Value *result, Object *object)
+inline void __qmljs_init_object(Value *result, Object *object)
{
result->type = OBJECT_TYPE;
result->objectValue = object;
if (value->type == OBJECT_TYPE)
__qmljs_object_default_value(ctx, result, value->objectValue, typeHint);
else
- __qmljs_init_undefined(ctx, result);
+ __qmljs_init_undefined(result);
}
inline void __qmljs_uplus(Context *ctx, Value *result, const Value *value)
{
double n = __qmljs_to_number(ctx, value);
- __qmljs_init_number(ctx, result, n);
+ __qmljs_init_number(result, n);
}
inline void __qmljs_uminus(Context *ctx, Value *result, const Value *value)
{
double n = __qmljs_to_number(ctx, value);
- __qmljs_init_number(ctx, result, -n);
+ __qmljs_init_number(result, -n);
}
inline void __qmljs_compl(Context *ctx, Value *result, const Value *value)
{
int n = __qmljs_to_int32(ctx, value);
- __qmljs_init_number(ctx, result, ~n);
+ __qmljs_init_number(result, ~n);
}
inline void __qmljs_not(Context *ctx, Value *result, const Value *value)
{
bool b = __qmljs_to_boolean(ctx, value);
- __qmljs_init_number(ctx, result, !b);
+ __qmljs_init_number(result, !b);
}
// binary operators
{
int lval = __qmljs_to_int32(ctx, left);
int rval = __qmljs_to_int32(ctx, right);
- __qmljs_init_number(ctx, result, lval | rval);
+ __qmljs_init_number(result, lval | rval);
}
inline void __qmljs_bit_xor(Context *ctx, Value *result, const Value *left, const Value *right)
{
int lval = __qmljs_to_int32(ctx, left);
int rval = __qmljs_to_int32(ctx, right);
- __qmljs_init_number(ctx, result, lval ^ rval);
+ __qmljs_init_number(result, lval ^ rval);
}
inline void __qmljs_bit_and(Context *ctx, Value *result, const Value *left, const Value *right)
{
int lval = __qmljs_to_int32(ctx, left);
int rval = __qmljs_to_int32(ctx, right);
- __qmljs_init_number(ctx, result, lval & rval);
+ __qmljs_init_number(result, lval & rval);
}
inline void __qmljs_add(Context *ctx, Value *result, const Value *left, const Value *right)
if (pright.type != STRING_TYPE)
__qmljs_to_string(ctx, &pright, &pright);
String *string = __qmljs_string_concat(ctx, pleft.stringValue, pright.stringValue);
- __qmljs_init_string(ctx, result, string);
+ __qmljs_init_string(result, string);
} else {
double x = __qmljs_to_number(ctx, &pleft);
double y = __qmljs_to_number(ctx, &pright);
- __qmljs_init_number(ctx, result, x + y);
+ __qmljs_init_number(result, x + y);
}
}
{
double lval = __qmljs_to_number(ctx, left);
double rval = __qmljs_to_number(ctx, right);
- __qmljs_init_number(ctx, result, lval - rval);
+ __qmljs_init_number(result, lval - rval);
}
inline void __qmljs_mul(Context *ctx, Value *result, const Value *left, const Value *right)
{
double lval = __qmljs_to_number(ctx, left);
double rval = __qmljs_to_number(ctx, right);
- __qmljs_init_number(ctx, result, lval * rval);
+ __qmljs_init_number(result, lval * rval);
}
inline void __qmljs_div(Context *ctx, Value *result, const Value *left, const Value *right)
{
double lval = __qmljs_to_number(ctx, left);
double rval = __qmljs_to_number(ctx, right);
- __qmljs_init_number(ctx, result, lval * rval);
+ __qmljs_init_number(result, lval * rval);
}
inline void __qmljs_mod(Context *ctx, Value *result, const Value *left, const Value *right)
{
double lval = __qmljs_to_number(ctx, left);
double rval = __qmljs_to_number(ctx, right);
- __qmljs_init_number(ctx, result, fmod(lval, rval));
+ __qmljs_init_number(result, fmod(lval, rval));
}
inline void __qmljs_shl(Context *ctx, Value *result, const Value *left, const Value *right)
{
int lval = __qmljs_to_int32(ctx, left);
unsigned rval = __qmljs_to_uint32(ctx, right);
- __qmljs_init_number(ctx, result, lval << rval);
+ __qmljs_init_number(result, lval << rval);
}
inline void __qmljs_shr(Context *ctx, Value *result, const Value *left, const Value *right)
{
int lval = __qmljs_to_int32(ctx, left);
unsigned rval = __qmljs_to_uint32(ctx, right);
- __qmljs_init_number(ctx, result, lval >> rval);
+ __qmljs_init_number(result, lval >> rval);
}
inline void __qmljs_ushr(Context *ctx, Value *result, const Value *left, const Value *right)
{
unsigned lval = __qmljs_to_uint32(ctx, left);
unsigned rval = __qmljs_to_uint32(ctx, right);
- __qmljs_init_number(ctx, result, lval << rval);
+ __qmljs_init_number(result, lval << rval);
}
inline void __qmljs_gt(Context *ctx, Value *result, const Value *left, const Value *right)
__qmljs_compare(ctx, result, left, right, false);
if (result->type == UNDEFINED_TYPE)
- __qmljs_init_boolean(ctx, result, false);
+ __qmljs_init_boolean(result, false);
}
inline void __qmljs_lt(Context *ctx, Value *result, const Value *left, const Value *right)
__qmljs_compare(ctx, result, left, right, true);
if (result->type == UNDEFINED_TYPE)
- __qmljs_init_boolean(ctx, result,false);
+ __qmljs_init_boolean(result, false);
}
inline void __qmljs_ge(Context *ctx, Value *result, const Value *left, const Value *right)
bool r = ! (result->type == UNDEFINED_TYPE ||
(result->type == BOOLEAN_TYPE && result->booleanValue == true));
- __qmljs_init_boolean(ctx, result, r);
+ __qmljs_init_boolean(result, r);
}
inline void __qmljs_le(Context *ctx, Value *result, const Value *left, const Value *right)
bool r = ! (result->type == UNDEFINED_TYPE ||
(result->type == BOOLEAN_TYPE && result->booleanValue == true));
- __qmljs_init_boolean(ctx, result, r);
+ __qmljs_init_boolean(result, r);
}
inline void __qmljs_eq(Context *ctx, Value *result, const Value *left, const Value *right)
{
bool r = __qmljs_equal(ctx, left, right);
- __qmljs_init_boolean(ctx, result, r);
+ __qmljs_init_boolean(result, r);
}
inline void __qmljs_ne(Context *ctx, Value *result, const Value *left, const Value *right)
{
bool r = ! __qmljs_equal(ctx, left, right);
- __qmljs_init_boolean(ctx, result, r);
+ __qmljs_init_boolean(result, r);
}
inline void __qmljs_se(Context *ctx, Value *result, const Value *left, const Value *right)
{
bool r = __qmljs_strict_equal(ctx, left, right);
- __qmljs_init_boolean(ctx, result, r);
+ __qmljs_init_boolean(result, r);
}
inline void __qmljs_sne(Context *ctx, Value *result, const Value *left, const Value *right)
{
bool r = ! __qmljs_strict_equal(ctx, left, right);
- __qmljs_init_boolean(ctx, result, r);
+ __qmljs_init_boolean(result, r);
}
inline bool __qmljs_strict_equal(Context *ctx, const Value *x, const Value *y)
{
Context *ctx = engine->rootContext;
FunctionObject *ctor = ctx->engine->newObjectCtor(ctx);
- ctor->setProperty(ctx, QLatin1String("prototype"), Value::object(ctx, ctx->engine->newObjectPrototype(ctx, ctor)));
- return Value::object(ctx, ctor);
+ ctor->setProperty(ctx, QLatin1String("prototype"), Value::fromObject(ctx->engine->newObjectPrototype(ctx, ctor)));
+ return Value::fromObject(ctor);
}
ObjectCtor::ObjectCtor(Context *scope)
void ObjectCtor::construct(Context *ctx)
{
- __qmljs_init_object(ctx, &ctx->thisObject, ctx->engine->newObject());
+ __qmljs_init_object(&ctx->thisObject, ctx->engine->newObject());
}
void ObjectCtor::call(Context *)
ObjectPrototype::ObjectPrototype(Context *ctx, FunctionObject *ctor)
{
- setProperty(ctx, QLatin1String("constructor"), Value::object(ctx, ctor));
+ setProperty(ctx, QLatin1String("constructor"), Value::fromObject(ctor));
}
//
{
Context *ctx = engine->rootContext;
FunctionObject *ctor = ctx->engine->newStringCtor(ctx);
- ctor->setProperty(ctx, QLatin1String("prototype"), Value::object(ctx, ctx->engine->newStringPrototype(ctx, ctor)));
- return Value::object(ctx, ctor);
+ ctor->setProperty(ctx, QLatin1String("prototype"), Value::fromObject(ctx->engine->newStringPrototype(ctx, ctor)));
+ return Value::fromObject(ctor);
}
StringCtor::StringCtor(Context *scope)
{
Value value;
if (ctx->argumentCount)
- value = Value::string(ctx, ctx->argument(0).toString(ctx));
+ value = Value::fromString(ctx->argument(0).toString(ctx));
else
- value = Value::string(ctx, QString());
- __qmljs_init_object(ctx, &ctx->thisObject, ctx->engine->newStringObject(value));
+ value = Value::fromString(ctx, QString());
+ __qmljs_init_object(&ctx->thisObject, ctx->engine->newStringObject(value));
}
void StringCtor::call(Context *ctx)
{
const Value arg = ctx->argument(0);
if (arg.is(UNDEFINED_TYPE))
- __qmljs_init_string(ctx, &ctx->result, String::get(ctx, QString()));
+ __qmljs_init_string(&ctx->result, String::get(ctx, QString()));
else
__qmljs_to_string(ctx, &ctx->result, &arg);
}
StringPrototype::StringPrototype(Context *ctx, FunctionObject *ctor)
{
- setProperty(ctx, QLatin1String("constructor"), Value::object(ctx, ctor));
+ setProperty(ctx, QLatin1String("constructor"), Value::fromObject(ctor));
setProperty(ctx, QLatin1String("toString"), method_toString);
setProperty(ctx, QLatin1String("valueOf"), method_valueOf);
setProperty(ctx, QLatin1String("charAt"), method_charAt);
if (pos >= 0 && pos < str.length())
result += str.at(pos);
- ctx->result = Value::string(ctx, result);
+ ctx->result = Value::fromString(ctx, result);
}
void StringPrototype::method_charCodeAt(Context *ctx)
if (pos >= 0 && pos < str.length())
result = str.at(pos).unicode();
- __qmljs_init_number(ctx, &ctx->result, result);
+ __qmljs_init_number(&ctx->result, result);
}
void StringPrototype::method_concat(Context *ctx)
value += v.stringValue->toQString();
}
- ctx->result = Value::string(ctx, value);
+ ctx->result = Value::fromString(ctx, value);
}
void StringPrototype::method_indexOf(Context *ctx)
if (! value.isEmpty())
index = value.indexOf(searchString, qMin(qMax(pos, 0), value.length()));
- __qmljs_init_number(ctx, &ctx->result, index);
+ __qmljs_init_number(&ctx->result, index);
}
void StringPrototype::method_lastIndexOf(Context *ctx)
if (!searchString.isEmpty() && pos == value.length())
--pos;
int index = value.lastIndexOf(searchString, pos);
- __qmljs_init_number(ctx, &ctx->result, index);
+ __qmljs_init_number(&ctx->result, index);
}
void StringPrototype::method_localeCompare(Context *ctx)
{
const QString value = getThisString(ctx);
const QString that = ctx->argument(0).toString(ctx)->toQString();
- __qmljs_init_number(ctx, &ctx->result, QString::localeAwareCompare(value, that));
+ __qmljs_init_number(&ctx->result, QString::localeAwareCompare(value, that));
}
void StringPrototype::method_match(Context *)
end = qMin(end, length);
int count = qMax(0, end - start);
- ctx->result = Value::string(ctx, text.mid(start, count));
+ ctx->result = Value::fromString(ctx, text.mid(start, count));
}
void StringPrototype::method_split(Context *)
qint32 x = Value::toInt32(start);
qint32 y = Value::toInt32(length);
- ctx->result = Value::string(ctx, value.mid(x, y));
+ ctx->result = Value::fromString(ctx, value.mid(x, y));
}
void StringPrototype::method_substring(Context *ctx)
qint32 x = Value::toInt32(start);
qint32 y = Value::toInt32(end - start);
- ctx->result = Value::string(ctx, value.mid(x, y));
+ ctx->result = Value::fromString(ctx, value.mid(x, y));
}
void StringPrototype::method_toLowerCase(Context *ctx)
{
QString value = getThisString(ctx);
- ctx->result = Value::string(ctx, value.toLower());
+ ctx->result = Value::fromString(ctx, value.toLower());
}
void StringPrototype::method_toLocaleLowerCase(Context *ctx)
void StringPrototype::method_toUpperCase(Context *ctx)
{
QString value = getThisString(ctx);
- ctx->result = Value::string(ctx, value.toUpper());
+ ctx->result = Value::fromString(ctx, value.toUpper());
}
void StringPrototype::method_toLocaleUpperCase(Context *ctx)
QChar c(ctx->argument(i).toUInt16(ctx));
str += c;
}
- ctx->result = Value::string(ctx, str);
+ ctx->result = Value::fromString(ctx, str);
}
//
{
Context *ctx = engine->rootContext;
FunctionObject *ctor = ctx->engine->newNumberCtor(ctx);
- ctor->setProperty(ctx, QLatin1String("prototype"), Value::object(ctx, ctx->engine->newNumberPrototype(ctx, ctor)));
- return Value::object(ctx, ctor);
+ ctor->setProperty(ctx, QLatin1String("prototype"), Value::fromObject(ctx->engine->newNumberPrototype(ctx, ctor)));
+ return Value::fromObject(ctor);
}
NumberCtor::NumberCtor(Context *scope)
void NumberCtor::construct(Context *ctx)
{
const double n = ctx->argument(0).toNumber(ctx);
- __qmljs_init_object(ctx, &ctx->thisObject, ctx->engine->newNumberObject(Value::number(ctx, n)));
+ __qmljs_init_object(&ctx->thisObject, ctx->engine->newNumberObject(Value::fromNumber(n)));
}
void NumberCtor::call(Context *ctx)
{
double value = ctx->argumentCount ? ctx->argument(0).toNumber(ctx) : 0;
- __qmljs_init_number(ctx, &ctx->result, value);
+ __qmljs_init_number(&ctx->result, value);
}
NumberPrototype::NumberPrototype(Context *ctx, FunctionObject *ctor)
{
- ctor->setProperty(ctx, QLatin1String("NaN"), Value::number(ctx, qSNaN()));
- ctor->setProperty(ctx, QLatin1String("NEGATIVE_INFINITY"), Value::number(ctx, -qInf()));
- ctor->setProperty(ctx, QLatin1String("POSITIVE_INFINITY"), Value::number(ctx, qInf()));
- ctor->setProperty(ctx, QLatin1String("MAX_VALUE"), Value::number(ctx, 1.7976931348623158e+308));
+ ctor->setProperty(ctx, QLatin1String("NaN"), Value::fromNumber(qSNaN()));
+ ctor->setProperty(ctx, QLatin1String("NEGATIVE_INFINITY"), Value::fromNumber(-qInf()));
+ ctor->setProperty(ctx, QLatin1String("POSITIVE_INFINITY"), Value::fromNumber(qInf()));
+ ctor->setProperty(ctx, QLatin1String("MAX_VALUE"), Value::fromNumber(1.7976931348623158e+308));
#ifdef __INTEL_COMPILER
# pragma warning( push )
# pragma warning(disable: 239)
#endif
- ctor->setProperty(ctx, QLatin1String("MIN_VALUE"), Value::number(ctx, 5e-324));
+ ctor->setProperty(ctx, QLatin1String("MIN_VALUE"), Value::fromNumber(5e-324));
#ifdef __INTEL_COMPILER
# pragma warning( pop )
#endif
- setProperty(ctx, QLatin1String("constructor"), Value::object(ctx, ctor));
+ setProperty(ctx, QLatin1String("constructor"), Value::fromObject(ctor));
setProperty(ctx, QLatin1String("toString"), method_toString);
setProperty(ctx, QLatin1String("toLocalString"), method_toLocaleString);
setProperty(ctx, QLatin1String("valueOf"), method_valueOf);
QString str;
double num = internalValue.toNumber(ctx);
if (qIsNaN(num)) {
- ctx->result = Value::string(ctx, QLatin1String("NaN"));
+ ctx->result = Value::fromString(ctx, QLatin1String("NaN"));
return;
} else if (qIsInf(num)) {
- ctx->result = Value::string(ctx, QLatin1String(num < 0 ? "-Infinity" : "Infinity"));
+ ctx->result = Value::fromString(ctx, QLatin1String(num < 0 ? "-Infinity" : "Infinity"));
return;
}
bool negative = false;
}
if (negative)
str.prepend(QLatin1Char('-'));
- ctx->result = Value::string(ctx, str);
+ ctx->result = Value::fromString(ctx, str);
return;
}
}
self.objectValue->defaultValue(ctx, &internalValue, NUMBER_HINT);
String *str = internalValue.toString(ctx);
- ctx->result = Value::string(ctx, str);
+ ctx->result = Value::fromString(str);
}
void NumberPrototype::method_toLocaleString(Context *ctx)
Value internalValue;
self.objectValue->defaultValue(ctx, &internalValue, STRING_HINT);
String *str = internalValue.toString(ctx);
- ctx->result = Value::string(ctx, str);
+ ctx->result = Value::fromString(str);
}
void NumberPrototype::method_valueOf(Context *ctx)
str = QString::fromLatin1(v < 0 ? "-Infinity" : "Infinity");
else
str = QString::number(v, 'f', int (fdigits));
- ctx->result = Value::string(ctx, str);
+ ctx->result = Value::fromString(ctx, str);
}
void NumberPrototype::method_toExponential(Context *ctx)
double v = internalValue.toNumber(ctx);
QString z = QString::number(v, 'e', int (fdigits));
- ctx->result = Value::string(ctx, z);
+ ctx->result = Value::fromString(ctx, z);
}
void NumberPrototype::method_toPrecision(Context *ctx)
self.objectValue->defaultValue(ctx, &internalValue, NUMBER_HINT);
double v = internalValue.toNumber(ctx);
- ctx->result = Value::string(ctx, QString::number(v, 'g', int (fdigits)));
+ ctx->result = Value::fromString(ctx, QString::number(v, 'g', int (fdigits)));
}
//
//
MathObject::MathObject(Context *ctx)
{
- setProperty(ctx, QLatin1String("E"), Value::number(ctx, ::exp(1.0)));
- setProperty(ctx, QLatin1String("LN2"), Value::number(ctx, ::log(2.0)));
- setProperty(ctx, QLatin1String("LN10"), Value::number(ctx, ::log(10.0)));
- setProperty(ctx, QLatin1String("LOG2E"), Value::number(ctx, 1.0/::log(2.0)));
- setProperty(ctx, QLatin1String("LOG10E"), Value::number(ctx, 1.0/::log(10.0)));
- setProperty(ctx, QLatin1String("PI"), Value::number(ctx, qt_PI));
- setProperty(ctx, QLatin1String("SQRT1_2"), Value::number(ctx, ::sqrt(0.5)));
- setProperty(ctx, QLatin1String("SQRT2"), Value::number(ctx, ::sqrt(2.0)));
+ setProperty(ctx, QLatin1String("E"), Value::fromNumber(::exp(1.0)));
+ setProperty(ctx, QLatin1String("LN2"), Value::fromNumber(::log(2.0)));
+ setProperty(ctx, QLatin1String("LN10"), Value::fromNumber(::log(10.0)));
+ setProperty(ctx, QLatin1String("LOG2E"), Value::fromNumber(1.0/::log(2.0)));
+ setProperty(ctx, QLatin1String("LOG10E"), Value::fromNumber(1.0/::log(10.0)));
+ setProperty(ctx, QLatin1String("PI"), Value::fromNumber(qt_PI));
+ setProperty(ctx, QLatin1String("SQRT1_2"), Value::fromNumber(::sqrt(0.5)));
+ setProperty(ctx, QLatin1String("SQRT2"), Value::fromNumber(::sqrt(2.0)));
setProperty(ctx, QLatin1String("abs"), method_abs, 1);
setProperty(ctx, QLatin1String("acos"), method_acos, 1);
{
double v = ctx->argument(0).toNumber(ctx);
if (v == 0) // 0 | -0
- ctx->result = Value::number(ctx, 0);
+ ctx->result = Value::fromNumber(0);
else
- ctx->result = Value::number(ctx, v < 0 ? -v : v);
+ ctx->result = Value::fromNumber(v < 0 ? -v : v);
}
void MathObject::method_acos(Context *ctx)
{
double v = ctx->argument(0).toNumber(ctx);
if (v > 1)
- ctx->result = Value::number(ctx, qSNaN());
+ ctx->result = Value::fromNumber(qSNaN());
else
- ctx->result = Value::number(ctx, ::acos(v));
+ ctx->result = Value::fromNumber(::acos(v));
}
void MathObject::method_asin(Context *ctx)
{
double v = ctx->argument(0).toNumber(ctx);
if (v > 1)
- ctx->result = Value::number(ctx, qSNaN());
+ ctx->result = Value::fromNumber(qSNaN());
else
- ctx->result = Value::number(ctx, ::asin(v));
+ ctx->result = Value::fromNumber(::asin(v));
}
void MathObject::method_atan(Context *ctx)
{
double v = ctx->argument(0).toNumber(ctx);
if (v == 0.0)
- ctx->result = Value::number(ctx, v);
+ ctx->result = Value::fromNumber(v);
else
- ctx->result = Value::number(ctx, ::atan(v));
+ ctx->result = Value::fromNumber(::atan(v));
}
void MathObject::method_atan2(Context *ctx)
double v1 = ctx->argument(0).toNumber(ctx);
double v2 = ctx->argument(1).toNumber(ctx);
if ((v1 < 0) && qIsFinite(v1) && qIsInf(v2) && (copySign(1.0, v2) == 1.0)) {
- ctx->result = Value::number(ctx, copySign(0, -1.0));
+ ctx->result = Value::fromNumber(copySign(0, -1.0));
return;
}
if ((v1 == 0.0) && (v2 == 0.0)) {
if ((copySign(1.0, v1) == 1.0) && (copySign(1.0, v2) == -1.0)) {
- ctx->result = Value::number(ctx, qt_PI);
+ ctx->result = Value::fromNumber(qt_PI);
return;
} else if ((copySign(1.0, v1) == -1.0) && (copySign(1.0, v2) == -1.0)) {
- ctx->result = Value::number(ctx, -qt_PI);
+ ctx->result = Value::fromNumber(-qt_PI);
return;
}
}
- ctx->result = Value::number(ctx, ::atan2(v1, v2));
+ ctx->result = Value::fromNumber(::atan2(v1, v2));
}
void MathObject::method_ceil(Context *ctx)
{
double v = ctx->argument(0).toNumber(ctx);
if (v < 0.0 && v > -1.0)
- ctx->result = Value::number(ctx, copySign(0, -1.0));
+ ctx->result = Value::fromNumber(copySign(0, -1.0));
else
- ctx->result = Value::number(ctx, ::ceil(v));
+ ctx->result = Value::fromNumber(::ceil(v));
}
void MathObject::method_cos(Context *ctx)
{
double v = ctx->argument(0).toNumber(ctx);
- ctx->result = Value::number(ctx, ::cos(v));
+ ctx->result = Value::fromNumber(::cos(v));
}
void MathObject::method_exp(Context *ctx)
double v = ctx->argument(0).toNumber(ctx);
if (qIsInf(v)) {
if (copySign(1.0, v) == -1.0)
- ctx->result = Value::number(ctx, 0);
+ ctx->result = Value::fromNumber(0);
else
- ctx->result = Value::number(ctx, qInf());
+ ctx->result = Value::fromNumber(qInf());
} else {
- ctx->result = Value::number(ctx, ::exp(v));
+ ctx->result = Value::fromNumber(::exp(v));
}
}
void MathObject::method_floor(Context *ctx)
{
double v = ctx->argument(0).toNumber(ctx);
- ctx->result = Value::number(ctx, ::floor(v));
+ ctx->result = Value::fromNumber(::floor(v));
}
void MathObject::method_log(Context *ctx)
{
double v = ctx->argument(0).toNumber(ctx);
if (v < 0)
- ctx->result = Value::number(ctx, qSNaN());
+ ctx->result = Value::fromNumber(qSNaN());
else
- ctx->result = Value::number(ctx, ::log(v));
+ ctx->result = Value::fromNumber(::log(v));
}
void MathObject::method_max(Context *ctx)
if (x > mx || qIsNaN(x))
mx = x;
}
- ctx->result = Value::number(ctx, mx);
+ ctx->result = Value::fromNumber(mx);
}
void MathObject::method_min(Context *ctx)
mx = x;
}
}
- ctx->result = Value::number(ctx, mx);
+ ctx->result = Value::fromNumber(mx);
}
void MathObject::method_pow(Context *ctx)
double y = ctx->argument(1).toNumber(ctx);
if (qIsNaN(y)) {
- ctx->result = Value::number(ctx, qSNaN());
+ ctx->result = Value::fromNumber(qSNaN());
return;
}
if (y == 0) {
- ctx->result = Value::number(ctx, 1);
+ ctx->result = Value::fromNumber(1);
} else if (((x == 1) || (x == -1)) && qIsInf(y)) {
- ctx->result = Value::number(ctx, qSNaN());
+ ctx->result = Value::fromNumber(qSNaN());
} else if (((x == 0) && copySign(1.0, x) == 1.0) && (y < 0)) {
- ctx->result = Value::number(ctx, qInf());
+ ctx->result = Value::fromNumber(qInf());
} else if ((x == 0) && copySign(1.0, x) == -1.0) {
if (y < 0) {
if (::fmod(-y, 2.0) == 1.0)
- ctx->result = Value::number(ctx, -qInf());
+ ctx->result = Value::fromNumber(-qInf());
else
- ctx->result = Value::number(ctx, qInf());
+ ctx->result = Value::fromNumber(qInf());
} else if (y > 0) {
if (::fmod(y, 2.0) == 1.0)
- ctx->result = Value::number(ctx, copySign(0, -1.0));
+ ctx->result = Value::fromNumber(copySign(0, -1.0));
else
- ctx->result = Value::number(ctx, 0);
+ ctx->result = Value::fromNumber(0);
}
}
}
#endif
else {
- ctx->result = Value::number(ctx, ::pow(x, y));
+ ctx->result = Value::fromNumber(::pow(x, y));
}
}
void MathObject::method_random(Context *ctx)
{
- ctx->result = Value::number(ctx, qrand() / (double) RAND_MAX);
+ ctx->result = Value::fromNumber(qrand() / (double) RAND_MAX);
}
void MathObject::method_round(Context *ctx)
{
double v = ctx->argument(0).toNumber(ctx);
v = copySign(::floor(v + 0.5), v);
- ctx->result = Value::number(ctx, v);
+ ctx->result = Value::fromNumber(v);
}
void MathObject::method_sin(Context *ctx)
{
double v = ctx->argument(0).toNumber(ctx);
- ctx->result = Value::number(ctx, ::sin(v));
+ ctx->result = Value::fromNumber(::sin(v));
}
void MathObject::method_sqrt(Context *ctx)
{
double v = ctx->argument(0).toNumber(ctx);
- ctx->result = Value::number(ctx, ::sqrt(v));
+ ctx->result = Value::fromNumber(::sqrt(v));
}
void MathObject::method_tan(Context *ctx)
{
double v = ctx->argument(0).toNumber(ctx);
if (v == 0.0)
- ctx->result = Value::number(ctx, v);
+ ctx->result = Value::fromNumber(v);
else
- ctx->result = Value::number(ctx, ::tan(v));
+ ctx->result = Value::fromNumber(::tan(v));
}
amd64_mov_membase_reg(_codePtr, AMD64_RDI, offsetof(Value, numberValue), AMD64_RAX, 8);
return;
} else if (IR::String *str = s->source->asString()) {
- amd64_mov_reg_reg(_codePtr, AMD64_RDI, AMD64_R14, 8);
- loadTempAddress(AMD64_RSI, t);
- amd64_mov_reg_imm(_codePtr, AMD64_RDX, _engine->newString(*str->value));
+ loadTempAddress(AMD64_RDI, t);
+ amd64_mov_reg_imm(_codePtr, AMD64_RSI, _engine->newString(*str->value));
amd64_call_code(_codePtr, __qmljs_init_string);
return;
} else if (IR::Closure *clos = s->source->asClosure()) {