-
-
Notifications
You must be signed in to change notification settings - Fork 561
Added undefined property to global scope #501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
9e2673a
Fix identifier resolution
croraf f782a4d
Debug
croraf 7e152c6
Fix: define ReferenceError on global object
croraf b50538b
Format
croraf 54907c8
Temp
croraf f905f12
Rearange some tests
croraf 95cd526
Ignore some tests which are awaiting other tickets
croraf 40028e7
Merge branch 'master' into reference_error
croraf 1aeb95c
Merge resolution
croraf 3c62b33
Fix: construct_reference_error
croraf b34da02
Unignore 4 tests
croraf c810be5
[undefined] add property to global scope
croraf e3d80a2
Merge branch 'master' into undefined
croraf ff07911
formatting
croraf e879bca
Add couple of tests
croraf d2b0ff5
Tests
croraf e40788d
Remove 2 comments
croraf ada9cc9
Replace unwrap with expect
croraf 4c1e6a6
Minor - use ok_or_else instead of match construct
croraf 74974e2
Cover assignmetoperator undefined case and test
croraf d1126e1
Merge branch 'master' into undefined
croraf 50f1381
Replace throw_reference_eror with construct_reference_error
croraf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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()) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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"); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,16 @@ | ||
| use super::{Executable, Interpreter}; | ||
| use crate::{ | ||
| builtins::value::{ResultValue, Value, ValueData}, | ||
| syntax::ast::node::identifier::Identifier, | ||
| }; | ||
| use crate::{builtins::value::ResultValue, syntax::ast::node::identifier::Identifier}; | ||
|
|
||
| impl Executable for Identifier { | ||
| fn run(&self, interpreter: &mut Interpreter) -> ResultValue { | ||
| let reference = resolve_binding(interpreter, self.as_ref()); | ||
| match reference.data() { | ||
| ValueData::Undefined => Err(interpreter | ||
| .throw_reference_error(self.as_ref()) | ||
| .expect_err("throw_reference_error() must return an error")), | ||
| _ => Ok(reference), | ||
| } | ||
| interpreter | ||
| .realm() | ||
| .environment | ||
| .get_binding_value(self.as_ref()) | ||
| .ok_or_else(|| { | ||
| interpreter | ||
| .throw_reference_error(self.as_ref()) | ||
| .expect_err("throw_reference_error() must return an error") | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| pub(crate) fn resolve_binding(interpreter: &mut Interpreter, name: &str) -> Value { | ||
| interpreter.realm().environment.get_binding_value(name) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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"); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.