From: Erik Verbruggen Date: Wed, 16 Jan 2013 10:41:23 +0000 (+0100) Subject: Rename native functions to builtin functions. X-Git-Tag: upstream/5.2.1~669^2~659^2~506 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=821e5806d9743f2b1f97b13fb9877d63f559ea18;p=platform%2Fupstream%2Fqtdeclarative.git Rename native functions to builtin functions. 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 --- diff --git a/llvm_runtime.cpp b/llvm_runtime.cpp index 6a0c163..dd5a625 100644 --- a/llvm_runtime.cpp +++ b/llvm_runtime.cpp @@ -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); diff --git a/qmljs_engine.cpp b/qmljs_engine.cpp index 6367dcc..2d34b3d 100644 --- a/qmljs_engine.cpp +++ b/qmljs_engine.cpp @@ -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; } diff --git a/qmljs_engine.h b/qmljs_engine.h index babaf1a..191268f 100644 --- a/qmljs_engine.h +++ b/qmljs_engine.h @@ -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 &boundArgs); diff --git a/qmljs_objects.cpp b/qmljs_objects.cpp index faf3a86..fbc976d 100644 --- a/qmljs_objects.cpp +++ b/qmljs_objects.cpp @@ -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; diff --git a/qmljs_objects.h b/qmljs_objects.h index 8fae05c..7d376e2 100644 --- a/qmljs_objects.h +++ b/qmljs_objects.h @@ -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); diff --git a/qmljs_runtime.cpp b/qmljs_runtime.cpp index f5853d9..1c969db 100644 --- a/qmljs_runtime.cpp +++ b/qmljs_runtime.cpp @@ -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"))); diff --git a/qmljs_runtime.h b/qmljs_runtime.h index 48e4fa2..6bd22f6 100644 --- a/qmljs_runtime.h +++ b/qmljs_runtime.h @@ -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);