/* * Copyright (c) 2021, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include #include #include namespace JS { GC_DEFINE_ALLOCATOR(Script); // 16.1.5 ParseScript ( sourceText, realm, hostDefined ), https://tc39.es/ecma262/#sec-parse-script Result, Vector> Script::parse(StringView source_text, Realm& realm, StringView filename, HostDefined* host_defined, size_t line_number_offset) { // 1. Let script be ParseText(sourceText, Script). auto parser = Parser(Lexer(source_text, filename, line_number_offset)); auto script = parser.parse_program(); // 2. If script is a List of errors, return body. if (parser.has_errors()) return parser.errors(); // 3. Return Script Record { [[Realm]]: realm, [[ECMAScriptCode]]: script, [[HostDefined]]: hostDefined }. return realm.heap().allocate