mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
248 lines
7.5 KiB
C++
248 lines
7.5 KiB
C++
/* Copyright 2014-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.
|
|
*/
|
|
|
|
#include "ecma-alloc.h"
|
|
#include "ecma-builtins.h"
|
|
#include "ecma-conversion.h"
|
|
#include "ecma-eval.h"
|
|
#include "ecma-gc.h"
|
|
#include "ecma-globals.h"
|
|
#include "ecma-helpers.h"
|
|
#include "ecma-try-catch-macro.h"
|
|
#include "jrt.h"
|
|
#include "vm.h"
|
|
|
|
#define ECMA_BUILTINS_INTERNAL
|
|
#include "ecma-builtins-internal.h"
|
|
|
|
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-global.inc.h"
|
|
#define BUILTIN_UNDERSCORED_ID global
|
|
#include "ecma-builtin-internal-routines-template.inc.h"
|
|
|
|
/** \addtogroup ecma ECMA
|
|
* @{
|
|
*
|
|
* \addtogroup ecmabuiltins
|
|
* @{
|
|
*
|
|
* \addtogroup global ECMA Global object built-in
|
|
* @{
|
|
*/
|
|
|
|
/**
|
|
* The Global object's 'eval' routine
|
|
*
|
|
* See also:
|
|
* ECMA-262 v5, 15.1.2.1
|
|
*
|
|
* @return completion value
|
|
* Returned value must be freed with ecma_free_completion_value.
|
|
*/
|
|
static ecma_completion_value_t
|
|
ecma_builtin_global_object_eval (ecma_value_t this_arg, /**< this argument */
|
|
ecma_value_t x) /**< routine's first argument */
|
|
{
|
|
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
|
|
|
|
bool is_direct_eval = vm_is_direct_eval_form_call ();
|
|
JERRY_ASSERT (!(is_direct_eval
|
|
&& !ecma_is_value_undefined (this_arg)));
|
|
|
|
/* See also: ECMA-262 v5, 10.1.1 */
|
|
bool is_called_from_strict_mode_code;
|
|
if (is_direct_eval)
|
|
{
|
|
is_called_from_strict_mode_code = vm_is_strict_mode ();
|
|
}
|
|
else
|
|
{
|
|
is_called_from_strict_mode_code = false;
|
|
}
|
|
|
|
if (!ecma_is_value_string (x))
|
|
{
|
|
/* step 1 */
|
|
ret_value = ecma_make_normal_completion_value (ecma_copy_value (x, true));
|
|
}
|
|
else
|
|
{
|
|
/* steps 2 to 8 */
|
|
ret_value = ecma_op_eval (ecma_get_string_from_value (x),
|
|
is_direct_eval,
|
|
is_called_from_strict_mode_code);
|
|
}
|
|
|
|
return ret_value;
|
|
} /* ecma_builtin_global_object_eval */
|
|
|
|
/**
|
|
* The Global object's 'parseInt' routine
|
|
*
|
|
* See also:
|
|
* ECMA-262 v5, 15.1.2.2
|
|
*
|
|
* @return completion value
|
|
* Returned value must be freed with ecma_free_completion_value.
|
|
*/
|
|
static ecma_completion_value_t
|
|
ecma_builtin_global_object_parse_int (ecma_value_t this_arg, /**< this argument */
|
|
ecma_value_t string, /**< routine's first argument */
|
|
ecma_value_t radix) /**< routine's second argument */
|
|
{
|
|
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, string, radix);
|
|
} /* ecma_builtin_global_object_parse_int */
|
|
|
|
/**
|
|
* The Global object's 'parseFloat' routine
|
|
*
|
|
* See also:
|
|
* ECMA-262 v5, 15.1.2.3
|
|
*
|
|
* @return completion value
|
|
* Returned value must be freed with ecma_free_completion_value.
|
|
*/
|
|
static ecma_completion_value_t
|
|
ecma_builtin_global_object_parse_float (ecma_value_t this_arg, /**< this argument */
|
|
ecma_value_t string) /**< routine's first argument */
|
|
{
|
|
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, string);
|
|
} /* ecma_builtin_global_object_parse_float */
|
|
|
|
/**
|
|
* The Global object's 'isNaN' routine
|
|
*
|
|
* See also:
|
|
* ECMA-262 v5, 15.1.2.4
|
|
*
|
|
* @return completion value
|
|
* Returned value must be freed with ecma_free_completion_value.
|
|
*/
|
|
static ecma_completion_value_t
|
|
ecma_builtin_global_object_is_nan (ecma_value_t this_arg __attr_unused___, /**< this argument */
|
|
ecma_value_t arg) /**< routine's first argument */
|
|
{
|
|
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
|
|
|
|
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, arg, ret_value);
|
|
|
|
bool is_nan = ecma_number_is_nan (arg_num);
|
|
|
|
ret_value = ecma_make_simple_completion_value (is_nan ? ECMA_SIMPLE_VALUE_TRUE
|
|
: ECMA_SIMPLE_VALUE_FALSE);
|
|
|
|
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
|
|
|
|
return ret_value;
|
|
} /* ecma_builtin_global_object_is_nan */
|
|
|
|
/**
|
|
* The Global object's 'isFinite' routine
|
|
*
|
|
* See also:
|
|
* ECMA-262 v5, 15.1.2.5
|
|
*
|
|
* @return completion value
|
|
* Returned value must be freed with ecma_free_completion_value.
|
|
*/
|
|
static ecma_completion_value_t
|
|
ecma_builtin_global_object_is_finite (ecma_value_t this_arg __attr_unused___, /**< this argument */
|
|
ecma_value_t arg) /**< routine's first argument */
|
|
{
|
|
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
|
|
|
|
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, arg, ret_value);
|
|
|
|
bool is_finite = !(ecma_number_is_nan (arg_num)
|
|
|| ecma_number_is_infinity (arg_num));
|
|
|
|
ret_value = ecma_make_simple_completion_value (is_finite ? ECMA_SIMPLE_VALUE_TRUE
|
|
: ECMA_SIMPLE_VALUE_FALSE);
|
|
|
|
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
|
|
|
|
return ret_value;
|
|
} /* ecma_builtin_global_object_is_finite */
|
|
|
|
/**
|
|
* The Global object's 'decodeURI' routine
|
|
*
|
|
* See also:
|
|
* ECMA-262 v5, 15.1.3.1
|
|
*
|
|
* @return completion value
|
|
* Returned value must be freed with ecma_free_completion_value.
|
|
*/
|
|
static ecma_completion_value_t
|
|
ecma_builtin_global_object_decode_uri (ecma_value_t this_arg, /**< this argument */
|
|
ecma_value_t encoded_uri) /**< routine's first argument */
|
|
{
|
|
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, encoded_uri);
|
|
} /* ecma_builtin_global_object_decode_uri */
|
|
|
|
/**
|
|
* The Global object's 'decodeURIComponent' routine
|
|
*
|
|
* See also:
|
|
* ECMA-262 v5, 15.1.3.2
|
|
*
|
|
* @return completion value
|
|
* Returned value must be freed with ecma_free_completion_value.
|
|
*/
|
|
static ecma_completion_value_t
|
|
ecma_builtin_global_object_decode_uri_component (ecma_value_t this_arg, /**< this argument */
|
|
ecma_value_t encoded_uri_component) /**< routine's
|
|
* first argument */
|
|
{
|
|
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, encoded_uri_component);
|
|
} /* ecma_builtin_global_object_decode_uri_component */
|
|
|
|
/**
|
|
* The Global object's 'encodeURI' routine
|
|
*
|
|
* See also:
|
|
* ECMA-262 v5, 15.1.3.3
|
|
*
|
|
* @return completion value
|
|
* Returned value must be freed with ecma_free_completion_value.
|
|
*/
|
|
static ecma_completion_value_t
|
|
ecma_builtin_global_object_encode_uri (ecma_value_t this_arg, /**< this argument */
|
|
ecma_value_t uri) /**< routine's first argument */
|
|
{
|
|
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, uri);
|
|
} /* ecma_builtin_global_object_encode_uri */
|
|
|
|
/**
|
|
* The Global object's 'encodeURIComponent' routine
|
|
*
|
|
* See also:
|
|
* ECMA-262 v5, 15.1.3.4
|
|
*
|
|
* @return completion value
|
|
* Returned value must be freed with ecma_free_completion_value.
|
|
*/
|
|
static ecma_completion_value_t
|
|
ecma_builtin_global_object_encode_uri_component (ecma_value_t this_arg, /**< this argument */
|
|
ecma_value_t uri_component) /**< routine's first argument */
|
|
{
|
|
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, uri_component);
|
|
} /* ecma_builtin_global_object_encode_uri_component */
|
|
|
|
/**
|
|
* @}
|
|
* @}
|
|
* @}
|
|
*/
|