mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
Implementation of Function.prototype.call.
This commit is contained in:
parent
18079fb4d3
commit
810e3c7ae8
@ -20,8 +20,7 @@
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-string-object.h"
|
||||
#include "ecma-function-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jrt.h"
|
||||
|
||||
@ -88,7 +87,29 @@ ecma_builtin_function_prototype_object_call (const ecma_value_t& this_arg, /**<
|
||||
const ecma_value_t* arguments_list_p, /**< list of arguments */
|
||||
ecma_length_t arguments_number) /**< number of arguments */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arguments_list_p, arguments_number);
|
||||
if (!ecma_op_is_callable (this_arg))
|
||||
{
|
||||
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_object_t *func_obj_p = ecma_get_object_from_value (this_arg);
|
||||
|
||||
if (arguments_number == 0)
|
||||
{
|
||||
return ecma_op_function_call (func_obj_p,
|
||||
ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED),
|
||||
NULL,
|
||||
0);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ecma_op_function_call (func_obj_p,
|
||||
arguments_list_p [0],
|
||||
(arguments_number == 1u) ? NULL : (arguments_list_p + 1),
|
||||
(ecma_length_t) (arguments_number - 1u));
|
||||
}
|
||||
}
|
||||
} /* ecma_builtin_function_prototype_object_call */
|
||||
|
||||
/**
|
||||
|
||||
28
tests/jerry/function.prototype.js
Normal file
28
tests/jerry/function.prototype.js
Normal file
@ -0,0 +1,28 @@
|
||||
// Copyright 2015 Samsung Electronics Co., Ltd.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
function f (arg1, arg2, arg3)
|
||||
{
|
||||
this.string = arg1;
|
||||
this.number = arg2;
|
||||
this.boolean = arg3;
|
||||
}
|
||||
|
||||
var this_arg = {};
|
||||
|
||||
f.call (this_arg, 's', 1, true, null);
|
||||
|
||||
assert (this_arg.string === 's');
|
||||
assert (this_arg.number === 1);
|
||||
assert (this_arg.boolean === true);
|
||||
Loading…
x
Reference in New Issue
Block a user