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 vm_SelfHosting_h_
8 #define vm_SelfHosting_h_
9 
10 #include "jsapi.h"
11 #include "NamespaceImports.h"
12 
13 #include "vm/Stack.h"
14 
15 namespace js {
16 
17 /*
18  * Check whether the given JSFunction is a self-hosted function whose
19  * self-hosted name is the given name.
20  */
21 bool IsSelfHostedFunctionWithName(JSFunction* fun, JSAtom* name);
22 
23 /*
24  * Returns the name of the cloned function's binding in the self-hosted global.
25  *
26  * This returns a non-null value only when this is a top level function
27  * declaration in the self-hosted global.
28  */
29 PropertyName* GetClonedSelfHostedFunctionName(const JSFunction* fun);
30 
31 /*
32  * Same as GetClonedSelfHostedFunctionName, but `fun` is guaranteed to be an
33  * extended function.
34  *
35  * This function is supposed to be used off-thread, especially the JIT
36  * compilation thread, that cannot access JSFunction.flags_, because of
37  * a race condition.
38  *
39  * See Also: WrappedFunction.isExtended_
40  */
41 PropertyName* GetClonedSelfHostedFunctionNameOffMainThread(JSFunction* fun);
42 
43 constexpr char ExtendedUnclonedSelfHostedFunctionNamePrefix = '$';
44 
45 /*
46  * Uncloned self-hosted functions with `$` prefix are allocated as
47  * extended function, to store the original name in `_SetCanonicalName`.
48  */
49 bool IsExtendedUnclonedSelfHostedFunctionName(JSAtom* name);
50 
51 void SetUnclonedSelfHostedCanonicalName(JSFunction* fun, JSAtom* name);
52 
53 bool IsCallSelfHostedNonGenericMethod(NativeImpl impl);
54 
55 bool ReportIncompatibleSelfHostedMethod(JSContext* cx, const CallArgs& args);
56 
57 /* Get the compile options used when compiling self hosted code. */
58 void FillSelfHostingCompileOptions(JS::CompileOptions& options);
59 
60 #ifdef DEBUG
61 /*
62  * Calls a self-hosted function by name.
63  *
64  * This function is only available in debug mode, because it always atomizes
65  * its |name| parameter. Use the alternative function below in non-debug code.
66  */
67 bool CallSelfHostedFunction(JSContext* cx, char const* name, HandleValue thisv,
68                             const AnyInvokeArgs& args, MutableHandleValue rval);
69 #endif
70 
71 /*
72  * Calls a self-hosted function by name.
73  */
74 bool CallSelfHostedFunction(JSContext* cx, HandlePropertyName name,
75                             HandleValue thisv, const AnyInvokeArgs& args,
76                             MutableHandleValue rval);
77 
78 bool intrinsic_NewArrayIterator(JSContext* cx, unsigned argc, JS::Value* vp);
79 
80 bool intrinsic_NewStringIterator(JSContext* cx, unsigned argc, JS::Value* vp);
81 
82 bool intrinsic_NewRegExpStringIterator(JSContext* cx, unsigned argc,
83                                        JS::Value* vp);
84 
85 } /* namespace js */
86 
87 #endif /* vm_SelfHosting_h_ */
88