Set the name of a function in more (most?) cases.
authorErik Verbruggen <erik.verbruggen@digia.com>
Thu, 29 Nov 2012 13:39:19 +0000 (14:39 +0100)
committerLars Knoll <lars.knoll@digia.com>
Thu, 29 Nov 2012 15:18:21 +0000 (16:18 +0100)
Change-Id: I1c2b9d61b6d97e3c2a8cb976fb6be8b68d51ae28
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
llvm_runtime.cpp
main.cpp
qmljs_engine.cpp
qmljs_engine.h
qmljs_objects.cpp
qmljs_objects.h
qmljs_runtime.cpp
qmljs_runtime.h

index 2ecbee6..9205dd5 100644 (file)
@@ -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)
index 47e4747..dccac7e 100644 (file)
--- 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)
     {
index ffecdf8..a1b3256 100644 (file)
@@ -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;
 }
index 4ecc1da..dcae173 100644 (file)
@@ -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();
index d550060..28932e3 100644 (file)
@@ -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;
+}
index 103a9de..957a562 100644 (file)
@@ -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);
 };
index c5d796f..1aa3c94 100644 (file)
@@ -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)
index a02713d..2df8dd1 100644 (file)
@@ -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);