mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-27 04:01:11 +08:00
emit/vm: 受限词法名集回滚三常量——eval 为可配置全局属性属合法遮蔽(规范自有属性臂无静态受限臂),class eval 维持解析期拒绝独立钉住(类体恒严格,与受限集无关)
This commit is contained in:
@@ -9,13 +9,13 @@ use oxide_parser::{
|
|||||||
BindingPattern, Declaration, ExportDefaultDeclarationKind, Expression, Statement, VariableDeclarationKind,
|
BindingPattern, Declaration, ExportDefaultDeclarationKind, Expression, Statement, VariableDeclarationKind,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// 脚本顶层 lexical 声明(let/const/class)禁止使用的受限全局名:4 名静态集。
|
/// 脚本顶层 lexical 声明(let/const/class)禁止使用的受限全局名:3 名静态集。
|
||||||
/// 三常量是全局对象上 {configurable:false} 的自有属性名(声明实例化无法建立
|
/// 受限判定走规范自有属性臂:全局对象上 {configurable:false} 自有属性名(声明
|
||||||
/// 遮蔽绑定);eval 属静态受限臂(顶层 lexical 声明不得遮蔽,var/function
|
/// 实例化无法建立遮蔽绑定)——现行规范下恰为三常量;eval 与各 builtin 属性皆
|
||||||
/// 路径不受本集约束)。名基静态集(编译期不可查运行时描述符)。与
|
/// 可配置(合法遮蔽),不在此列。名基静态集(编译期不可查运行时描述符)。与
|
||||||
/// BUILTIN_GLOBALS 语义不同(后者是 put 写拦截/双写名单),不互相派生,交叠
|
/// BUILTIN_GLOBALS 语义不同(后者是 put 写拦截/双写名单),不互相派生,交叠
|
||||||
/// 名由漂移守卫单测断言恒同步。
|
/// 名由漂移守卫单测断言恒同步。
|
||||||
pub(crate) const RESTRICTED_GLOBAL_LEXICAL_NAMES: &[&str] = &["undefined", "eval", "NaN", "Infinity"];
|
pub(crate) const RESTRICTED_GLOBAL_LEXICAL_NAMES: &[&str] = &["undefined", "NaN", "Infinity"];
|
||||||
|
|
||||||
/// 脚本顶层 lexical 声明撞受限全局名 → SyntaxError(声明实例化期拒绝,整程序
|
/// 脚本顶层 lexical 声明撞受限全局名 → SyntaxError(声明实例化期拒绝,整程序
|
||||||
/// 编译失败)。错误消息与既有重复声明错同形;非顶层或名不在受限集 → Ok。
|
/// 编译失败)。错误消息与既有重复声明错同形;非顶层或名不在受限集 → Ok。
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
//! 脚本顶层 lexical 声明撞受限全局名的编译期拒绝:let/const/class 声明名撞
|
//! 脚本顶层 lexical 声明撞受限全局名的编译期拒绝:let/const 声明名撞
|
||||||
//! 受限集(undefined/eval/NaN/Infinity——三常量不可配置自有属性 + eval 静态
|
//! 受限集(undefined/NaN/Infinity——三常量,全局对象 {configurable:false}
|
||||||
//! 受限臂)→ SyntaxError(整程序编译失败)。局部作用域(函数体/块/try)与
|
//! 自有属性名)→ SyntaxError(整程序编译失败)。局部作用域(函数体/块/try)与
|
||||||
//! eval 代码为合法遮蔽不拒;三常数值使用不受影响。
|
//! eval 代码为合法遮蔽不拒;三常数值使用不受影响。
|
||||||
|
//!
|
||||||
|
//! class 名撞 eval 不在本集(解析器 early-error 族独立拒绝,类体恒严格模式,
|
||||||
|
//! 与受限集检查无关,见 top_level_class_eval_name_rejected)。
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@@ -108,21 +111,25 @@ fn top_level_let_uses_nan_value_allowed() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn top_level_let_eval_name_rejected() {
|
fn top_level_let_eval_name_allowed() {
|
||||||
// eval 属静态受限臂:顶层 lexical 声明不得遮蔽(var/function 路径不受
|
// eval 是全局对象可配置自有属性(受限判定走自有属性臂,eval 不命中):
|
||||||
// 本集约束)。
|
// 合法遮蔽,不在受限集。
|
||||||
assert_compile_err("let eval;");
|
let r = assert_ok("let eval; 1");
|
||||||
|
assert_eq!(r.as_int(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn top_level_const_eval_name_rejected() {
|
fn top_level_const_eval_name_allowed() {
|
||||||
assert_compile_err("const eval = 1;");
|
let r = assert_ok("const eval = 1; 1");
|
||||||
|
assert_eq!(r.as_int(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn top_level_class_eval_name_rejected() {
|
fn top_level_class_eval_name_rejected() {
|
||||||
// 若解析器更早拒绝(early error 族),亦接受该拒绝相位(整程序拒绝可观察
|
// eval 不在受限集(let/const 合法遮蔽),但 class 名撞 eval 由解析器
|
||||||
// 行为同形)。
|
// early-error 族拒绝:类体恒严格模式,类名绑定检查落在类作用域 strict
|
||||||
|
// 判定内(V8 同形:sloppy `class eval {}` 亦 SyntaxError)。与本受限集
|
||||||
|
// 检查无关,整程序拒绝可观察行为同形,断言任意拒绝相位。
|
||||||
assert!(eval("class eval {}").is_err(), "class eval 类名应被拒绝");
|
assert!(eval("class eval {}").is_err(), "class eval 类名应被拒绝");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user