From: Erik Verbruggen Date: Thu, 29 Nov 2012 13:39:19 +0000 (+0100) Subject: Set the name of a function in more (most?) cases. X-Git-Tag: upstream/5.2.1~669^2~659^2~776 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=36356a4b273e19ca599bf2a0cbfb02fda69e6c0a;p=platform%2Fupstream%2Fqtdeclarative.git Set the name of a function in more (most?) cases. Change-Id: I1c2b9d61b6d97e3c2a8cb976fb6be8b68d51ae28 Reviewed-by: Lars Knoll --- diff --git a/llvm_runtime.cpp b/llvm_runtime.cpp index 2ecbee6..9205dd5 100644 --- a/llvm_runtime.cpp +++ b/llvm_runtime.cpp @@ -83,9 +83,9 @@ void __qmljs_llvm_init_string(ExecutionContext *ctx, Value *result, const char * *result = Value::fromString(__qmljs_string_from_utf8(ctx, str)); } -void __qmljs_llvm_init_native_function(ExecutionContext *ctx, Value *result, Value (*code)(ExecutionContext *)) +void __qmljs_llvm_init_native_function(ExecutionContext *ctx, Value *result, String *name, Value (*code)(ExecutionContext *)) { - *result = __qmljs_init_native_function(code, ctx); + *result = __qmljs_init_native_function(name, code, ctx); } bool __qmljs_llvm_to_boolean(ExecutionContext *ctx, const Value *value) diff --git a/main.cpp b/main.cpp index 47e4747..dccac7e 100644 --- a/main.cpp +++ b/main.cpp @@ -68,7 +68,9 @@ using namespace QQmlJS::VM; struct Print: FunctionObject { - Print(ExecutionContext *scope): FunctionObject(scope) {} + Print(ExecutionContext *scope): FunctionObject(scope) { + name = scope->engine->newString("print"); + } virtual Value call(ExecutionContext *ctx) { @@ -85,7 +87,9 @@ struct Print: FunctionObject struct TestHarnessError: FunctionObject { - TestHarnessError(ExecutionContext *scope, bool &errorInTestHarness): FunctionObject(scope), errorOccurred(errorInTestHarness) {} + TestHarnessError(ExecutionContext *scope, bool &errorInTestHarness): FunctionObject(scope), errorOccurred(errorInTestHarness) { + name = scope->engine->newString("$ERROR"); + } virtual Value call(ExecutionContext *ctx) { diff --git a/qmljs_engine.cpp b/qmljs_engine.cpp index ffecdf8..a1b3256 100644 --- a/qmljs_engine.cpp +++ b/qmljs_engine.cpp @@ -199,9 +199,9 @@ String *ExecutionEngine::identifier(const QString &s) return id; } -FunctionObject *ExecutionEngine::newNativeFunction(ExecutionContext *scope, Value (*code)(ExecutionContext *)) +FunctionObject *ExecutionEngine::newNativeFunction(ExecutionContext *scope, String *name, Value (*code)(ExecutionContext *)) { - NativeFunction *f = new NativeFunction(scope, code); + NativeFunction *f = new NativeFunction(scope, name, code); f->prototype = scope->engine->functionPrototype; return f; } diff --git a/qmljs_engine.h b/qmljs_engine.h index 4ecc1da..dcae173 100644 --- a/qmljs_engine.h +++ b/qmljs_engine.h @@ -148,7 +148,7 @@ struct ExecutionEngine String *identifier(const QString &s); - FunctionObject *newNativeFunction(ExecutionContext *scope, Value (*code)(ExecutionContext *)); + FunctionObject *newNativeFunction(ExecutionContext *scope, String *name, Value (*code)(ExecutionContext *)); FunctionObject *newScriptFunction(ExecutionContext *scope, IR::Function *function); Object *newObject(); diff --git a/qmljs_objects.cpp b/qmljs_objects.cpp index d550060..28932e3 100644 --- a/qmljs_objects.cpp +++ b/qmljs_objects.cpp @@ -76,7 +76,8 @@ void Object::__put__(ExecutionContext *ctx, const QString &name, const Value &va void Object::__put__(ExecutionContext *ctx, const QString &name, Value (*code)(ExecutionContext *), int count) { Q_UNUSED(count); - __put__(ctx, name, Value::fromObject(ctx->engine->newNativeFunction(ctx, code))); + String *nameStr = ctx->engine->newString(name); + __put__(ctx, name, Value::fromObject(ctx->engine->newNativeFunction(ctx, nameStr, code))); } Value Object::getValue(ExecutionContext *ctx, PropertyDescriptor *p) const @@ -510,6 +511,12 @@ Value EvalFunction::call(ExecutionContext *context, Value /*thisObject*/, Value return result; } +EvalFunction::EvalFunction(ExecutionContext *scope) + : FunctionObject(scope) +{ + name = scope->engine->newString(QLatin1String("eval")); +} + QQmlJS::IR::Function *EvalFunction::parseSource(QQmlJS::VM::ExecutionContext *ctx, const QString &fileName, const QString &source, QQmlJS::Codegen::Mode mode) @@ -585,6 +592,12 @@ QQmlJS::IR::Function *EvalFunction::parseSource(QQmlJS::VM::ExecutionContext *ct /// isNaN [15.1.2.4] +IsNaNFunction::IsNaNFunction(ExecutionContext *scope) + : FunctionObject(scope) +{ + name = scope->engine->newString(QLatin1String("isNaN")); +} + Value IsNaNFunction::call(ExecutionContext * /*context*/, Value /*thisObject*/, Value *args, int /*argc*/) { // TODO: see if we can generate code for this directly @@ -593,6 +606,12 @@ Value IsNaNFunction::call(ExecutionContext * /*context*/, Value /*thisObject*/, } /// isFinite [15.1.2.5] +IsFiniteFunction::IsFiniteFunction(ExecutionContext *scope) + : FunctionObject(scope) +{ + name = scope->engine->newString(QLatin1String("isFinite")); +} + Value IsFiniteFunction::call(ExecutionContext * /*context*/, Value /*thisObject*/, Value *args, int /*argc*/) { // TODO: see if we can generate code for this directly @@ -709,3 +728,11 @@ PropertyDescriptor *ArgumentsObject::__getPropertyDescriptor__(ExecutionContext return Object::__getPropertyDescriptor__(ctx, name, to_fill); } + + +NativeFunction::NativeFunction(ExecutionContext *scope, String *name, Value (*code)(ExecutionContext *)) + : FunctionObject(scope) + , code(code) +{ + this->name = name; +} diff --git a/qmljs_objects.h b/qmljs_objects.h index 103a9de..957a562 100644 --- a/qmljs_objects.h +++ b/qmljs_objects.h @@ -524,7 +524,7 @@ protected: struct NativeFunction: FunctionObject { Value (*code)(ExecutionContext *); - NativeFunction(ExecutionContext *scope, Value (*code)(ExecutionContext *)): FunctionObject(scope), code(code) {} + NativeFunction(ExecutionContext *scope, String *name, Value (*code)(ExecutionContext *)); virtual Value call(ExecutionContext *ctx) { return code(ctx); } virtual Value construct(ExecutionContext *ctx) { ctx->thisObject = code(ctx); return ctx->thisObject; } }; @@ -541,7 +541,7 @@ struct ScriptFunction: FunctionObject { struct EvalFunction : FunctionObject { - EvalFunction(ExecutionContext *scope): FunctionObject(scope) {} + EvalFunction(ExecutionContext *scope); static QQmlJS::IR::Function *parseSource(QQmlJS::VM::ExecutionContext *ctx, const QString &fileName, const QString &source, @@ -552,14 +552,14 @@ struct EvalFunction : FunctionObject struct IsNaNFunction: FunctionObject { - IsNaNFunction(ExecutionContext *scope): FunctionObject(scope) {} + IsNaNFunction(ExecutionContext *scope); virtual Value call(ExecutionContext *context, Value thisObject, Value *args, int argc); }; struct IsFiniteFunction: FunctionObject { - IsFiniteFunction(ExecutionContext *scope): FunctionObject(scope) {} + IsFiniteFunction(ExecutionContext *scope); virtual Value call(ExecutionContext *context, Value thisObject, Value *args, int argc); }; diff --git a/qmljs_runtime.cpp b/qmljs_runtime.cpp index c5d796f..1aa3c94 100644 --- a/qmljs_runtime.cpp +++ b/qmljs_runtime.cpp @@ -119,9 +119,9 @@ Value __qmljs_init_closure(IR::Function *clos, ExecutionContext *ctx) return Value::fromObject(ctx->engine->newScriptFunction(ctx, clos)); } -Value __qmljs_init_native_function(Value (*code)(ExecutionContext *), ExecutionContext *ctx) +Value __qmljs_init_native_function(String *name, Value (*code)(ExecutionContext *), ExecutionContext *ctx) { - return Value::fromObject(ctx->engine->newNativeFunction(ctx, code)); + return Value::fromObject(ctx->engine->newNativeFunction(ctx, name, code)); } Value __qmljs_string_literal_undefined(ExecutionContext *ctx) diff --git a/qmljs_runtime.h b/qmljs_runtime.h index a02713d..2df8dd1 100644 --- a/qmljs_runtime.h +++ b/qmljs_runtime.h @@ -107,7 +107,7 @@ void __qmljs_builtin_declare_var(ExecutionContext *ctx, bool deletable, String * // constructors Value __qmljs_init_closure(IR::Function *clos, ExecutionContext *ctx); -Value __qmljs_init_native_function(Value (*code)(ExecutionContext *), ExecutionContext *ctx); +Value __qmljs_init_native_function(String *name, Value (*code)(ExecutionContext *), ExecutionContext *ctx); Bool __qmljs_is_function(Value value);