Debian Codegraph @

js/src/jit/VMFunctions.h

raw
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 #ifndef jit_VMFunctions_h
8 #define jit_VMFunctions_h
9
10 #include "mozilla/Assertions.h"
11 #include "mozilla/HashFunctions.h"
12
13 #include <stddef.h>
14 #include <stdint.h>
15
16 #include "jstypes.h"
17 #include "NamespaceImports.h"
18
19 #include "gc/AllocKind.h"
20 #include "js/ScalarType.h"
21 #include "js/TypeDecls.h"
22 #include "vm/TypeofEqOperand.h"
23 #include "vm/UsingHint.h"
24
25 class JSJitInfo;
26 class JSLinearString;
27
28 namespace js {
29
30 class AbstractGeneratorObject;
31 class ArrayObject;
32 class DateObject;
33 class GlobalObject;
34 class InterpreterFrame;
35 class LexicalScope;
36 class ClassBodyScope;
37 class MapObject;
38 class NativeObject;
39 class PlainObject;
40 class PropertyName;
41 class SetObject;
42 class Shape;
43 class TypedArrayObject;
44 class WithScope;
45 class MegamorphicCacheEntry;
46
47 namespace gc {
48
49 struct Cell;
50
51 } // namespace gc
52
53 namespace wasm {
54
55 class AnyRef;
56
57 } // namespace wasm
58
59 namespace jit {
60
61 class BaselineFrame;
62 class InterpreterStubExitFrameLayout;
63
64 enum DataType : uint8_t {
65 Type_Void,
66 Type_Bool,
67 Type_Int32,
68 Type_Double,
69 Type_Pointer,
70 Type_Cell,
71 Type_Value,
72 Type_Handle
73 };
74
75 // [SMDOC] JIT-to-C++ Function Calls. (callVM)
76 //
77 // Sometimes it is easier to reuse C++ code by calling VM's functions. Calling a
78 // function from the VM can be achieved with the use of callWithABI but this is
79 // discouraged when the called functions might trigger exceptions and/or
80 // garbage collections which are expecting to walk the stack. VMFunctions and
81 // callVM are interfaces provided to handle the exception handling and register
82 // the stack end (JITActivation) such that walking the stack is made possible.
83 //
84 // VMFunctionData is a structure which contains the necessary information needed
85 // for generating a trampoline function to make a call (with generateVMWrapper)
86 // and to root the arguments of the function (in TraceJitExitFrame).
87 // VMFunctionData is created with the VMFunctionDataHelper template, which
88 // infers the VMFunctionData fields from the function signature. The rooting and
89 // trampoline code is therefore determined by the arguments of a function and
90 // their locations in the signature of a function.
91 //
92 // VM functions all expect a JSContext* as first argument. This argument is
93 // implicitly provided by the trampoline code (in generateVMWrapper) and used
94 // for creating new objects or reporting errors. If your function does not make
95 // use of a JSContext* argument, then you might probably use a callWithABI
96 // call.
97 //
98 // Functions described using the VMFunction system must conform to a simple
99 // protocol: the return type must have a special "failure" value (for example,
100 // false for bool, or nullptr for Objects). If the function is designed to
101 // return a value that does not meet this requirement - such as
102 // object-or-nullptr, or an integer, an optional, final outParam can be
103 // specified. In this case, the return type must be boolean to indicate
104 // failure.
105 //
106 // JIT Code usage:
107 //
108 // Different JIT compilers in SpiderMonkey have their own implementations of
109 // callVM to call VM functions. However, the general shape of them is that
110 // arguments (excluding the JSContext or trailing out-param) are pushed on to
111 // the stack from right to left (rightmost argument is pushed first).
112 //
113 // Regardless of return value protocol being used (final outParam, or return
114 // value) the generated trampolines ensure the return value ends up in
115 // JSReturnOperand, ReturnReg or ReturnDoubleReg.
116 //
117 // Example:
118 //
119 // The details will differ slightly between the different compilers in
120 // SpiderMonkey, but the general shape of our usage looks like this:
121 //
122 // Suppose we have a function Foo:
123 //
124 // bool Foo(JSContext* cx, HandleObject x, HandleId y,
125 // MutableHandleValue z);
126 //
127 // This function returns true on success, and z is the outparam return value.
128 //
129 // A VM function wrapper for this can be created by adding an entry to
130 // VM_FUNCTION_LIST in VMFunctionList-inl.h:
131 //
132 // _(Foo, js::Foo)
133 //
134 // In the compiler code the call would then be issued like this:
135 //
136 // masm.Push(id);
137 // masm.Push(obj);
138 //
139 // using Fn = bool (*)(JSContext*, HandleObject, HandleId,
140 // MutableHandleValue);
141 // if (!callVM<Fn, js::Foo>()) {
142 // return false;
143 // }
144 //
145 // After this, the result value is in the return value register.
146
147 // Data for a VM function. All VMFunctionDatas are stored in a constexpr array.
148 struct VMFunctionData {
149 #if defined(DEBUG) || defined(JS_JITSPEW) || defined(JS_ION_PERF)
150 // Informative name of the wrapped function. The name should not be present
151 // in release builds in order to save memory.
152 const char* name_;
153 #endif
154
155 // Note: a maximum of seven root types is supported.
156 enum RootType : uint8_t {
157 RootNone = 0,
158 RootObject,
159 RootString,
160 RootId,
161 RootValue,
162 RootCell,
163 RootBigInt
164 };
165
166 // Contains an combination of enumerated types used by the gc for marking
167 // arguments of the VM wrapper.
168 uint64_t argumentRootTypes;
169
170 enum ArgProperties {
171 WordByValue = 0,
172 DoubleByValue = 1,
173 WordByRef = 2,
174 DoubleByRef = 3,
175 // BitMask version.
176 Word = 0,
177 Double = 1,
178 ByRef = 2
179 };
180
181 // Contains properties about the first 16 arguments.
182 uint32_t argumentProperties;
183
184 // Which arguments should be passed in float register on platforms that
185 // have them.
186 uint32_t argumentPassedInFloatRegs;
187
188 // Number of arguments expected, excluding JSContext * as an implicit
189 // first argument and an outparam as a possible implicit final argument.
190 uint8_t explicitArgs;
191
192 // The root type of the out param if outParam == Type_Handle.
193 RootType outParamRootType;
194
195 // The outparam may be any Type_*, and must be the final argument to the
196 // function, if not Void. outParam != Void implies that the return type
197 // has a boolean failure mode.
198 DataType outParam;
199
200 // Type returned by the C function and used by the VMFunction wrapper to
201 // check for failures of the C function. Valid failure/return types are
202 // boolean and object pointers which are asserted inside the VMFunction
203 // constructor. If the C function use an outparam (!= Type_Void), then
204 // the only valid failure/return type is boolean -- object pointers are
205 // pointless because the wrapper will only use it to compare it against
206 // nullptr before discarding its value.
207 DataType returnType;
208
209 // Number of Values the VM wrapper should pop from the stack when it returns.
210 // Used by baseline IC stubs so that they can use tail calls to call the VM
211 // wrapper.
212 uint8_t extraValuesToPop;
213
214 uint32_t argc() const {
215 // JSContext * + args + (OutParam? *)
216 return 1 + explicitArgc() + ((outParam == Type_Void) ? 0 : 1);
217 }
218
219 DataType failType() const { return returnType; }
220
221 // Whether this function returns anything more than a boolean flag for
222 // failures.
223 bool returnsData() const {
224 return returnType == Type_Cell || outParam != Type_Void;
225 }
226
227 ArgProperties argProperties(uint32_t explicitArg) const {
228 return ArgProperties((argumentProperties >> (2 * explicitArg)) & 3);
229 }
230
231 RootType argRootType(uint32_t explicitArg) const {
232 return RootType((argumentRootTypes >> (3 * explicitArg)) & 7);
233 }
234
235 bool argPassedInFloatReg(uint32_t explicitArg) const {
236 return ((argumentPassedInFloatRegs >> explicitArg) & 1) == 1;
237 }
238
239 #if defined(DEBUG) || defined(JS_JITSPEW) || defined(JS_ION_PERF)
240 const char* name() const { return name_; }
241 #endif
242
243 // Return the stack size consumed by explicit arguments.
244 size_t explicitStackSlots() const {
245 size_t stackSlots = explicitArgs;
246
247 // Fetch all double-word flags of explicit arguments.
248 uint32_t n = ((1 << (explicitArgs * 2)) - 1) // = Explicit argument mask.
249 & 0x55555555 // = Mask double-size args.
250 & argumentProperties;
251
252 // Add the number of double-word flags. (expect a few loop
253 // iteration)
254 while (n) {
255 stackSlots++;
256 n &= n - 1;
257 }
258 return stackSlots;
259 }
260
261 // Double-size argument which are passed by value are taking the space
262 // of 2 C arguments. This function is used to compute the number of
263 // argument expected by the C function. This is not the same as
264 // explicitStackSlots because reference to stack slots may take one less
265 // register in the total count.
266 size_t explicitArgc() const {
267 size_t stackSlots = explicitArgs;
268
269 // Fetch all explicit arguments.
270 uint32_t n = ((1 << (explicitArgs * 2)) - 1) // = Explicit argument mask.
271 & argumentProperties;
272
273 // Filter double-size arguments (0x5 = 0b0101) and remove (& ~)
274 // arguments passed by reference (0b1010 >> 1 == 0b0101).
275 n = (n & 0x55555555) & ~(n >> 1);
276
277 // Add the number of double-word transfered by value. (expect a few
278 // loop iteration)
279 while (n) {
280 stackSlots++;
281 n &= n - 1;
282 }
283 return stackSlots;
284 }
285
286 size_t doubleByRefArgs() const {
287 size_t count = 0;
288
289 // Fetch all explicit arguments.
290 uint32_t n = ((1 << (explicitArgs * 2)) - 1) // = Explicit argument mask.
291 & argumentProperties;
292
293 // Filter double-size arguments (0x5 = 0b0101) and take (&) only
294 // arguments passed by reference (0b1010 >> 1 == 0b0101).
295 n = (n & 0x55555555) & (n >> 1);
296
297 // Add the number of double-word transfered by refference. (expect a
298 // few loop iterations)
299 while (n) {
300 count++;
301 n &= n - 1;
302 }
303 return count;
304 }
305
306 size_t sizeOfOutParamStackSlot() const;
307
308 constexpr VMFunctionData(const char* name, uint32_t explicitArgs,
309 uint32_t argumentProperties,
310 uint32_t argumentPassedInFloatRegs,
311 uint64_t argRootTypes, DataType outParam,
312 RootType outParamRootType, DataType returnType,
313 uint8_t extraValuesToPop = 0)
314 :
315 #if defined(DEBUG) || defined(JS_JITSPEW) || defined(JS_ION_PERF)
316 name_(name),
317 #endif
318 argumentRootTypes(argRootTypes),
319 argumentProperties(argumentProperties),
320 argumentPassedInFloatRegs(argumentPassedInFloatRegs),
321 explicitArgs(explicitArgs),
322 outParamRootType(outParamRootType),
323 outParam(outParam),
324 returnType(returnType),
325 extraValuesToPop(extraValuesToPop) {
326 // Check for valid failure/return type.
327 MOZ_ASSERT_IF(outParam != Type_Void,
328 returnType == Type_Void || returnType == Type_Bool);
329 MOZ_ASSERT(returnType == Type_Void || returnType == Type_Bool ||
330 returnType == Type_Cell);
331 }
332
333 constexpr VMFunctionData(const VMFunctionData& o) = default;
334 };
335
336 // Extract the last element of a list of types.
337 template <typename... ArgTypes>
338 struct LastArg;
339
340 template <>
341 struct LastArg<> {
342 using Type = void;
343 };
344
345 template <typename HeadType>
346 struct LastArg<HeadType> {
347 using Type = HeadType;
348 };
349
350 template <typename HeadType, typename... TailTypes>
351 struct LastArg<HeadType, TailTypes...> {
352 using Type = typename LastArg<TailTypes...>::Type;
353 };
354
355 [[nodiscard]] bool InvokeFunction(JSContext* cx, HandleObject obj0,
356 bool constructing, bool ignoresReturnValue,
357 uint32_t argc, Value* argv,
358 MutableHandleValue rval);
359
360 bool InvokeFromInterpreterStub(JSContext* cx,
361 InterpreterStubExitFrameLayout* frame);
362 void* GetContextSensitiveInterpreterStub();
363
364 bool CheckOverRecursed(JSContext* cx);
365 bool CheckOverRecursedBaseline(JSContext* cx, BaselineFrame* frame);
366
367 [[nodiscard]] bool MutatePrototype(JSContext* cx, Handle<PlainObject*> obj,
368 HandleValue value);
369
370 enum class EqualityKind : bool { NotEqual, Equal };
371
372 template <EqualityKind Kind>
373 bool StringsEqual(JSContext* cx, HandleString lhs, HandleString rhs, bool* res);
374
375 enum class ComparisonKind : bool { GreaterThanOrEqual, LessThan };
376
377 template <ComparisonKind Kind>
378 bool StringsCompare(JSContext* cx, HandleString lhs, HandleString rhs,
379 bool* res);
380
381 JSString* ArrayJoin(JSContext* cx, HandleObject array, HandleString sep);
382 [[nodiscard]] bool SetArrayLength(JSContext* cx, HandleObject obj,
383 HandleValue value, bool strict);
384
385 [[nodiscard]] bool CharCodeAt(JSContext* cx, HandleString str, int32_t index,
386 uint32_t* code);
387 [[nodiscard]] bool CodePointAt(JSContext* cx, HandleString str, int32_t index,
388 uint32_t* code);
389 JSLinearString* StringFromCharCodeNoGC(JSContext* cx, int32_t code);
390 JSLinearString* LinearizeForCharAccessPure(JSString* str);
391 JSLinearString* LinearizeForCharAccess(JSContext* cx, JSString* str);
392 int32_t StringTrimStartIndex(const JSString* str);
393 int32_t StringTrimEndIndex(const JSString* str, int32_t start);
394 JSString* CharCodeToLowerCase(JSContext* cx, int32_t code);
395 JSString* CharCodeToUpperCase(JSContext* cx, int32_t code);
396
397 [[nodiscard]] bool SetProperty(JSContext* cx, HandleObject obj,
398 Handle<PropertyName*> name, HandleValue value,
399 bool strict, jsbytecode* pc);
400
401 [[nodiscard]] bool InterruptCheck(JSContext* cx);
402
403 JSObject* NewStringObject(JSContext* cx, HandleString str);
404
405 bool OperatorIn(JSContext* cx, HandleValue key, HandleObject obj, bool* out);
406
407 [[nodiscard]] bool GetIntrinsicValue(JSContext* cx, Handle<PropertyName*> name,
408 MutableHandleValue rval);
409
410 [[nodiscard]] bool CreateThisFromIC(JSContext* cx, HandleObject callee,
411 HandleObject newTarget, Value* argv,
412 uint32_t argc, MutableHandleValue rval);
413 [[nodiscard]] bool CreateThisFromIon(JSContext* cx, HandleObject callee,
414 HandleObject newTarget,
415 MutableHandleValue rval);
416
417 void PostWriteBarrier(JSRuntime* rt, js::gc::Cell* cell);
418 void PostGlobalWriteBarrier(JSRuntime* rt, GlobalObject* obj);
419
420 void PostWriteElementBarrier(JSRuntime* rt, JSObject* obj, int32_t index);
421
422 // If |str| represents an int32, assign it to |result| and return true.
423 // Otherwise return false.
424 bool GetInt32FromStringPure(JSContext* cx, JSString* str, int32_t* result);
425
426 // If |str| is an index in the range [0, INT32_MAX], return it. If the string
427 // is not an index in this range, return -1.
428 int32_t GetIndexFromString(JSString* str);
429
430 JSObject* WrapObjectPure(JSContext* cx, JSObject* obj);
431
432 [[nodiscard]] bool DebugPrologue(JSContext* cx, BaselineFrame* frame);
433 [[nodiscard]] bool DebugEpilogue(JSContext* cx, BaselineFrame* frame,
434 const jsbytecode* pc, bool ok);
435 [[nodiscard]] bool DebugEpilogueOnBaselineReturn(JSContext* cx,
436 BaselineFrame* frame,
437 const jsbytecode* pc);
438 void FrameIsDebuggeeCheck(BaselineFrame* frame);
439
440 JSObject* CreateGeneratorFromFrame(JSContext* cx, BaselineFrame* frame);
441 JSObject* CreateGenerator(JSContext* cx, HandleFunction, HandleScript,
442 HandleObject, HandleObject);
443
444 [[nodiscard]] bool NormalSuspend(JSContext* cx, HandleObject obj,
445 BaselineFrame* frame, uint32_t frameSize,
446 const jsbytecode* pc);
447 [[nodiscard]] bool FinalSuspend(JSContext* cx, HandleObject obj,
448 const jsbytecode* pc);
449 [[nodiscard]] bool InterpretResume(JSContext* cx, HandleObject obj,
450 Value* stackValues, MutableHandleValue rval);
451 [[nodiscard]] bool DebugAfterYield(JSContext* cx, BaselineFrame* frame);
452 [[nodiscard]] bool GeneratorThrowOrReturn(
453 JSContext* cx, BaselineFrame* frame,
454 Handle<AbstractGeneratorObject*> genObj, HandleValue arg,
455 int32_t resumeKindArg);
456
457 [[nodiscard]] bool GlobalDeclInstantiationFromIon(JSContext* cx,
458 HandleScript script,
459 const jsbytecode* pc);
460 [[nodiscard]] bool InitFunctionEnvironmentObjects(JSContext* cx,
461 BaselineFrame* frame);
462
463 [[nodiscard]] bool NewArgumentsObject(JSContext* cx, BaselineFrame* frame,
464 MutableHandleValue res);
465
466 ArrayObject* NewArrayObjectEnsureDenseInitLength(JSContext* cx, int32_t count);
467
468 ArrayObject* InitRestParameter(JSContext* cx, uint32_t length, Value* rest,
469 Handle<ArrayObject*> arrRes);
470
471 [[nodiscard]] bool HandleDebugTrap(JSContext* cx, BaselineFrame* frame,
472 const uint8_t* retAddr);
473 [[nodiscard]] bool OnDebuggerStatement(JSContext* cx, BaselineFrame* frame);
474 [[nodiscard]] bool GlobalHasLiveOnDebuggerStatement(JSContext* cx);
475
476 [[nodiscard]] bool EnterWith(JSContext* cx, BaselineFrame* frame,
477 HandleValue val, Handle<WithScope*> templ);
478 [[nodiscard]] bool LeaveWith(JSContext* cx, BaselineFrame* frame);
479
480 [[nodiscard]] bool PushLexicalEnv(JSContext* cx, BaselineFrame* frame,
481 Handle<LexicalScope*> scope);
482 [[nodiscard]] bool PushClassBodyEnv(JSContext* cx, BaselineFrame* frame,
483 Handle<ClassBodyScope*> scope);
484 [[nodiscard]] bool DebugLeaveThenPopLexicalEnv(JSContext* cx,
485 BaselineFrame* frame,
486 const jsbytecode* pc);
487 [[nodiscard]] bool FreshenLexicalEnv(JSContext* cx, BaselineFrame* frame);
488 [[nodiscard]] bool DebuggeeFreshenLexicalEnv(JSContext* cx,
489 BaselineFrame* frame,
490 const jsbytecode* pc);
491 [[nodiscard]] bool RecreateLexicalEnv(JSContext* cx, BaselineFrame* frame);
492 [[nodiscard]] bool DebuggeeRecreateLexicalEnv(JSContext* cx,
493 BaselineFrame* frame,
494 const jsbytecode* pc);
495 [[nodiscard]] bool DebugLeaveLexicalEnv(JSContext* cx, BaselineFrame* frame,
496 const jsbytecode* pc);
497
498 [[nodiscard]] bool PushVarEnv(JSContext* cx, BaselineFrame* frame,
499 Handle<Scope*> scope);
500
501 [[nodiscard]] bool InitBaselineFrameForOsr(BaselineFrame* frame,
502 InterpreterFrame* interpFrame,
503 uint32_t numStackValues);
504
505 JSString* StringReplace(JSContext* cx, HandleString string,
506 HandleString pattern, HandleString repl);
507
508 void AssertValidBigIntPtr(JSContext* cx, JS::BigInt* bi);
509 void AssertValidObjectPtr(JSContext* cx, JSObject* obj);
510 void AssertValidStringPtr(JSContext* cx, JSString* str);
511 void AssertValidSymbolPtr(JSContext* cx, JS::Symbol* sym);
512 void AssertValidValue(JSContext* cx, Value* v);
513
514 void JitValuePreWriteBarrier(JSRuntime* rt, Value* vp);
515 void JitStringPreWriteBarrier(JSRuntime* rt, JSString** stringp);
516 void JitObjectPreWriteBarrier(JSRuntime* rt, JSObject** objp);
517 void JitShapePreWriteBarrier(JSRuntime* rt, Shape** shapep);
518 void JitWasmAnyRefPreWriteBarrier(JSRuntime* rt, wasm::AnyRef* refp);
519
520 bool ObjectIsCallable(JSObject* obj);
521 bool ObjectIsConstructor(JSObject* obj);
522 JSObject* ObjectKeys(JSContext* cx, HandleObject obj);
523 bool ObjectKeysLength(JSContext* cx, HandleObject obj, int32_t* length);
524
525 [[nodiscard]] bool ThrowRuntimeLexicalError(JSContext* cx,
526 unsigned errorNumber);
527
528 [[nodiscard]] bool ThrowBadDerivedReturnOrUninitializedThis(JSContext* cx,
529 HandleValue v);
530
531 [[nodiscard]] bool BaselineGetFunctionThis(JSContext* cx, BaselineFrame* frame,
532 MutableHandleValue res);
533
534 [[nodiscard]] bool CallNativeGetter(JSContext* cx, HandleFunction callee,
535 HandleValue receiver,
536 MutableHandleValue result);
537
538 bool CallDOMGetter(JSContext* cx, const JSJitInfo* jitInfo, HandleObject obj,
539 MutableHandleValue result);
540
541 bool CallDOMSetter(JSContext* cx, const JSJitInfo* jitInfo, HandleObject obj,
542 HandleValue value);
543
544 [[nodiscard]] bool CallNativeSetter(JSContext* cx, HandleFunction callee,
545 HandleObject obj, HandleValue rhs);
546
547 [[nodiscard]] bool EqualStringsHelperPure(JSString* str1, JSString* str2);
548
549 void HandleCodeCoverageAtPC(BaselineFrame* frame, jsbytecode* pc);
550 void HandleCodeCoverageAtPrologue(BaselineFrame* frame);
551
552 bool CheckProxyGetByValueResult(JSContext* cx, HandleObject obj, HandleValue id,
553 HandleValue value, MutableHandleValue result);
554
555 bool GetNativeDataPropertyPure(JSContext* cx, JSObject* obj, PropertyKey id,
556 MegamorphicCacheEntry* entry, Value* vp);
557
558 bool GetNativeDataPropertyPureWithCacheLookup(JSContext* cx, JSObject* obj,
559 PropertyKey id,
560 MegamorphicCacheEntry* entry,
561 Value* vp);
562
563 bool GetNativeDataPropertyByValuePure(JSContext* cx, JSObject* obj,
564 MegamorphicCacheEntry* cacheEntry,
565 Value* vp);
566
567 bool GetPropMaybeCached(JSContext* cx, HandleObject obj, HandleId id,
568 MegamorphicCacheEntry* cacheEntry,
569 MutableHandleValue result);
570
571 bool GetElemMaybeCached(JSContext* cx, HandleObject obj, HandleValue id,
572 MegamorphicCacheEntry* cacheEntry,
573 MutableHandleValue result);
574
575 template <bool HasOwn>
576 bool HasNativeDataPropertyPure(JSContext* cx, JSObject* obj,
577 MegamorphicCacheEntry* cacheEntry, Value* vp);
578
579 bool HasNativeElementPure(JSContext* cx, NativeObject* obj, int32_t index,
580 Value* vp);
581
582 bool ObjectHasGetterSetterPure(JSContext* cx, JSObject* objArg, jsid id,
583 GetterSetter* getterSetter);
584
585 template <bool Cached>
586 bool SetElementMegamorphic(JSContext* cx, HandleObject obj, HandleValue index,
587 HandleValue value, bool strict);
588
589 template <bool Cached>
590 bool SetPropertyMegamorphic(JSContext* cx, HandleObject obj, HandleId id,
591 HandleValue value, bool strict);
592
593 JSString* TypeOfNameObject(JSObject* obj, JSRuntime* rt);
594
595 bool TypeOfEqObject(JSObject* obj, TypeofEqOperand operand);
596
597 bool GetPrototypeOf(JSContext* cx, HandleObject target,
598 MutableHandleValue rval);
599
600 bool DoConcatStringObject(JSContext* cx, HandleValue lhs, HandleValue rhs,
601 MutableHandleValue res);
602
603 bool IsPossiblyWrappedTypedArray(JSContext* cx, JSObject* obj, bool* result);
604
605 void* AllocateDependentString(JSContext* cx);
606 void* AllocateFatInlineString(JSContext* cx);
607 void* AllocateBigIntNoGC(JSContext* cx, bool requestMinorGC);
608 void AllocateAndInitTypedArrayBuffer(JSContext* cx, TypedArrayObject* obj,
609 int32_t count);
610
611 #ifdef JS_GC_PROBES
612 void TraceCreateObject(JSObject* obj);
613 #endif
614
615 bool DoStringToInt64(JSContext* cx, HandleString str, uint64_t* res);
616
617 BigInt* CreateBigIntFromInt32(JSContext* cx, int32_t i32);
618
619 #if JS_BITS_PER_WORD == 32
620 BigInt* CreateBigIntFromInt64(JSContext* cx, uint32_t low, uint32_t high);
621 BigInt* CreateBigIntFromUint64(JSContext* cx, uint32_t low, uint32_t high);
622 #else
623 BigInt* CreateBigIntFromInt64(JSContext* cx, uint64_t i64);
624 BigInt* CreateBigIntFromUint64(JSContext* cx, uint64_t i64);
625 #endif
626
627 template <EqualityKind Kind>
628 bool BigIntEqual(BigInt* x, BigInt* y);
629
630 template <ComparisonKind Kind>
631 bool BigIntCompare(BigInt* x, BigInt* y);
632
633 template <EqualityKind Kind>
634 bool BigIntNumberEqual(BigInt* x, double y);
635
636 template <ComparisonKind Kind>
637 bool BigIntNumberCompare(BigInt* x, double y);
638
639 template <ComparisonKind Kind>
640 bool NumberBigIntCompare(double x, BigInt* y);
641
642 template <EqualityKind Kind>
643 bool BigIntStringEqual(JSContext* cx, HandleBigInt x, HandleString y,
644 bool* res);
645
646 template <ComparisonKind Kind>
647 bool BigIntStringCompare(JSContext* cx, HandleBigInt x, HandleString y,
648 bool* res);
649
650 template <ComparisonKind Kind>
651 bool StringBigIntCompare(JSContext* cx, HandleString x, HandleBigInt y,
652 bool* res);
653
654 BigInt* BigIntAsIntN(JSContext* cx, HandleBigInt x, int32_t bits);
655 BigInt* BigIntAsUintN(JSContext* cx, HandleBigInt x, int32_t bits);
656
657 using AtomicsCompareExchangeFn = int32_t (*)(TypedArrayObject*, size_t, int32_t,
658 int32_t);
659
660 using AtomicsReadWriteModifyFn = int32_t (*)(TypedArrayObject*, size_t,
661 int32_t);
662
663 AtomicsCompareExchangeFn AtomicsCompareExchange(Scalar::Type elementType);
664 AtomicsReadWriteModifyFn AtomicsExchange(Scalar::Type elementType);
665 AtomicsReadWriteModifyFn AtomicsAdd(Scalar::Type elementType);
666 AtomicsReadWriteModifyFn AtomicsSub(Scalar::Type elementType);
667 AtomicsReadWriteModifyFn AtomicsAnd(Scalar::Type elementType);
668 AtomicsReadWriteModifyFn AtomicsOr(Scalar::Type elementType);
669 AtomicsReadWriteModifyFn AtomicsXor(Scalar::Type elementType);
670
671 BigInt* AtomicsLoad64(JSContext* cx, TypedArrayObject* typedArray,
672 size_t index);
673
674 void AtomicsStore64(TypedArrayObject* typedArray, size_t index,
675 const BigInt* value);
676
677 BigInt* AtomicsCompareExchange64(JSContext* cx, TypedArrayObject* typedArray,
678 size_t index, const BigInt* expected,
679 const BigInt* replacement);
680
681 BigInt* AtomicsExchange64(JSContext* cx, TypedArrayObject* typedArray,
682 size_t index, const BigInt* value);
683
684 BigInt* AtomicsAdd64(JSContext* cx, TypedArrayObject* typedArray, size_t index,
685 const BigInt* value);
686 BigInt* AtomicsAnd64(JSContext* cx, TypedArrayObject* typedArray, size_t index,
687 const BigInt* value);
688 BigInt* AtomicsOr64(JSContext* cx, TypedArrayObject* typedArray, size_t index,
689 const BigInt* value);
690 BigInt* AtomicsSub64(JSContext* cx, TypedArrayObject* typedArray, size_t index,
691 const BigInt* value);
692 BigInt* AtomicsXor64(JSContext* cx, TypedArrayObject* typedArray, size_t index,
693 const BigInt* value);
694
695 float RoundFloat16ToFloat32(int32_t d);
696 float RoundFloat16ToFloat32(float d);
697 float RoundFloat16ToFloat32(double d);
698
699 float Float16ToFloat32(int32_t value);
700 int32_t Float32ToFloat16(float value);
701
702 void DateFillLocalTimeSlots(DateObject* dateObj);
703
704 JSAtom* AtomizeStringNoGC(JSContext* cx, JSString* str);
705
706 bool SetObjectHas(JSContext* cx, Handle<SetObject*> obj, HandleValue key,
707 bool* rval);
708 bool SetObjectDelete(JSContext* cx, Handle<SetObject*> obj, HandleValue key,
709 bool* rval);
710 bool SetObjectAdd(JSContext* cx, Handle<SetObject*> obj, HandleValue key);
711 bool SetObjectAddFromIC(JSContext* cx, Handle<SetObject*> obj, HandleValue key,
712 MutableHandleValue rval);
713 bool MapObjectHas(JSContext* cx, Handle<MapObject*> obj, HandleValue key,
714 bool* rval);
715 bool MapObjectGet(JSContext* cx, Handle<MapObject*> obj, HandleValue key,
716 MutableHandleValue rval);
717 bool MapObjectDelete(JSContext* cx, Handle<MapObject*> obj, HandleValue key,
718 bool* rval);
719 bool MapObjectSet(JSContext* cx, Handle<MapObject*> obj, HandleValue key,
720 HandleValue val);
721 bool MapObjectSetFromIC(JSContext* cx, Handle<MapObject*> obj, HandleValue key,
722 HandleValue val, MutableHandleValue rval);
723
724 void AssertSetObjectHash(JSContext* cx, SetObject* obj, const Value* value,
725 mozilla::HashNumber actualHash);
726 void AssertMapObjectHash(JSContext* cx, MapObject* obj, const Value* value,
727 mozilla::HashNumber actualHash);
728
729 void AssertPropertyLookup(NativeObject* obj, PropertyKey id, uint32_t slot);
730
731 // Functions used when JS_MASM_VERBOSE is enabled.
732 void AssumeUnreachable(const char* output);
733 void Printf0(const char* output);
734 void Printf1(const char* output, uintptr_t value);
735
736 enum class VMFunctionId;
737
738 extern const VMFunctionData& GetVMFunction(VMFunctionId id);
739
740 extern size_t NumVMFunctions();
741
742 } // namespace jit
743 } // namespace js
744
745 #if defined(JS_CODEGEN_ARM)
746 extern "C" {
747 extern MOZ_EXPORT int64_t __aeabi_idivmod(int, int);
748 extern MOZ_EXPORT int64_t __aeabi_uidivmod(int, int);
749 }
750 #endif
751
752 #endif /* jit_VMFunctions_h */