1425bb815Sopenharmony_ci/* Copyright JS Foundation and other contributors, http://js.foundation
2425bb815Sopenharmony_ci *
3425bb815Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4425bb815Sopenharmony_ci * you may not use this file except in compliance with the License.
5425bb815Sopenharmony_ci * You may obtain a copy of the License at
6425bb815Sopenharmony_ci *
7425bb815Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8425bb815Sopenharmony_ci *
9425bb815Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10425bb815Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS
11425bb815Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12425bb815Sopenharmony_ci * See the License for the specific language governing permissions and
13425bb815Sopenharmony_ci * limitations under the License.
14425bb815Sopenharmony_ci */
15425bb815Sopenharmony_ci
16425bb815Sopenharmony_ci#ifndef JS_PARSER_LIMITS_H
17425bb815Sopenharmony_ci#define JS_PARSER_LIMITS_H
18425bb815Sopenharmony_ci
19425bb815Sopenharmony_ci/** \addtogroup parser Parser
20425bb815Sopenharmony_ci * @{
21425bb815Sopenharmony_ci *
22425bb815Sopenharmony_ci * \addtogroup jsparser JavaScript
23425bb815Sopenharmony_ci * @{
24425bb815Sopenharmony_ci *
25425bb815Sopenharmony_ci * \addtogroup jsparser_internals Internals
26425bb815Sopenharmony_ci * @{
27425bb815Sopenharmony_ci */
28425bb815Sopenharmony_ci
29425bb815Sopenharmony_ci/**
30425bb815Sopenharmony_ci * Maximum identifier length accepted by the parser.
31425bb815Sopenharmony_ci * Limit: LEXER_MAX_STRING_LENGTH.
32425bb815Sopenharmony_ci */
33425bb815Sopenharmony_ci#ifndef PARSER_MAXIMUM_IDENT_LENGTH
34425bb815Sopenharmony_ci#define PARSER_MAXIMUM_IDENT_LENGTH 255
35425bb815Sopenharmony_ci#endif /* !PARSER_MAXIMUM_IDENT_LENGTH */
36425bb815Sopenharmony_ci
37425bb815Sopenharmony_ci/**
38425bb815Sopenharmony_ci * Maximum string limit.
39425bb815Sopenharmony_ci * Limit: 2147483647 / 65535.
40425bb815Sopenharmony_ci */
41425bb815Sopenharmony_ci#if ENABLED (JERRY_CPOINTER_32_BIT)
42425bb815Sopenharmony_ci#define PARSER_MAXIMUM_STRING_LIMIT 2147483647
43425bb815Sopenharmony_ci#else /* !ENABLED (JERRY_CPOINTER_32_BIT) */
44425bb815Sopenharmony_ci#define PARSER_MAXIMUM_STRING_LIMIT 65535
45425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_CPOINTER_32_BIT) */
46425bb815Sopenharmony_ci
47425bb815Sopenharmony_ci/**
48425bb815Sopenharmony_ci * Maximum string length.
49425bb815Sopenharmony_ci * Limit: PARSER_MAXIMUM_STRING_LIMIT.
50425bb815Sopenharmony_ci */
51425bb815Sopenharmony_ci#ifndef PARSER_MAXIMUM_STRING_LENGTH
52425bb815Sopenharmony_ci#define PARSER_MAXIMUM_STRING_LENGTH PARSER_MAXIMUM_STRING_LIMIT
53425bb815Sopenharmony_ci#endif /* !PARSER_MAXIMUM_STRING_LENGTH */
54425bb815Sopenharmony_ci
55425bb815Sopenharmony_ci/**
56425bb815Sopenharmony_ci * Maximum number of registers.
57425bb815Sopenharmony_ci * Limit: min: 256, max: min(PARSER_MAXIMUM_NUMBER_OF_LITERALS / 2, 16383)
58425bb815Sopenharmony_ci */
59425bb815Sopenharmony_ci#ifndef PARSER_MAXIMUM_NUMBER_OF_REGISTERS
60425bb815Sopenharmony_ci#define PARSER_MAXIMUM_NUMBER_OF_REGISTERS 256
61425bb815Sopenharmony_ci#endif /* !PARSER_MAXIMUM_NUMBER_OF_REGISTERS */
62425bb815Sopenharmony_ci
63425bb815Sopenharmony_ci/**
64425bb815Sopenharmony_ci * Maximum number of literals.
65425bb815Sopenharmony_ci * Limit: 32767 - PARSER_MAXIMUM_NUMBER_OF_REGISTERS. Recommended: 32767 - PARSER_MAXIMUM_NUMBER_OF_REGISTERS.
66425bb815Sopenharmony_ci */
67425bb815Sopenharmony_ci#ifndef PARSER_MAXIMUM_NUMBER_OF_LITERALS
68425bb815Sopenharmony_ci#define PARSER_MAXIMUM_NUMBER_OF_LITERALS (32767 - PARSER_MAXIMUM_NUMBER_OF_REGISTERS)
69425bb815Sopenharmony_ci#endif /* !PARSER_MAXIMUM_NUMBER_OF_LITERALS */
70425bb815Sopenharmony_ci
71425bb815Sopenharmony_ci/**
72425bb815Sopenharmony_ci * Maximum depth of scope stack.
73425bb815Sopenharmony_ci * Limit: 32767. Recommended: 32767
74425bb815Sopenharmony_ci */
75425bb815Sopenharmony_ci#ifndef PARSER_MAXIMUM_DEPTH_OF_SCOPE_STACK
76425bb815Sopenharmony_ci#define PARSER_MAXIMUM_DEPTH_OF_SCOPE_STACK 32767
77425bb815Sopenharmony_ci#endif /* !PARSER_MAXIMUM_DEPTH_OF_SCOPE_STACK */
78425bb815Sopenharmony_ci
79425bb815Sopenharmony_ci/**
80425bb815Sopenharmony_ci * Maximum code size.
81425bb815Sopenharmony_ci * Limit: 16777215. Recommended: 65535, 16777215.
82425bb815Sopenharmony_ci */
83425bb815Sopenharmony_ci#ifndef PARSER_MAXIMUM_CODE_SIZE
84425bb815Sopenharmony_ci#define PARSER_MAXIMUM_CODE_SIZE (65535 << (JMEM_ALIGNMENT_LOG))
85425bb815Sopenharmony_ci#endif /* !PARSER_MAXIMUM_CODE_SIZE */
86425bb815Sopenharmony_ci
87425bb815Sopenharmony_ci/**
88425bb815Sopenharmony_ci * Maximum number of values pushed onto the stack by a function.
89425bb815Sopenharmony_ci * Limit: 65500. Recommended: 1024.
90425bb815Sopenharmony_ci */
91425bb815Sopenharmony_ci#ifndef PARSER_MAXIMUM_STACK_LIMIT
92425bb815Sopenharmony_ci#define PARSER_MAXIMUM_STACK_LIMIT 1024
93425bb815Sopenharmony_ci
94425bb815Sopenharmony_ci#endif /* !PARSER_MAXIMUM_STACK_LIMIT */
95425bb815Sopenharmony_ci
96425bb815Sopenharmony_ci/* Checks. */
97425bb815Sopenharmony_ci
98425bb815Sopenharmony_ci#if (PARSER_MAXIMUM_STRING_LENGTH < 1) || (PARSER_MAXIMUM_STRING_LENGTH > PARSER_MAXIMUM_STRING_LIMIT)
99425bb815Sopenharmony_ci#error "Maximum string length is not within range."
100425bb815Sopenharmony_ci#endif /* (PARSER_MAXIMUM_STRING_LENGTH < 1) || (PARSER_MAXIMUM_STRING_LENGTH > PARSER_MAXIMUM_STRING_LIMIT) */
101425bb815Sopenharmony_ci
102425bb815Sopenharmony_ci#if (PARSER_MAXIMUM_IDENT_LENGTH < 1) || (PARSER_MAXIMUM_IDENT_LENGTH > PARSER_MAXIMUM_STRING_LENGTH)
103425bb815Sopenharmony_ci#error "Maximum identifier length is not within range."
104425bb815Sopenharmony_ci#endif /* (PARSER_MAXIMUM_IDENT_LENGTH < 1) || (PARSER_MAXIMUM_IDENT_LENGTH > PARSER_MAXIMUM_STRING_LENGTH) */
105425bb815Sopenharmony_ci
106425bb815Sopenharmony_ci#if ((PARSER_MAXIMUM_NUMBER_OF_LITERALS < 1) \
107425bb815Sopenharmony_ci     || (PARSER_MAXIMUM_NUMBER_OF_LITERALS + PARSER_MAXIMUM_NUMBER_OF_REGISTERS > 32767))
108425bb815Sopenharmony_ci#error "Maximum number of literals is not within range."
109425bb815Sopenharmony_ci#endif /* ((PARSER_MAXIMUM_NUMBER_OF_LITERALS < 1) \
110425bb815Sopenharmony_ci           || (PARSER_MAXIMUM_NUMBER_OF_LITERALS > 32767)) */
111425bb815Sopenharmony_ci
112425bb815Sopenharmony_ci#if (PARSER_MAXIMUM_DEPTH_OF_SCOPE_STACK < 1) || (PARSER_MAXIMUM_DEPTH_OF_SCOPE_STACK > 32767)
113425bb815Sopenharmony_ci#error "Maximum depth of scope stack is not within range."
114425bb815Sopenharmony_ci#endif /* (PARSER_MAXIMUM_DEPTH_OF_SCOPE_STACK < 1) || (PARSER_MAXIMUM_DEPTH_OF_SCOPE_STACK > 32767) */
115425bb815Sopenharmony_ci
116425bb815Sopenharmony_ci#if ((PARSER_MAXIMUM_NUMBER_OF_REGISTERS * 2) > PARSER_MAXIMUM_NUMBER_OF_LITERALS)
117425bb815Sopenharmony_ci#error "Maximum number of registers is not within range."
118425bb815Sopenharmony_ci#endif /* ((PARSER_MAXIMUM_NUMBER_OF_REGISTERS * 2) > PARSER_MAXIMUM_NUMBER_OF_LITERALS) */
119425bb815Sopenharmony_ci
120425bb815Sopenharmony_ci#if (PARSER_MAXIMUM_CODE_SIZE < 4096) || (PARSER_MAXIMUM_CODE_SIZE > 16777215)
121425bb815Sopenharmony_ci#error "Maximum code size is not within range."
122425bb815Sopenharmony_ci#endif /* (PARSER_MAXIMUM_CODE_SIZE < 4096) || (PARSER_MAXIMUM_CODE_SIZE > 16777215) */
123425bb815Sopenharmony_ci
124425bb815Sopenharmony_ci#if (PARSER_MAXIMUM_STACK_LIMIT < 16) || (PARSER_MAXIMUM_STACK_LIMIT > 65500)
125425bb815Sopenharmony_ci#error "Maximum function stack usage is not within range."
126425bb815Sopenharmony_ci#endif /* (PARSER_MAXIMUM_STACK_LIMIT < 16) || (PARSER_MAXIMUM_STACK_LIMIT > 65500) */
127425bb815Sopenharmony_ci
128425bb815Sopenharmony_ci/**
129425bb815Sopenharmony_ci * @}
130425bb815Sopenharmony_ci * @}
131425bb815Sopenharmony_ci * @}
132425bb815Sopenharmony_ci */
133425bb815Sopenharmony_ci
134425bb815Sopenharmony_ci#endif /* !JS_PARSER_LIMITS_H */
135