Skip to content
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

LibJS: RAII in js???? #16630

Merged
merged 8 commits into from Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .prettierignore
Expand Up @@ -2,3 +2,9 @@ Base/home/anon/Source/js
Userland/Libraries/LibJS/Tests/invalid-lhs-in-assignment.js
Userland/Libraries/LibJS/Tests/unicode-identifier-escape.js
Userland/Libraries/LibJS/Tests/modules/failing.mjs

# FIXME: Remove once prettier is updated to support using declarations.
linusg marked this conversation as resolved.
Show resolved Hide resolved
Userland/Libraries/LibJS/Tests/builtins/DisposableStack/DisposableStack.prototype.@@dispose.js
Userland/Libraries/LibJS/Tests/modules/top-level-dispose.mjs
Userland/Libraries/LibJS/Tests/using-declaration.js
Userland/Libraries/LibJS/Tests/using-for-loops.js
299 changes: 220 additions & 79 deletions Userland/Libraries/LibJS/AST.cpp

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions Userland/Libraries/LibJS/AST.h
Expand Up @@ -922,6 +922,8 @@ class ForStatement final : public IterationStatement {
virtual Bytecode::CodeGenerationErrorOr<void> generate_labelled_evaluation(Bytecode::Generator&, Vector<DeprecatedFlyString> const&) const override;

private:
Completion for_body_evaluation(Interpreter&, Vector<DeprecatedFlyString> const&, size_t per_iteration_bindings_size) const;

RefPtr<ASTNode> m_init;
RefPtr<Expression> m_test;
RefPtr<Expression> m_update;
Expand Down Expand Up @@ -1719,6 +1721,29 @@ class VariableDeclaration final : public Declaration {
NonnullRefPtrVector<VariableDeclarator> m_declarations;
};

class UsingDeclaration final : public Declaration {
public:
UsingDeclaration(SourceRange source_range, NonnullRefPtrVector<VariableDeclarator> declarations)
: Declaration(move(source_range))
, m_declarations(move(declarations))
{
}

virtual Completion execute(Interpreter&) const override;
virtual void dump(int indent) const override;

virtual ThrowCompletionOr<void> for_each_bound_name(ThrowCompletionOrVoidCallback<DeprecatedFlyString const&>&& callback) const override;

virtual bool is_constant_declaration() const override { return true; };

virtual bool is_lexical_declaration() const override { return true; }

NonnullRefPtrVector<VariableDeclarator> const& declarations() const { return m_declarations; }

private:
NonnullRefPtrVector<VariableDeclarator> m_declarations;
};

class ObjectProperty final : public ASTNode {
public:
enum class Type : u8 {
Expand Down
6 changes: 6 additions & 0 deletions Userland/Libraries/LibJS/CMakeLists.txt
Expand Up @@ -75,6 +75,9 @@ set(SOURCES
Runtime/DateConstructor.cpp
Runtime/DatePrototype.cpp
Runtime/DeclarativeEnvironment.cpp
Runtime/DisposableStack.cpp
Runtime/DisposableStackConstructor.cpp
Runtime/DisposableStackPrototype.cpp
Runtime/ECMAScriptFunctionObject.cpp
Runtime/Environment.cpp
Runtime/Error.cpp
Expand Down Expand Up @@ -193,6 +196,9 @@ set(SOURCES
Runtime/StringIteratorPrototype.cpp
Runtime/StringObject.cpp
Runtime/StringPrototype.cpp
Runtime/SuppressedError.cpp
Runtime/SuppressedErrorConstructor.cpp
Runtime/SuppressedErrorPrototype.cpp
Runtime/Symbol.cpp
Runtime/SymbolConstructor.cpp
Runtime/SymbolObject.cpp
Expand Down
5 changes: 4 additions & 1 deletion Userland/Libraries/LibJS/Forward.h
Expand Up @@ -27,6 +27,7 @@
__JS_ENUMERATE(BooleanObject, boolean, BooleanPrototype, BooleanConstructor, void) \
__JS_ENUMERATE(DataView, data_view, DataViewPrototype, DataViewConstructor, void) \
__JS_ENUMERATE(Date, date, DatePrototype, DateConstructor, void) \
__JS_ENUMERATE(DisposableStack, disposable_stack, DisposableStackPrototype, DisposableStackConstructor, void) \
__JS_ENUMERATE(Error, error, ErrorPrototype, ErrorConstructor, void) \
__JS_ENUMERATE(FinalizationRegistry, finalization_registry, FinalizationRegistryPrototype, FinalizationRegistryConstructor, void) \
__JS_ENUMERATE(FunctionObject, function, FunctionPrototype, FunctionConstructor, void) \
Expand All @@ -39,6 +40,7 @@
__JS_ENUMERATE(Set, set, SetPrototype, SetConstructor, void) \
__JS_ENUMERATE(ShadowRealm, shadow_realm, ShadowRealmPrototype, ShadowRealmConstructor, void) \
__JS_ENUMERATE(StringObject, string, StringPrototype, StringConstructor, void) \
__JS_ENUMERATE(SuppressedError, suppressed_error, SuppressedErrorPrototype, SuppressedErrorConstructor, void) \
__JS_ENUMERATE(SymbolObject, symbol, SymbolPrototype, SymbolConstructor, void) \
__JS_ENUMERATE(WeakMap, weak_map, WeakMapPrototype, WeakMapConstructor, void) \
__JS_ENUMERATE(WeakRef, weak_ref, WeakRefPrototype, WeakRefConstructor, void) \
Expand Down Expand Up @@ -132,7 +134,8 @@
__JS_ENUMERATE(unscopables, unscopables) \
__JS_ENUMERATE(species, species) \
__JS_ENUMERATE(toPrimitive, to_primitive) \
__JS_ENUMERATE(toStringTag, to_string_tag)
__JS_ENUMERATE(toStringTag, to_string_tag) \
__JS_ENUMERATE(dispose, dispose)

#define JS_ENUMERATE_REGEXP_FLAGS \
__JS_ENUMERATE(hasIndices, has_indices, d) \
Expand Down