mirror of https://github.com/boa-dev/boa.git
croraf
4 years ago
committed by
GitHub
11 changed files with 125 additions and 30 deletions
@ -0,0 +1,32 @@
|
||||
//! This module implements the global `undefined` property.
|
||||
//!
|
||||
//! The global undefined property represents the primitive value undefined.
|
||||
//!
|
||||
//! More information:
|
||||
//! - [MDN documentation][mdn]
|
||||
//! - [ECMAScript reference][spec]
|
||||
//!
|
||||
//! [spec]: https://tc39.es/ecma262/#sec-undefined
|
||||
//! [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined
|
||||
|
||||
#[cfg(test)] |
||||
mod tests; |
||||
|
||||
use crate::{builtins::value::Value, BoaProfiler}; |
||||
|
||||
/// JavaScript global `undefined` property.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] |
||||
pub(crate) struct Undefined; |
||||
|
||||
impl Undefined { |
||||
/// The binding name of the property.
|
||||
pub(crate) const NAME: &'static str = "undefined"; |
||||
|
||||
/// Initialize the `undefined` property on the global object.
|
||||
#[inline] |
||||
pub(crate) fn init(_: &Value) -> (&str, Value) { |
||||
let _timer = BoaProfiler::global().start_event(Self::NAME, "init"); |
||||
|
||||
(Self::NAME, Value::undefined()) |
||||
} |
||||
} |
@ -0,0 +1,18 @@
|
||||
use crate::exec; |
||||
|
||||
#[test] |
||||
fn undefined_direct_evaluation() { |
||||
let scenario = r#" |
||||
undefined; |
||||
"#; |
||||
assert_eq!(&exec(scenario), "undefined"); |
||||
} |
||||
|
||||
#[test] |
||||
fn undefined_assignment() { |
||||
let scenario = r#" |
||||
a = undefined; |
||||
a |
||||
"#; |
||||
assert_eq!(&exec(scenario), "undefined"); |
||||
} |
@ -0,0 +1,28 @@
|
||||
use crate::exec; |
||||
|
||||
#[test] |
||||
fn assignmentoperator_lhs_not_defined() { |
||||
let scenario = r#" |
||||
try { |
||||
a += 5 |
||||
} catch (err) { |
||||
err.message |
||||
} |
||||
"#; |
||||
|
||||
assert_eq!(&exec(scenario), "a is not defined"); |
||||
} |
||||
|
||||
#[test] |
||||
fn assignmentoperator_rhs_throws_error() { |
||||
let scenario = r#" |
||||
try { |
||||
let a; |
||||
a += b |
||||
} catch (err) { |
||||
err.message |
||||
} |
||||
"#; |
||||
|
||||
assert_eq!(&exec(scenario), "b is not defined"); |
||||
} |
Loading…
Reference in new issue