aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/builtins/cpp/ImportMetaObjectBuiltins.cpp
blob: 83a2ba8c247a63bed81e11c8a9ac9b52ff3af1a2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/*
 * Copyright (c) 2015 Igalia
 * Copyright (c) 2015 Igalia S.L.
 * Copyright (c) 2015 Igalia.
 * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
 * Copyright (c) 2015, 2016, 2017 Canon Inc.
 * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
 * Copyright (c) 2023 Codeblog Corp. All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGE.
 * 
 */

// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py

#include "config.h"
#include "ImportMetaObjectBuiltins.h"

#include "WebCoreJSClientData.h"
#include <JavaScriptCore/IdentifierInlines.h>
#include <JavaScriptCore/ImplementationVisibility.h>
#include <JavaScriptCore/Intrinsic.h>
#include <JavaScriptCore/JSObjectInlines.h>
#include <JavaScriptCore/VM.h>

namespace WebCore {

const JSC::ConstructAbility s_importMetaObjectLoadCJS2ESMCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
const JSC::ConstructorKind s_importMetaObjectLoadCJS2ESMCodeConstructorKind = JSC::ConstructorKind::None;
const JSC::ImplementationVisibility s_importMetaObjectLoadCJS2ESMCodeImplementationVisibility = JSC::ImplementationVisibility::Public;
const int s_importMetaObjectLoadCJS2ESMCodeLength = 2943;
static const JSC::Intrinsic s_importMetaObjectLoadCJS2ESMCodeIntrinsic = JSC::NoIntrinsic;
const char* const s_importMetaObjectLoadCJS2ESMCode =
    "(function (resolvedSpecifier) {\n" \
    "  \"use strict\";\n" \
    "\n" \
    "  var loader = @Loader;\n" \
    "  var queue = @createFIFO();\n" \
    "  var key = resolvedSpecifier;\n" \
    "  while (key) {\n" \
    "    //\n" \
    "    //\n" \
    "    //\n" \
    "    var entry = loader.registry.@get(key);\n" \
    "\n" \
    "    if (!entry || !entry.state || entry.state <= @ModuleFetch) {\n" \
    "      @fulfillModuleSync(key);\n" \
    "      entry = loader.registry.@get(key);\n" \
    "    }\n" \
    "\n" \
    "\n" \
    "    //\n" \
    "    //\n" \
    "    //\n" \
    "    //\n" \
    "    var sourceCodeObject = @getPromiseInternalField(\n" \
    "      entry.fetch,\n" \
    "      @promiseFieldReactionsOrResult\n" \
    "    );\n" \
    "    //\n" \
    "    //\n" \
    "    //\n" \
    "    var moduleRecordPromise = loader.parseModule(key, sourceCodeObject);\n" \
    "    var module = entry.module;\n" \
    "    if (!module && moduleRecordPromise && @isPromise(moduleRecordPromise)) {\n" \
    "      var reactionsOrResult = @getPromiseInternalField(\n" \
    "        moduleRecordPromise,\n" \
    "        @promiseFieldReactionsOrResult\n" \
    "      );\n" \
    "      var flags = @getPromiseInternalField(\n" \
    "        moduleRecordPromise,\n" \
    "        @promiseFieldFlags\n" \
    "      );\n" \
    "      var state = flags & @promiseStateMask;\n" \
    "      //\n" \
    "      if (\n" \
    "        state === @promiseStatePending ||\n" \
    "        (reactionsOrResult && @isPromise(reactionsOrResult))\n" \
    "      ) {\n" \
    "        @throwTypeError(`require() async module \\\"${key}\\\" is unsupported`);\n" \
    "      } else if (state === @promiseStateRejected) {\n" \
    "        //\n" \
    "        //\n" \
    "        @throwTypeError(\n" \
    "          `${\n" \
    "            reactionsOrResult?.message ?? \"An error occurred\"\n" \
    "          } while parsing module \\\"${key}\\\"`\n" \
    "        );\n" \
    "      }\n" \
    "      entry.module = module = reactionsOrResult;\n" \
    "    } else if (moduleRecordPromise && !module) {\n" \
    "      entry.module = module = moduleRecordPromise;\n" \
    "    }\n" \
    "\n" \
    "    //\n" \
    "    @setStateToMax(entry, @ModuleLink);\n" \
    "    var dependenciesMap = module.dependenciesMap;\n" \
    "    var requestedModules = loader.requestedModules(module);\n" \
    "    var dependencies = @newArrayWithSize(requestedModules.length);\n" \
    "    for (var i = 0, length = requestedModules.length; i < length; ++i) {\n" \
    "      var depName = requestedModules[i];\n" \
    "      //\n" \
    "      //\n" \
    "      var depKey =\n" \
    "        depName[0] === \"/\"\n" \
    "          ? depName\n" \
    "          : loader.resolve(depName, key, @undefined);\n" \
    "      var depEntry = loader.ensureRegistered(depKey);\n" \
    "      if (depEntry.state < @ModuleLink) {\n" \
    "        queue.push(depKey);\n" \
    "      }\n" \
    "\n" \
    "      @putByValDirect(dependencies, i, depEntry);\n" \
    "      dependenciesMap.@set(depName, depEntry);\n" \
    "    }\n" \
    "\n" \
    "    entry.dependencies = dependencies;\n" \
    "    //\n" \
    "    entry.instantiate = @Promise.resolve(entry)\n" \
    "    entry.satisfy = @Promise.resolve(entry);\n" \
    "    key = queue.shift();\n" \
    "    while (key && (loader.registry.@get(key)?.state ?? @ModuleFetch) >= @ModuleLink) {\n" \
    "      key = queue.shift();\n" \
    "    }\n" \
    "\n" \
    "  }\n" \
    "\n" \
    "  var linkAndEvaluateResult = loader.linkAndEvaluateModule(\n" \
    "    resolvedSpecifier,\n" \
    "    @undefined\n" \
    "  );\n" \
    "  if (linkAndEvaluateResult && @isPromise(linkAndEvaluateResult)) {\n" \
    "    //\n" \
    "    //\n" \
    "    @throwTypeError(\n" \
    "      `require() async module \\\"${resolvedSpecifier}\\\" is unsupported`\n" \
    "    );\n" \
    "  }\n" \
    "\n" \
    "  return loader.registry.@get(resolvedSpecifier);\n" \
    "\n" \
    "})\n" \
;

const JSC::ConstructAbility s_importMetaObjectRequireESMCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
const JSC::ConstructorKind s_importMetaObjectRequireESMCodeConstructorKind = JSC::ConstructorKind::None;
const JSC::ImplementationVisibility s_importMetaObjectRequireESMCodeImplementationVisibility = JSC::ImplementationVisibility::Public;
const int s_importMetaObjectRequireESMCodeLength = 616;
static const JSC::Intrinsic s_importMetaObjectRequireESMCodeIntrinsic = JSC::NoIntrinsic;
const char* const s_importMetaObjectRequireESMCode =
    "(function (resolved) {\n" \
    "  \"use strict\";\n" \
    "  var entry = @Loader.registry.@get(resolved);\n" \
    "\n" \
    "  if (!entry || !entry.evaluated) {\n" \
    "    entry = @loadCJS2ESM(resolved); \n" \
    "  }\n" \
    "\n" \
    "  if (!entry || !entry.evaluated || !entry.module) {\n" \
    "    @throwTypeError(`require() failed to evaluate module \\\"${resolved}\\\". This is an internal consistentency error.`);\n" \
    "  }\n" \
    "  var exports = @Loader.getModuleNamespaceObject(entry.module);\n" \
    "  var commonJS = exports.default;\n" \
    "  var cjs = commonJS?.[@commonJSSymbol];\n" \
    "  if (cjs === 0) {\n" \
    "    return commonJS;\n" \
    "  } else if (cjs && @isCallable(commonJS)) {\n" \
    "    return commonJS();\n" \
    "  }\n" \
    "  \n" \
    "  return exports;\n" \
    "})\n" \
;

const JSC::ConstructAbility s_importMetaObjectInternalRequireCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
const JSC::ConstructorKind s_importMetaObjectInternalRequireCodeConstructorKind = JSC::ConstructorKind::None;
const JSC::ImplementationVisibility s_importMetaObjectInternalRequireCodeImplementationVisibility = JSC::ImplementationVisibility::Public;
const int s_importMetaObjectInternalRequireCodeLength = 983;
static const JSC::Intrinsic s_importMetaObjectInternalRequireCodeIntrinsic = JSC::NoIntrinsic;
const char* const s_importMetaObjectInternalRequireCode =
    "(function (resolved) {\n" \
    "  \"use strict\";\n" \
    "\n" \
    "  var cached = @requireMap.@get(resolved);\n" \
    "  const last5 = resolved.substring(resolved.length - 5);\n" \
    "  if (cached) {\n" \
    "    if (last5 === \".node\") {\n" \
    "      return cached.exports;\n" \
    "    }\n" \
    "\n" \
    "    return cached;\n" \
    "  }\n" \
    "  \n" \
    "  //\n" \
    "  if (last5 === \".json\") {\n" \
    "    var fs = (globalThis[Symbol.for(\"_fs\")] ||= @Bun.fs());\n" \
    "    var exports = JSON.parse(fs.readFileSync(resolved, \"utf8\"));\n" \
    "    @requireMap.@set(resolved, exports);\n" \
    "    return exports;\n" \
    "  } else if (last5 === \".node\") {\n" \
    "    var module = { exports: {} };\n" \
    "    process.dlopen(module, resolved);\n" \
    "    @requireMap.@set(resolved, module);\n" \
    "    return module.exports;\n" \
    "  } else if (last5 === \".toml\") {\n" \
    "    var fs = (globalThis[Symbol.for(\"_fs\")] ||= @Bun.fs());\n" \
    "    var exports = @Bun.TOML.parse(fs.readFileSync(resolved, \"utf8\"));\n" \
    "    @requireMap.@set(resolved, exports);\n" \
    "    return exports;\n" \
    "  } else {\n" \
    "    var exports = @requireESM(resolved);\n" \
    "    @requireMap.@set(resolved, exports);\n" \
    "    return exports;\n" \
    "  }\n" \
    "})\n" \
;

const JSC::ConstructAbility s_importMetaObjectRequireCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
const JSC::ConstructorKind s_importMetaObjectRequireCodeConstructorKind = JSC::ConstructorKind::None;
const JSC::ImplementationVisibility s_importMetaObjectRequireCodeImplementationVisibility = JSC::ImplementationVisibility::Public;
const int s_importMetaObjectRequireCodeLength = 222;
static const JSC::Intrinsic s_importMetaObjectRequireCodeIntrinsic = JSC::NoIntrinsic;
const char* const s_importMetaObjectRequireCode =
    "(function (name) {\n" \
    "  const from = this?.path ?? arguments.callee.path;\n" \
    "\n" \
    "  if (typeof name !== \"string\") {\n" \
    "    @throwTypeError(\"require(name) must be a string\");\n" \
    "  }\n" \
    "\n" \
    "  return @internalRequire(@resolveSync(name, from));\n" \
    "})\n" \
;

const JSC::ConstructAbility s_importMetaObjectMainCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
const JSC::ConstructorKind s_importMetaObjectMainCodeConstructorKind = JSC::ConstructorKind::None;
const JSC::ImplementationVisibility s_importMetaObjectMainCodeImplementationVisibility = JSC::ImplementationVisibility::Public;
const int s_importMetaObjectMainCodeLength = 52;
static const JSC::Intrinsic s_importMetaObjectMainCodeIntrinsic = JSC::NoIntrinsic;
const char* const s_importMetaObjectMainCode =
    "(function () {\n" \
    "  return this.path === @Bun.main;\n" \
    "})\n" \
;


#define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \
{\
    JSVMClientData* clientData = static_cast<JSVMClientData*>(vm.clientData); \
    return clientData->builtinFunctions().importMetaObjectBuiltins().codeName##Executable()->link(vm, nullptr, clientData->builtinFunctions().importMetaObjectBuiltins().codeName##Source(), std::nullopt, s_##codeName##Intrinsic); \
}
WEBCORE_FOREACH_IMPORTMETAOBJECT_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR)
#undef DEFINE_BUILTIN_GENERATOR


} // namespace WebCore