mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-24 02:31:13 +08:00
fix: Date toPrimitive 单测钉改严格脚本并推进版本
This commit is contained in:
@@ -989,12 +989,14 @@ fn date_to_primitive_user_throw_propagates_original() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn date_to_primitive_called_as_function_no_strict_this() {
|
||||
fn date_to_primitive_called_as_function_strict_this() {
|
||||
let mut vm = Vm::new();
|
||||
// 顶层函数形态调用(this 为 undefined)抛 TypeError,且不触发 toString/valueOf 查找。
|
||||
// 严格脚本顶层函数形态调用(this 为 undefined)抛 TypeError,且不触发 toString/valueOf 查找。
|
||||
// 用严格脚本使 this 恒为 undefined(规范保证),不依赖 sloppy 顶层 this 绑定
|
||||
// (JS 函数与 native 函数两条路径取值不同,前者替换为全局对象、后者保留 undefined)。
|
||||
let r = eval(
|
||||
&mut vm,
|
||||
"var toPrimitive = Date.prototype[Symbol.toPrimitive]; \
|
||||
"'use strict'; var toPrimitive = Date.prototype[Symbol.toPrimitive]; \
|
||||
try { toPrimitive('default'); 'no' } catch (e) { e instanceof TypeError ? 'yes' : 'no' }",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
Reference in New Issue
Block a user