mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:47:45 +00:00
LibJS: Convert has_restricted_global_property() to ThrowCompletionOr
This commit is contained in:
parent
9571631b58
commit
1817c1f83c
3 changed files with 6 additions and 5 deletions
|
@ -3593,9 +3593,10 @@ ThrowCompletionOr<void> Program::global_declaration_instantiation(Interpreter& i
|
||||||
return IterationDecision::Break;
|
return IterationDecision::Break;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto restricted_global = global_environment.has_restricted_global_property(name);
|
auto restricted_global_or_error = global_environment.has_restricted_global_property(name);
|
||||||
if (interpreter.exception())
|
if (restricted_global_or_error.is_error())
|
||||||
return IterationDecision::Break;
|
return IterationDecision::Break;
|
||||||
|
auto restricted_global = restricted_global_or_error.release_value();
|
||||||
|
|
||||||
if (restricted_global)
|
if (restricted_global)
|
||||||
interpreter.vm().throw_exception<SyntaxError>(global_object, ErrorType::RestrictedGlobalProperty, name);
|
interpreter.vm().throw_exception<SyntaxError>(global_object, ErrorType::RestrictedGlobalProperty, name);
|
||||||
|
|
|
@ -175,14 +175,14 @@ bool GlobalEnvironment::has_lexical_declaration(FlyString const& name) const
|
||||||
}
|
}
|
||||||
|
|
||||||
// 9.1.1.4.14 HasRestrictedGlobalProperty ( N ), https://tc39.es/ecma262/#sec-hasrestrictedglobalproperty
|
// 9.1.1.4.14 HasRestrictedGlobalProperty ( N ), https://tc39.es/ecma262/#sec-hasrestrictedglobalproperty
|
||||||
bool GlobalEnvironment::has_restricted_global_property(FlyString const& name) const
|
ThrowCompletionOr<bool> GlobalEnvironment::has_restricted_global_property(FlyString const& name) const
|
||||||
{
|
{
|
||||||
// 1. Let ObjRec be envRec.[[ObjectRecord]].
|
// 1. Let ObjRec be envRec.[[ObjectRecord]].
|
||||||
// 2. Let globalObject be ObjRec.[[BindingObject]].
|
// 2. Let globalObject be ObjRec.[[BindingObject]].
|
||||||
auto& global_object = m_object_record->binding_object();
|
auto& global_object = m_object_record->binding_object();
|
||||||
|
|
||||||
// 3. Let existingProp be ? globalObject.[[GetOwnProperty]](N).
|
// 3. Let existingProp be ? globalObject.[[GetOwnProperty]](N).
|
||||||
auto existing_prop = TRY_OR_DISCARD(global_object.internal_get_own_property(name));
|
auto existing_prop = TRY(global_object.internal_get_own_property(name));
|
||||||
|
|
||||||
// 4. If existingProp is undefined, return false.
|
// 4. If existingProp is undefined, return false.
|
||||||
if (!existing_prop.has_value())
|
if (!existing_prop.has_value())
|
||||||
|
|
|
@ -33,7 +33,7 @@ public:
|
||||||
|
|
||||||
bool has_var_declaration(FlyString const& name) const;
|
bool has_var_declaration(FlyString const& name) const;
|
||||||
bool has_lexical_declaration(FlyString const& name) const;
|
bool has_lexical_declaration(FlyString const& name) const;
|
||||||
bool has_restricted_global_property(FlyString const& name) const;
|
ThrowCompletionOr<bool> has_restricted_global_property(FlyString const& name) const;
|
||||||
bool can_declare_global_var(FlyString const& name) const;
|
bool can_declare_global_var(FlyString const& name) const;
|
||||||
bool can_declare_global_function(FlyString const& name) const;
|
bool can_declare_global_function(FlyString const& name) const;
|
||||||
void create_global_var_binding(FlyString const& name, bool can_be_deleted);
|
void create_global_var_binding(FlyString const& name, bool can_be_deleted);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue