Rename native functions to builtin functions.
authorErik Verbruggen <erik.verbruggen@me.com>
Wed, 16 Jan 2013 10:41:23 +0000 (11:41 +0100)
committerSimon Hausmann <simon.hausmann@digia.com>
Wed, 16 Jan 2013 13:27:28 +0000 (14:27 +0100)
Both the JIT and the compiler generate native code, but the functions
have to be registered as ScriptFunction objects, not NativeFunction
objects. The name BuiltinFunction prevents confusion or errors.

Change-Id: Ic6dca457362f916201b3e5178fbd36c6d754fa9c
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
llvm_runtime.cpp
qmljs_engine.cpp
qmljs_engine.h
qmljs_objects.cpp
qmljs_objects.h
qmljs_runtime.cpp
qmljs_runtime.h

index 6a0c163..dd5a625 100644 (file)
@@ -83,11 +83,6 @@ 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, String *name, Value (*code)(ExecutionContext *))
-{
-    *result = __qmljs_init_native_function(name, code, ctx);
-}
-
 bool __qmljs_llvm_to_boolean(ExecutionContext *ctx, const Value *value)
 {
     return __qmljs_to_boolean(*value, ctx);
index 6367dcc..2d34b3d 100644 (file)
@@ -239,9 +239,9 @@ Function *ExecutionEngine::newFunction(const QString &name)
     return f;
 }
 
-FunctionObject *ExecutionEngine::newNativeFunction(ExecutionContext *scope, String *name, Value (*code)(ExecutionContext *))
+FunctionObject *ExecutionEngine::newBuiltinFunction(ExecutionContext *scope, String *name, Value (*code)(ExecutionContext *))
 {
-    NativeFunction *f = new (memoryManager) NativeFunction(scope, name, code);
+    BuiltinFunction *f = new (memoryManager) BuiltinFunction(scope, name, code);
     f->prototype = scope->engine->functionPrototype;
     return f;
 }
index babaf1a..191268f 100644 (file)
@@ -168,7 +168,7 @@ struct ExecutionEngine
 
     VM::Function *newFunction(const QString &name);
 
-    FunctionObject *newNativeFunction(ExecutionContext *scope, String *name, Value (*code)(ExecutionContext *));
+    FunctionObject *newBuiltinFunction(ExecutionContext *scope, String *name, Value (*code)(ExecutionContext *));
     FunctionObject *newScriptFunction(ExecutionContext *scope, VM::Function *function);
     BoundFunction *newBoundFunction(ExecutionContext *scope, FunctionObject *target, Value boundThis, const QVector<Value> &boundArgs);
 
index faf3a86..fbc976d 100644 (file)
@@ -149,7 +149,7 @@ void Object::defineDefaultProperty(ExecutionContext *context, const QString &nam
 {
     Q_UNUSED(argumentCount);
     String *s = context->engine->identifier(name);
-    FunctionObject* function = context->engine->newNativeFunction(context, s, code);
+    FunctionObject* function = context->engine->newBuiltinFunction(context, s, code);
     function->defineReadonlyProperty(context->engine->id_length, Value::fromInt32(argumentCount));
     defineDefaultProperty(s, Value::fromObject(function));
 }
@@ -800,7 +800,7 @@ ScriptFunction::ScriptFunction(ExecutionContext *scope, VM::Function *function)
     prototype = scope->engine->functionPrototype;
 
     if (scope->strictMode) {
-        FunctionObject *thrower = scope->engine->newNativeFunction(scope, 0, __qmljs_throw_type_error);
+        FunctionObject *thrower = scope->engine->newBuiltinFunction(scope, 0, __qmljs_throw_type_error);
         PropertyDescriptor pd = PropertyDescriptor::fromAccessor(thrower, thrower);
         pd.configurable = PropertyDescriptor::Disabled;
         pd.enumberable = PropertyDescriptor::Disabled;
@@ -1174,15 +1174,15 @@ ArgumentsObject::ArgumentsObject(ExecutionContext *context, int formalParameterC
     if (context->strictMode) {
         for (uint i = 0; i < context->argumentCount; ++i)
             Object::__put__(context, QString::number(i), context->arguments[i]);
-        FunctionObject *thrower = context->engine->newNativeFunction(context, 0, __qmljs_throw_type_error);
+        FunctionObject *thrower = context->engine->newBuiltinFunction(context, 0, __qmljs_throw_type_error);
         PropertyDescriptor pd = PropertyDescriptor::fromAccessor(thrower, thrower);
         pd.configurable = PropertyDescriptor::Disabled;
         pd.enumberable = PropertyDescriptor::Disabled;
         __defineOwnProperty__(context, QStringLiteral("callee"), &pd);
         __defineOwnProperty__(context, QStringLiteral("caller"), &pd);
     } else {
-        FunctionObject *get = context->engine->newNativeFunction(context, 0, method_getArg);
-        FunctionObject *set = context->engine->newNativeFunction(context, 0, method_setArg);
+        FunctionObject *get = context->engine->newBuiltinFunction(context, 0, method_getArg);
+        FunctionObject *set = context->engine->newBuiltinFunction(context, 0, method_setArg);
         PropertyDescriptor pd = PropertyDescriptor::fromAccessor(get, set);
         pd.configurable = PropertyDescriptor::Enabled;
         pd.enumberable = PropertyDescriptor::Enabled;
@@ -1245,20 +1245,20 @@ Value ArgumentsObject::method_setArg(ExecutionContext *ctx)
     return Value::undefinedValue();
 }
 
-NativeFunction::NativeFunction(ExecutionContext *scope, String *name, Value (*code)(ExecutionContext *))
+BuiltinFunction::BuiltinFunction(ExecutionContext *scope, String *name, Value (*code)(ExecutionContext *))
     : FunctionObject(scope)
     , code(code)
 {
     this->name = name;
 }
 
-Value NativeFunction::construct(ExecutionContext *ctx)
+Value BuiltinFunction::construct(ExecutionContext *ctx)
 {
     ctx->throwTypeError();
     return Value::undefinedValue();
 }
 
-void NativeFunction::maybeAdjustThisObjectForDirectCall(ExecutionContext *context, Value thisArg)
+void BuiltinFunction::maybeAdjustThisObjectForDirectCall(ExecutionContext *context, Value thisArg)
 {
     // Built-in functions allow for the this object to be null or undefined. This overrides
     // the behaviour of changing thisObject to the global object if null/undefined and allows
@@ -1282,7 +1282,7 @@ BoundFunction::BoundFunction(ExecutionContext *scope, FunctionObject *target, Va
         len = 0;
     defineReadonlyProperty(scope->engine->id_length, Value::fromInt32(len));
 
-    FunctionObject *thrower = scope->engine->newNativeFunction(scope, 0, __qmljs_throw_type_error);
+    FunctionObject *thrower = scope->engine->newBuiltinFunction(scope, 0, __qmljs_throw_type_error);
     PropertyDescriptor pd = PropertyDescriptor::fromAccessor(thrower, thrower);
     pd.configurable = PropertyDescriptor::Disabled;
     pd.enumberable = PropertyDescriptor::Disabled;
index 8fae05c..7d376e2 100644 (file)
@@ -288,10 +288,10 @@ protected:
     virtual Value construct(ExecutionContext *ctx);
 };
 
-struct NativeFunction: FunctionObject {
+struct BuiltinFunction: FunctionObject {
     Value (*code)(ExecutionContext *);
 
-    NativeFunction(ExecutionContext *scope, String *name, Value (*code)(ExecutionContext *));
+    BuiltinFunction(ExecutionContext *scope, String *name, Value (*code)(ExecutionContext *));
     virtual Value call(ExecutionContext *ctx) { return code(ctx); }
     virtual Value construct(ExecutionContext *ctx);
     virtual void maybeAdjustThisObjectForDirectCall(ExecutionContext *context, Value thisArg);
index f5853d9..1c969db 100644 (file)
@@ -117,11 +117,6 @@ Value __qmljs_init_closure(VM::Function *clos, ExecutionContext *ctx)
     return Value::fromObject(ctx->engine->newScriptFunction(ctx, clos));
 }
 
-Value __qmljs_init_native_function(String *name, Value (*code)(ExecutionContext *), ExecutionContext *ctx)
-{
-    return Value::fromObject(ctx->engine->newNativeFunction(ctx, name, code));
-}
-
 Value __qmljs_string_literal_undefined(ExecutionContext *ctx)
 {
     return Value::fromString(ctx->engine->identifier(QStringLiteral("undefined")));
index 48e4fa2..6bd22f6 100644 (file)
@@ -109,7 +109,6 @@ void __qmljs_builtin_define_getter_setter(Value object, String *name, Value gett
 
 // constructors
 Value __qmljs_init_closure(VM::Function *clos, ExecutionContext *ctx);
-Value __qmljs_init_native_function(String *name, Value (*code)(ExecutionContext *), ExecutionContext *ctx);
 
 Bool __qmljs_is_function(Value value);