1 /* Copyright JS Foundation and other contributors, http://js.foundation 2 * 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef JS_PARSER_LIMITS_H 17 #define JS_PARSER_LIMITS_H 18 19 /** \addtogroup parser Parser 20 * @{ 21 * 22 * \addtogroup jsparser JavaScript 23 * @{ 24 * 25 * \addtogroup jsparser_internals Internals 26 * @{ 27 */ 28 29 /** 30 * Maximum identifier length accepted by the parser. 31 * Limit: LEXER_MAX_STRING_LENGTH. 32 */ 33 #ifndef PARSER_MAXIMUM_IDENT_LENGTH 34 #define PARSER_MAXIMUM_IDENT_LENGTH 255 35 #endif /* !PARSER_MAXIMUM_IDENT_LENGTH */ 36 37 /** 38 * Maximum string limit. 39 * Limit: 2147483647 / 65535. 40 */ 41 #if ENABLED (JERRY_CPOINTER_32_BIT) 42 #define PARSER_MAXIMUM_STRING_LIMIT 2147483647 43 #else /* !ENABLED (JERRY_CPOINTER_32_BIT) */ 44 #define PARSER_MAXIMUM_STRING_LIMIT 65535 45 #endif /* ENABLED (JERRY_CPOINTER_32_BIT) */ 46 47 /** 48 * Maximum string length. 49 * Limit: PARSER_MAXIMUM_STRING_LIMIT. 50 */ 51 #ifndef PARSER_MAXIMUM_STRING_LENGTH 52 #define PARSER_MAXIMUM_STRING_LENGTH PARSER_MAXIMUM_STRING_LIMIT 53 #endif /* !PARSER_MAXIMUM_STRING_LENGTH */ 54 55 /** 56 * Maximum number of registers. 57 * Limit: min: 256, max: min(PARSER_MAXIMUM_NUMBER_OF_LITERALS / 2, 16383) 58 */ 59 #ifndef PARSER_MAXIMUM_NUMBER_OF_REGISTERS 60 #define PARSER_MAXIMUM_NUMBER_OF_REGISTERS 256 61 #endif /* !PARSER_MAXIMUM_NUMBER_OF_REGISTERS */ 62 63 /** 64 * Maximum number of literals. 65 * Limit: 32767 - PARSER_MAXIMUM_NUMBER_OF_REGISTERS. Recommended: 32767 - PARSER_MAXIMUM_NUMBER_OF_REGISTERS. 66 */ 67 #ifndef PARSER_MAXIMUM_NUMBER_OF_LITERALS 68 #define PARSER_MAXIMUM_NUMBER_OF_LITERALS (32767 - PARSER_MAXIMUM_NUMBER_OF_REGISTERS) 69 #endif /* !PARSER_MAXIMUM_NUMBER_OF_LITERALS */ 70 71 /** 72 * Maximum depth of scope stack. 73 * Limit: 32767. Recommended: 32767 74 */ 75 #ifndef PARSER_MAXIMUM_DEPTH_OF_SCOPE_STACK 76 #define PARSER_MAXIMUM_DEPTH_OF_SCOPE_STACK 32767 77 #endif /* !PARSER_MAXIMUM_DEPTH_OF_SCOPE_STACK */ 78 79 /** 80 * Maximum code size. 81 * Limit: 16777215. Recommended: 65535, 16777215. 82 */ 83 #ifndef PARSER_MAXIMUM_CODE_SIZE 84 #define PARSER_MAXIMUM_CODE_SIZE (65535 << (JMEM_ALIGNMENT_LOG)) 85 #endif /* !PARSER_MAXIMUM_CODE_SIZE */ 86 87 /** 88 * Maximum number of values pushed onto the stack by a function. 89 * Limit: 65500. Recommended: 1024. 90 */ 91 #ifndef PARSER_MAXIMUM_STACK_LIMIT 92 #define PARSER_MAXIMUM_STACK_LIMIT 1024 93 94 #endif /* !PARSER_MAXIMUM_STACK_LIMIT */ 95 96 /* Checks. */ 97 98 #if (PARSER_MAXIMUM_STRING_LENGTH < 1) || (PARSER_MAXIMUM_STRING_LENGTH > PARSER_MAXIMUM_STRING_LIMIT) 99 #error "Maximum string length is not within range." 100 #endif /* (PARSER_MAXIMUM_STRING_LENGTH < 1) || (PARSER_MAXIMUM_STRING_LENGTH > PARSER_MAXIMUM_STRING_LIMIT) */ 101 102 #if (PARSER_MAXIMUM_IDENT_LENGTH < 1) || (PARSER_MAXIMUM_IDENT_LENGTH > PARSER_MAXIMUM_STRING_LENGTH) 103 #error "Maximum identifier length is not within range." 104 #endif /* (PARSER_MAXIMUM_IDENT_LENGTH < 1) || (PARSER_MAXIMUM_IDENT_LENGTH > PARSER_MAXIMUM_STRING_LENGTH) */ 105 106 #if ((PARSER_MAXIMUM_NUMBER_OF_LITERALS < 1) \ 107 || (PARSER_MAXIMUM_NUMBER_OF_LITERALS + PARSER_MAXIMUM_NUMBER_OF_REGISTERS > 32767)) 108 #error "Maximum number of literals is not within range." 109 #endif /* ((PARSER_MAXIMUM_NUMBER_OF_LITERALS < 1) \ 110 || (PARSER_MAXIMUM_NUMBER_OF_LITERALS > 32767)) */ 111 112 #if (PARSER_MAXIMUM_DEPTH_OF_SCOPE_STACK < 1) || (PARSER_MAXIMUM_DEPTH_OF_SCOPE_STACK > 32767) 113 #error "Maximum depth of scope stack is not within range." 114 #endif /* (PARSER_MAXIMUM_DEPTH_OF_SCOPE_STACK < 1) || (PARSER_MAXIMUM_DEPTH_OF_SCOPE_STACK > 32767) */ 115 116 #if ((PARSER_MAXIMUM_NUMBER_OF_REGISTERS * 2) > PARSER_MAXIMUM_NUMBER_OF_LITERALS) 117 #error "Maximum number of registers is not within range." 118 #endif /* ((PARSER_MAXIMUM_NUMBER_OF_REGISTERS * 2) > PARSER_MAXIMUM_NUMBER_OF_LITERALS) */ 119 120 #if (PARSER_MAXIMUM_CODE_SIZE < 4096) || (PARSER_MAXIMUM_CODE_SIZE > 16777215) 121 #error "Maximum code size is not within range." 122 #endif /* (PARSER_MAXIMUM_CODE_SIZE < 4096) || (PARSER_MAXIMUM_CODE_SIZE > 16777215) */ 123 124 #if (PARSER_MAXIMUM_STACK_LIMIT < 16) || (PARSER_MAXIMUM_STACK_LIMIT > 65500) 125 #error "Maximum function stack usage is not within range." 126 #endif /* (PARSER_MAXIMUM_STACK_LIMIT < 16) || (PARSER_MAXIMUM_STACK_LIMIT > 65500) */ 127 128 /** 129 * @} 130 * @} 131 * @} 132 */ 133 134 #endif /* !JS_PARSER_LIMITS_H */ 135