1### Begin File: JSCBuiltins.h
2/*
3 * Copyright (c) 2015 Yusuke Suzuki <utatane.tea@gmail.com>.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24 * THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 */
27
28// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
29// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
30
31#ifndef JSCBuiltins_h
32#define JSCBuiltins_h
33
34namespace JSC {
35class FunctionExecutable;
36class VM;
37
38enum class ConstructAbility : unsigned;
39}
40
41namespace JSC {
42
43/* Operations.Promise */
44extern const char* s_operationsPromiseIsPromiseCode;
45extern const int s_operationsPromiseIsPromiseCodeLength;
46extern const JSC::ConstructAbility s_operationsPromiseIsPromiseCodeConstructAbility;
47extern const char* s_operationsPromiseNewPromiseReactionCode;
48extern const int s_operationsPromiseNewPromiseReactionCodeLength;
49extern const JSC::ConstructAbility s_operationsPromiseNewPromiseReactionCodeConstructAbility;
50extern const char* s_operationsPromiseNewPromiseCapabilityCode;
51extern const int s_operationsPromiseNewPromiseCapabilityCodeLength;
52extern const JSC::ConstructAbility s_operationsPromiseNewPromiseCapabilityCodeConstructAbility;
53extern const char* s_operationsPromiseTriggerPromiseReactionsCode;
54extern const int s_operationsPromiseTriggerPromiseReactionsCodeLength;
55extern const JSC::ConstructAbility s_operationsPromiseTriggerPromiseReactionsCodeConstructAbility;
56extern const char* s_operationsPromiseRejectPromiseCode;
57extern const int s_operationsPromiseRejectPromiseCodeLength;
58extern const JSC::ConstructAbility s_operationsPromiseRejectPromiseCodeConstructAbility;
59extern const char* s_operationsPromiseFulfillPromiseCode;
60extern const int s_operationsPromiseFulfillPromiseCodeLength;
61extern const JSC::ConstructAbility s_operationsPromiseFulfillPromiseCodeConstructAbility;
62extern const char* s_operationsPromiseCreateResolvingFunctionsCode;
63extern const int s_operationsPromiseCreateResolvingFunctionsCodeLength;
64extern const JSC::ConstructAbility s_operationsPromiseCreateResolvingFunctionsCodeConstructAbility;
65extern const char* s_operationsPromisePromiseReactionJobCode;
66extern const int s_operationsPromisePromiseReactionJobCodeLength;
67extern const JSC::ConstructAbility s_operationsPromisePromiseReactionJobCodeConstructAbility;
68extern const char* s_operationsPromisePromiseResolveThenableJobCode;
69extern const int s_operationsPromisePromiseResolveThenableJobCodeLength;
70extern const JSC::ConstructAbility s_operationsPromisePromiseResolveThenableJobCodeConstructAbility;
71extern const char* s_operationsPromiseInitializePromiseCode;
72extern const int s_operationsPromiseInitializePromiseCodeLength;
73extern const JSC::ConstructAbility s_operationsPromiseInitializePromiseCodeConstructAbility;
74
75#define JSC_FOREACH_OPERATIONSPROMISE_BUILTIN_DATA(macro) \
76 macro(isPromise, operationsPromiseIsPromise, 1) \
77 macro(newPromiseReaction, operationsPromiseNewPromiseReaction, 2) \
78 macro(newPromiseCapability, operationsPromiseNewPromiseCapability, 1) \
79 macro(triggerPromiseReactions, operationsPromiseTriggerPromiseReactions, 2) \
80 macro(rejectPromise, operationsPromiseRejectPromise, 2) \
81 macro(fulfillPromise, operationsPromiseFulfillPromise, 2) \
82 macro(createResolvingFunctions, operationsPromiseCreateResolvingFunctions, 1) \
83 macro(promiseReactionJob, operationsPromisePromiseReactionJob, 2) \
84 macro(promiseResolveThenableJob, operationsPromisePromiseResolveThenableJob, 3) \
85 macro(initializePromise, operationsPromiseInitializePromise, 1) \
86
87#define JSC_BUILTIN_OPERATIONSPROMISE_ISPROMISE 1
88#define JSC_BUILTIN_OPERATIONSPROMISE_NEWPROMISEREACTION 1
89#define JSC_BUILTIN_OPERATIONSPROMISE_NEWPROMISECAPABILITY 1
90#define JSC_BUILTIN_OPERATIONSPROMISE_TRIGGERPROMISEREACTIONS 1
91#define JSC_BUILTIN_OPERATIONSPROMISE_REJECTPROMISE 1
92#define JSC_BUILTIN_OPERATIONSPROMISE_FULFILLPROMISE 1
93#define JSC_BUILTIN_OPERATIONSPROMISE_CREATERESOLVINGFUNCTIONS 1
94#define JSC_BUILTIN_OPERATIONSPROMISE_PROMISEREACTIONJOB 1
95#define JSC_BUILTIN_OPERATIONSPROMISE_PROMISERESOLVETHENABLEJOB 1
96#define JSC_BUILTIN_OPERATIONSPROMISE_INITIALIZEPROMISE 1
97
98#define JSC_FOREACH_BUILTIN_CODE(macro) \
99 macro(operationsPromiseIsPromiseCode, isPromise, s_operationsPromiseIsPromiseCodeLength) \
100 macro(operationsPromiseNewPromiseReactionCode, newPromiseReaction, s_operationsPromiseNewPromiseReactionCodeLength) \
101 macro(operationsPromiseNewPromiseCapabilityCode, newPromiseCapability, s_operationsPromiseNewPromiseCapabilityCodeLength) \
102 macro(operationsPromiseTriggerPromiseReactionsCode, triggerPromiseReactions, s_operationsPromiseTriggerPromiseReactionsCodeLength) \
103 macro(operationsPromiseRejectPromiseCode, rejectPromise, s_operationsPromiseRejectPromiseCodeLength) \
104 macro(operationsPromiseFulfillPromiseCode, fulfillPromise, s_operationsPromiseFulfillPromiseCodeLength) \
105 macro(operationsPromiseCreateResolvingFunctionsCode, createResolvingFunctions, s_operationsPromiseCreateResolvingFunctionsCodeLength) \
106 macro(operationsPromisePromiseReactionJobCode, promiseReactionJob, s_operationsPromisePromiseReactionJobCodeLength) \
107 macro(operationsPromisePromiseResolveThenableJobCode, promiseResolveThenableJob, s_operationsPromisePromiseResolveThenableJobCodeLength) \
108 macro(operationsPromiseInitializePromiseCode, initializePromise, s_operationsPromiseInitializePromiseCodeLength) \
109
110#define JSC_FOREACH_BUILTIN_FUNCTION_NAME(macro) \
111 macro(createResolvingFunctions) \
112 macro(fulfillPromise) \
113 macro(initializePromise) \
114 macro(isPromise) \
115 macro(newPromiseCapability) \
116 macro(newPromiseReaction) \
117 macro(promiseReactionJob) \
118 macro(promiseResolveThenableJob) \
119 macro(rejectPromise) \
120 macro(triggerPromiseReactions) \
121
122#define DECLARE_BUILTIN_GENERATOR(codeName, functionName, argumentCount) \
123 JSC::FunctionExecutable* codeName##Generator(JSC::VM&);
124
125JSC_FOREACH_BUILTIN_CODE(DECLARE_BUILTIN_GENERATOR)
126#undef DECLARE_BUILTIN_GENERATOR
127
128#define JSC_BUILTIN_EXISTS(object, func) defined JSC_BUILTIN_ ## object ## _ ## func
129
130} // namespace JSC
131
132#endif // JSCBuiltins_h
133
134### End File: JSCBuiltins.h
135
136### Begin File: JSCBuiltins.cpp
137/*
138 * Copyright (c) 2015 Yusuke Suzuki <utatane.tea@gmail.com>.
139 *
140 * Redistribution and use in source and binary forms, with or without
141 * modification, are permitted provided that the following conditions
142 * are met:
143 * 1. Redistributions of source code must retain the above copyright
144 * notice, this list of conditions and the following disclaimer.
145 * 2. Redistributions in binary form must reproduce the above copyright
146 * notice, this list of conditions and the following disclaimer in the
147 * documentation and/or other materials provided with the distribution.
148 *
149 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
150 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
151 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
152 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
153 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
154 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
155 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
156 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
157 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
158 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
159 * THE POSSIBILITY OF SUCH DAMAGE.
160 *
161 */
162
163// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
164// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
165
166#include "config.h"
167#include "JSCBuiltins.h"
168
169#include "BuiltinExecutables.h"
170#include "Executable.h"
171#include "JSCellInlines.h"
172#include "VM.h"
173
174namespace JSC {
175
176const JSC::ConstructAbility s_operationsPromiseIsPromiseCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
177const int s_operationsPromiseIsPromiseCodeLength = 158;
178const char* s_operationsPromiseIsPromiseCode =
179 "(function (promise)\n" \
180 "{\n" \
181 " \"use strict\";\n" \
182 "\n" \
183 " return @isObject(promise) && !!promise.@promiseState;\n" \
184 "})\n" \
185;
186
187const JSC::ConstructAbility s_operationsPromiseNewPromiseReactionCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
188const int s_operationsPromiseNewPromiseReactionCodeLength = 220;
189const char* s_operationsPromiseNewPromiseReactionCode =
190 "(function (capability, handler)\n" \
191 "{\n" \
192 " \"use strict\";\n" \
193 "\n" \
194 " return {\n" \
195 " @capabilities: capability,\n" \
196 " @handler: handler\n" \
197 " };\n" \
198 "})\n" \
199;
200
201const JSC::ConstructAbility s_operationsPromiseNewPromiseCapabilityCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
202const int s_operationsPromiseNewPromiseCapabilityCodeLength = 1427;
203const char* s_operationsPromiseNewPromiseCapabilityCode =
204 "(function (constructor)\n" \
205 "{\n" \
206 " \"use strict\";\n" \
207 "\n" \
208 " //\n" \
209 " if (typeof constructor !== \"function\")\n" \
210 " throw new @TypeError(\"promise capability requires a constructor function\");\n" \
211 "\n" \
212 " var promiseCapability = {\n" \
213 " @promise: undefined,\n" \
214 " @resolve: undefined,\n" \
215 " @reject: undefined\n" \
216 " };\n" \
217 "\n" \
218 " function executor(resolve, reject)\n" \
219 " {\n" \
220 " if (promiseCapability.@resolve !== undefined)\n" \
221 " throw new @TypeError(\"resolve function is already set\");\n" \
222 " if (promiseCapability.@reject !== undefined)\n" \
223 " throw new @TypeError(\"reject function is already set\");\n" \
224 "\n" \
225 " promiseCapability.@resolve = resolve;\n" \
226 " promiseCapability.@reject = reject;\n" \
227 " }\n" \
228 "\n" \
229 " var promise = new constructor(executor);\n" \
230 "\n" \
231 " if (typeof promiseCapability.@resolve !== \"function\")\n" \
232 " throw new @TypeError(\"executor did not take a resolve function\");\n" \
233 "\n" \
234 " if (typeof promiseCapability.@reject !== \"function\")\n" \
235 " throw new @TypeError(\"executor did not take a reject function\");\n" \
236 "\n" \
237 " promiseCapability.@promise = promise;\n" \
238 "\n" \
239 " return promiseCapability;\n" \
240 "})\n" \
241;
242
243const JSC::ConstructAbility s_operationsPromiseTriggerPromiseReactionsCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
244const int s_operationsPromiseTriggerPromiseReactionsCodeLength = 269;
245const char* s_operationsPromiseTriggerPromiseReactionsCode =
246 "(function (reactions, argument)\n" \
247 "{\n" \
248 " \"use strict\";\n" \
249 "\n" \
250 " for (var index = 0, length = reactions.length; index < length; ++index)\n" \
251 " @enqueueJob(@promiseReactionJob, [reactions[index], argument]);\n" \
252 "})\n" \
253;
254
255const JSC::ConstructAbility s_operationsPromiseRejectPromiseCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
256const int s_operationsPromiseRejectPromiseCodeLength = 541;
257const char* s_operationsPromiseRejectPromiseCode =
258 "(function (promise, reason)\n" \
259 "{\n" \
260 " \"use strict\";\n" \
261 "\n" \
262 " var reactions = promise.@promiseRejectReactions;\n" \
263 " promise.@promiseResult = reason;\n" \
264 " promise.@promiseFulfillReactions = undefined;\n" \
265 " promise.@promiseRejectReactions = undefined;\n" \
266 " promise.@promiseState = @promiseRejected;\n" \
267 "\n" \
268 " @InspectorInstrumentation.promiseRejected(promise, reason, reactions);\n" \
269 "\n" \
270 " @triggerPromiseReactions(reactions, reason);\n" \
271 "})\n" \
272;
273
274const JSC::ConstructAbility s_operationsPromiseFulfillPromiseCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
275const int s_operationsPromiseFulfillPromiseCodeLength = 540;
276const char* s_operationsPromiseFulfillPromiseCode =
277 "(function (promise, value)\n" \
278 "{\n" \
279 " \"use strict\";\n" \
280 "\n" \
281 " var reactions = promise.@promiseFulfillReactions;\n" \
282 " promise.@promiseResult = value;\n" \
283 " promise.@promiseFulfillReactions = undefined;\n" \
284 " promise.@promiseRejectReactions = undefined;\n" \
285 " promise.@promiseState = @promiseFulfilled;\n" \
286 "\n" \
287 " @InspectorInstrumentation.promiseFulfilled(promise, value, reactions);\n" \
288 "\n" \
289 " @triggerPromiseReactions(reactions, value);\n" \
290 "})\n" \
291;
292
293const JSC::ConstructAbility s_operationsPromiseCreateResolvingFunctionsCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
294const int s_operationsPromiseCreateResolvingFunctionsCodeLength = 1468;
295const char* s_operationsPromiseCreateResolvingFunctionsCode =
296 "(function (promise)\n" \
297 "{\n" \
298 " \"use strict\";\n" \
299 "\n" \
300 " var alreadyResolved = false;\n" \
301 "\n" \
302 " var resolve = function (resolution) {\n" \
303 " if (alreadyResolved)\n" \
304 " return undefined;\n" \
305 " alreadyResolved = true;\n" \
306 "\n" \
307 " if (resolution === promise)\n" \
308 " return @rejectPromise(promise, new @TypeError(\"Resolve a promise with itself\"));\n" \
309 "\n" \
310 " if (!@isObject(resolution))\n" \
311 " return @fulfillPromise(promise, resolution);\n" \
312 "\n" \
313 " var then;\n" \
314 " try {\n" \
315 " then = resolution.then;\n" \
316 " } catch (error) {\n" \
317 " return @rejectPromise(promise, error);\n" \
318 " }\n" \
319 "\n" \
320 " if (typeof then !== 'function')\n" \
321 " return @fulfillPromise(promise, resolution);\n" \
322 "\n" \
323 " @enqueueJob(@promiseResolveThenableJob, [promise, resolution, then]);\n" \
324 "\n" \
325 " return undefined;\n" \
326 " };\n" \
327 "\n" \
328 " var reject = function (reason) {\n" \
329 " if (alreadyResolved)\n" \
330 " return undefined;\n" \
331 " alreadyResolved = true;\n" \
332 "\n" \
333 " return @rejectPromise(promise, reason);\n" \
334 " };\n" \
335 "\n" \
336 " return {\n" \
337 " @resolve: resolve,\n" \
338 " @reject: reject\n" \
339 " };\n" \
340 "})\n" \
341;
342
343const JSC::ConstructAbility s_operationsPromisePromiseReactionJobCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
344const int s_operationsPromisePromiseReactionJobCodeLength = 493;
345const char* s_operationsPromisePromiseReactionJobCode =
346 "(function (reaction, argument)\n" \
347 "{\n" \
348 " \"use strict\";\n" \
349 "\n" \
350 " var promiseCapability = reaction.@capabilities;\n" \
351 "\n" \
352 " var result;\n" \
353 " try {\n" \
354 " result = reaction.@handler.@call(undefined, argument);\n" \
355 " } catch (error) {\n" \
356 " return promiseCapability.@reject.@call(undefined, error);\n" \
357 " }\n" \
358 "\n" \
359 " return promiseCapability.@resolve.@call(undefined, result);\n" \
360 "})\n" \
361;
362
363const JSC::ConstructAbility s_operationsPromisePromiseResolveThenableJobCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
364const int s_operationsPromisePromiseResolveThenableJobCodeLength = 453;
365const char* s_operationsPromisePromiseResolveThenableJobCode =
366 "(function (promiseToResolve, thenable, then)\n" \
367 "{\n" \
368 " \"use strict\";\n" \
369 "\n" \
370 " var resolvingFunctions = @createResolvingFunctions(promiseToResolve);\n" \
371 "\n" \
372 " try {\n" \
373 " return then.@call(thenable, resolvingFunctions.@resolve, resolvingFunctions.@reject);\n" \
374 " } catch (error) {\n" \
375 " return resolvingFunctions.@reject.@call(undefined, error);\n" \
376 " }\n" \
377 "})\n" \
378;
379
380const JSC::ConstructAbility s_operationsPromiseInitializePromiseCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
381const int s_operationsPromiseInitializePromiseCodeLength = 731;
382const char* s_operationsPromiseInitializePromiseCode =
383 "(function (executor)\n" \
384 "{\n" \
385 " \"use strict\";\n" \
386 "\n" \
387 " if (typeof executor !== 'function')\n" \
388 " throw new @TypeError(\"Promise constructor takes a function argument\");\n" \
389 "\n" \
390 " this.@promiseState = @promisePending;\n" \
391 " this.@promiseFulfillReactions = [];\n" \
392 " this.@promiseRejectReactions = [];\n" \
393 "\n" \
394 " var resolvingFunctions = @createResolvingFunctions(this);\n" \
395 " try {\n" \
396 " executor(resolvingFunctions.@resolve, resolvingFunctions.@reject);\n" \
397 " } catch (error) {\n" \
398 " return resolvingFunctions.@reject.@call(undefined, error);\n" \
399 " }\n" \
400 "\n" \
401 " return this;\n" \
402 "})\n" \
403;
404
405
406#define DEFINE_BUILTIN_GENERATOR(codeName, functionName, argumentCount) \
407JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \
408{\
409 return vm.builtinExecutables()->codeName##Executable()->link(vm, vm.builtinExecutables()->codeName##Source()); }
410JSC_FOREACH_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR)
411#undef DEFINE_BUILTIN_GENERATOR
412
413
414} // namespace JSC
415### End File: JSCBuiltins.cpp