mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
Introducing ecma_get_magic_string that returns pointer to requested magic string that is used in an ECMA routine.
This commit is contained in:
parent
b059212e32
commit
df224408fc
@ -20,6 +20,7 @@
|
||||
#include "ecma-function-object.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-magic-strings.h"
|
||||
#include "ecma-number-arithmetic.h"
|
||||
#include "ecma-operations.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
@ -136,11 +137,10 @@ free_string_literal_copy(string_literal_copy *str_lit_descr_p) /**< string liter
|
||||
static bool
|
||||
do_strict_eval_arguments_check( ecma_reference_t ref) /**< ECMA-reference */
|
||||
{
|
||||
FIXME( Move magic strings to header file and make them ecma_char_t[] );
|
||||
FIXME( Replace strcmp with ecma_char_t[] comparator );
|
||||
return ( ref.is_strict
|
||||
&& ( __strcmp( (char*)ref.referenced_name_p, "eval") == 0
|
||||
|| __strcmp( (char*)ref.referenced_name_p, "arguments") == 0 )
|
||||
&& ( __strcmp( (char*)ref.referenced_name_p, (char*)ecma_get_magic_string( ECMA_MAGIC_STRING_EVAL)) == 0
|
||||
|| __strcmp( (char*)ref.referenced_name_p, (char*)ecma_get_magic_string( ECMA_MAGIC_STRING_ARGUMENTS)) == 0 )
|
||||
&& ( ref.base.value_type == ECMA_TYPE_OBJECT )
|
||||
&& ( ecma_get_pointer( ref.base.value) != NULL )
|
||||
&& ( ( (ecma_object_t*) ecma_get_pointer( ref.base.value) )->is_lexical_environment ) );
|
||||
|
||||
55
src/libecmaoperations/ecma-magic-strings.c
Normal file
55
src/libecmaoperations/ecma-magic-strings.c
Normal file
@ -0,0 +1,55 @@
|
||||
/* Copyright 2014 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-magic-strings.h"
|
||||
|
||||
/** \addtogroup ecma ---TODO---
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmamagicstrings Collection of magic string constants used in ECMA
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get specified magic string
|
||||
*
|
||||
* @return pointer to magic string contant
|
||||
*/
|
||||
const ecma_char_t*
|
||||
ecma_get_magic_string( ecma_magic_string_id_t id) /**< magic string id */
|
||||
{
|
||||
TODO( Support UTF-16 );
|
||||
|
||||
switch ( id )
|
||||
{
|
||||
case ECMA_MAGIC_STRING_ARGUMENTS:
|
||||
return (ecma_char_t*) "arguments";
|
||||
case ECMA_MAGIC_STRING_EVAL:
|
||||
return (ecma_char_t*) "eval";
|
||||
case ECMA_MAGIC_STRING_PROTOTYPE:
|
||||
return (ecma_char_t*) "prototype";
|
||||
case ECMA_MAGIC_STRING_CONSTRUCTOR:
|
||||
return (ecma_char_t*) "constructor";
|
||||
case ECMA_MAGIC_STRING_CALLER:
|
||||
return (ecma_char_t*) "caller";
|
||||
}
|
||||
|
||||
JERRY_UNREACHABLE();
|
||||
} /* ecma_get_magic_string */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
47
src/libecmaoperations/ecma-magic-strings.h
Normal file
47
src/libecmaoperations/ecma-magic-strings.h
Normal file
@ -0,0 +1,47 @@
|
||||
/* Copyright 2014 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.
|
||||
*/
|
||||
|
||||
#ifndef ECMA_MAGIC_STRINGS_H
|
||||
#define ECMA_MAGIC_STRINGS_H
|
||||
|
||||
#include "ecma-globals.h"
|
||||
|
||||
/** \addtogroup ecma ---TODO---
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmamagicstrings Collection of magic string constants used in ECMA
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Identifiers of ECMA magic string constants
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ECMA_MAGIC_STRING_ARGUMENTS, /**< "arguments" */
|
||||
ECMA_MAGIC_STRING_EVAL, /**< "eval" */
|
||||
ECMA_MAGIC_STRING_PROTOTYPE, /**< "prototype" */
|
||||
ECMA_MAGIC_STRING_CONSTRUCTOR, /**< "constructor" */
|
||||
ECMA_MAGIC_STRING_CALLER /**< "caller" */
|
||||
} ecma_magic_string_id_t;
|
||||
|
||||
extern const ecma_char_t* ecma_get_magic_string( ecma_magic_string_id_t id);
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* ECMA_MAGIC_STRINGS_H */
|
||||
Loading…
x
Reference in New Issue
Block a user