V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
v8config.h
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8CONFIG_H_
6 #define V8CONFIG_H_
7 
8 // clang-format off
9 
10 // Platform headers for feature detection below.
11 #if defined(__ANDROID__)
12 # include <sys/cdefs.h>
13 #elif defined(__APPLE__)
14 # include <TargetConditionals.h>
15 #elif defined(__linux__)
16 # include <features.h>
17 #endif
18 
19 
20 // This macro allows to test for the version of the GNU C library (or
21 // a compatible C library that masquerades as glibc). It evaluates to
22 // 0 if libc is not GNU libc or compatible.
23 // Use like:
24 // #if V8_GLIBC_PREREQ(2, 3)
25 // ...
26 // #endif
27 #if defined(__GLIBC__) && defined(__GLIBC_MINOR__)
28 # define V8_GLIBC_PREREQ(major, minor) \
29  ((__GLIBC__ * 100 + __GLIBC_MINOR__) >= ((major) * 100 + (minor)))
30 #else
31 # define V8_GLIBC_PREREQ(major, minor) 0
32 #endif
33 
34 
35 // This macro allows to test for the version of the GNU C++ compiler.
36 // Note that this also applies to compilers that masquerade as GCC,
37 // for example clang and the Intel C++ compiler for Linux.
38 // Use like:
39 // #if V8_GNUC_PREREQ(4, 3, 1)
40 // ...
41 // #endif
42 #if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
43 # define V8_GNUC_PREREQ(major, minor, patchlevel) \
44  ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= \
45  ((major) * 10000 + (minor) * 100 + (patchlevel)))
46 #elif defined(__GNUC__) && defined(__GNUC_MINOR__)
47 # define V8_GNUC_PREREQ(major, minor, patchlevel) \
48  ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100) >= \
49  ((major) * 10000 + (minor) * 100 + (patchlevel)))
50 #else
51 # define V8_GNUC_PREREQ(major, minor, patchlevel) 0
52 #endif
53 
54 
55 
56 // -----------------------------------------------------------------------------
57 // Operating system detection
58 //
59 // V8_OS_ANDROID - Android
60 // V8_OS_BSD - BSDish (Mac OS X, Net/Free/Open/DragonFlyBSD)
61 // V8_OS_CYGWIN - Cygwin
62 // V8_OS_DRAGONFLYBSD - DragonFlyBSD
63 // V8_OS_FREEBSD - FreeBSD
64 // V8_OS_FUCHSIA - Fuchsia
65 // V8_OS_LINUX - Linux
66 // V8_OS_MACOSX - Mac OS X
67 // V8_OS_NETBSD - NetBSD
68 // V8_OS_OPENBSD - OpenBSD
69 // V8_OS_POSIX - POSIX compatible (mostly everything except Windows)
70 // V8_OS_QNX - QNX Neutrino
71 // V8_OS_SOLARIS - Sun Solaris and OpenSolaris
72 // V8_OS_AIX - AIX
73 // V8_OS_WIN - Microsoft Windows
74 
75 #if defined(__ANDROID__)
76 # define V8_OS_ANDROID 1
77 # define V8_OS_LINUX 1
78 # define V8_OS_POSIX 1
79 #elif defined(__APPLE__)
80 # define V8_OS_BSD 1
81 # define V8_OS_MACOSX 1
82 # define V8_OS_POSIX 1
83 #elif defined(__CYGWIN__)
84 # define V8_OS_CYGWIN 1
85 # define V8_OS_POSIX 1
86 #elif defined(__linux__)
87 # define V8_OS_LINUX 1
88 # define V8_OS_POSIX 1
89 #elif defined(__sun)
90 # define V8_OS_POSIX 1
91 # define V8_OS_SOLARIS 1
92 #elif defined(_AIX)
93 #define V8_OS_POSIX 1
94 #define V8_OS_AIX 1
95 #elif defined(__FreeBSD__)
96 # define V8_OS_BSD 1
97 # define V8_OS_FREEBSD 1
98 # define V8_OS_POSIX 1
99 #elif defined(__Fuchsia__)
100 # define V8_OS_FUCHSIA 1
101 # define V8_OS_POSIX 1
102 #elif defined(__DragonFly__)
103 # define V8_OS_BSD 1
104 # define V8_OS_DRAGONFLYBSD 1
105 # define V8_OS_POSIX 1
106 #elif defined(__NetBSD__)
107 # define V8_OS_BSD 1
108 # define V8_OS_NETBSD 1
109 # define V8_OS_POSIX 1
110 #elif defined(__OpenBSD__)
111 # define V8_OS_BSD 1
112 # define V8_OS_OPENBSD 1
113 # define V8_OS_POSIX 1
114 #elif defined(__QNXNTO__)
115 # define V8_OS_POSIX 1
116 # define V8_OS_QNX 1
117 #elif defined(_WIN32)
118 # define V8_OS_WIN 1
119 #endif
120 
121 
122 // -----------------------------------------------------------------------------
123 // C library detection
124 //
125 // V8_LIBC_MSVCRT - MSVC libc
126 // V8_LIBC_BIONIC - Bionic libc
127 // V8_LIBC_BSD - BSD libc derivate
128 // V8_LIBC_GLIBC - GNU C library
129 // V8_LIBC_UCLIBC - uClibc
130 //
131 // Note that testing for libc must be done using #if not #ifdef. For example,
132 // to test for the GNU C library, use:
133 // #if V8_LIBC_GLIBC
134 // ...
135 // #endif
136 
137 #if defined (_MSC_VER)
138 # define V8_LIBC_MSVCRT 1
139 #elif defined(__BIONIC__)
140 # define V8_LIBC_BIONIC 1
141 # define V8_LIBC_BSD 1
142 #elif defined(__UCLIBC__)
143 // Must test for UCLIBC before GLIBC, as UCLIBC pretends to be GLIBC.
144 # define V8_LIBC_UCLIBC 1
145 #elif defined(__GLIBC__) || defined(__GNU_LIBRARY__)
146 # define V8_LIBC_GLIBC 1
147 #else
148 # define V8_LIBC_BSD V8_OS_BSD
149 #endif
150 
151 
152 // -----------------------------------------------------------------------------
153 // Compiler detection
154 //
155 // V8_CC_GNU - GCC, or clang in gcc mode
156 // V8_CC_INTEL - Intel C++
157 // V8_CC_MINGW - Minimalist GNU for Windows
158 // V8_CC_MINGW32 - Minimalist GNU for Windows (mingw32)
159 // V8_CC_MINGW64 - Minimalist GNU for Windows (mingw-w64)
160 // V8_CC_MSVC - Microsoft Visual C/C++, or clang in cl.exe mode
161 //
162 // C++11 feature detection
163 //
164 // V8_HAS_CXX11_ALIGNAS - alignas specifier supported
165 // V8_HAS_CXX11_ALIGNOF - alignof(type) operator supported
166 //
167 // Compiler-specific feature detection
168 //
169 // V8_HAS___ALIGNOF - __alignof(type) operator supported
170 // V8_HAS___ALIGNOF__ - __alignof__(type) operator supported
171 // V8_HAS_ATTRIBUTE_ALIGNED - __attribute__((aligned(n))) supported
172 // V8_HAS_ATTRIBUTE_ALWAYS_INLINE - __attribute__((always_inline))
173 // supported
174 // V8_HAS_ATTRIBUTE_DEPRECATED - __attribute__((deprecated)) supported
175 // V8_HAS_ATTRIBUTE_NOINLINE - __attribute__((noinline)) supported
176 // V8_HAS_ATTRIBUTE_UNUSED - __attribute__((unused)) supported
177 // V8_HAS_ATTRIBUTE_VISIBILITY - __attribute__((visibility)) supported
178 // V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT - __attribute__((warn_unused_result))
179 // supported
180 // V8_HAS_BUILTIN_BSWAP16 - __builtin_bswap16() supported
181 // V8_HAS_BUILTIN_BSWAP32 - __builtin_bswap32() supported
182 // V8_HAS_BUILTIN_BSWAP64 - __builtin_bswap64() supported
183 // V8_HAS_BUILTIN_CLZ - __builtin_clz() supported
184 // V8_HAS_BUILTIN_CTZ - __builtin_ctz() supported
185 // V8_HAS_BUILTIN_EXPECT - __builtin_expect() supported
186 // V8_HAS_BUILTIN_FRAME_ADDRESS - __builtin_frame_address() supported
187 // V8_HAS_BUILTIN_POPCOUNT - __builtin_popcount() supported
188 // V8_HAS_BUILTIN_SADD_OVERFLOW - __builtin_sadd_overflow() supported
189 // V8_HAS_BUILTIN_SSUB_OVERFLOW - __builtin_ssub_overflow() supported
190 // V8_HAS_BUILTIN_UADD_OVERFLOW - __builtin_uadd_overflow() supported
191 // V8_HAS_DECLSPEC_ALIGN - __declspec(align(n)) supported
192 // V8_HAS_DECLSPEC_DEPRECATED - __declspec(deprecated) supported
193 // V8_HAS_DECLSPEC_NOINLINE - __declspec(noinline) supported
194 // V8_HAS_DECLSPEC_SELECTANY - __declspec(selectany) supported
195 // V8_HAS_DECLSPEC_NORETURN - __declspec(noreturn) supported
196 // V8_HAS___FORCEINLINE - __forceinline supported
197 //
198 // Note that testing for compilers and/or features must be done using #if
199 // not #ifdef. For example, to test for Intel C++ Compiler, use:
200 // #if V8_CC_INTEL
201 // ...
202 // #endif
203 
204 #if defined(__clang__)
205 
206 #if defined(__GNUC__) // Clang in gcc mode.
207 # define V8_CC_GNU 1
208 #endif
209 
210 // Clang defines __alignof__ as alias for __alignof
211 # define V8_HAS___ALIGNOF 1
212 # define V8_HAS___ALIGNOF__ V8_HAS___ALIGNOF
213 
214 # define V8_HAS_ATTRIBUTE_ALIGNED (__has_attribute(aligned))
215 # define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (__has_attribute(always_inline))
216 # define V8_HAS_ATTRIBUTE_DEPRECATED (__has_attribute(deprecated))
217 # define V8_HAS_ATTRIBUTE_DEPRECATED_MESSAGE \
218  (__has_extension(attribute_deprecated_with_message))
219 # define V8_HAS_ATTRIBUTE_NOINLINE (__has_attribute(noinline))
220 # define V8_HAS_ATTRIBUTE_UNUSED (__has_attribute(unused))
221 # define V8_HAS_ATTRIBUTE_VISIBILITY (__has_attribute(visibility))
222 # define V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT \
223  (__has_attribute(warn_unused_result))
224 
225 # define V8_HAS_BUILTIN_BSWAP16 (__has_builtin(__builtin_bswap16))
226 # define V8_HAS_BUILTIN_BSWAP32 (__has_builtin(__builtin_bswap32))
227 # define V8_HAS_BUILTIN_BSWAP64 (__has_builtin(__builtin_bswap64))
228 # define V8_HAS_BUILTIN_CLZ (__has_builtin(__builtin_clz))
229 # define V8_HAS_BUILTIN_CTZ (__has_builtin(__builtin_ctz))
230 # define V8_HAS_BUILTIN_EXPECT (__has_builtin(__builtin_expect))
231 # define V8_HAS_BUILTIN_FRAME_ADDRESS (__has_builtin(__builtin_frame_address))
232 # define V8_HAS_BUILTIN_POPCOUNT (__has_builtin(__builtin_popcount))
233 # define V8_HAS_BUILTIN_SADD_OVERFLOW (__has_builtin(__builtin_sadd_overflow))
234 # define V8_HAS_BUILTIN_SSUB_OVERFLOW (__has_builtin(__builtin_ssub_overflow))
235 # define V8_HAS_BUILTIN_UADD_OVERFLOW (__has_builtin(__builtin_uadd_overflow))
236 
237 # define V8_HAS_CXX11_ALIGNAS (__has_feature(cxx_alignas))
238 
239 # if __cplusplus >= 201402L
240 # define V8_CAN_HAVE_DCHECK_IN_CONSTEXPR 1
241 # endif
242 
243 #elif defined(__GNUC__)
244 
245 # define V8_CC_GNU 1
246 # if defined(__INTEL_COMPILER) // Intel C++ also masquerades as GCC 3.2.0
247 # define V8_CC_INTEL 1
248 # endif
249 # if defined(__MINGW32__)
250 # define V8_CC_MINGW32 1
251 # endif
252 # if defined(__MINGW64__)
253 # define V8_CC_MINGW64 1
254 # endif
255 # define V8_CC_MINGW (V8_CC_MINGW32 || V8_CC_MINGW64)
256 
257 # define V8_HAS___ALIGNOF__ (V8_GNUC_PREREQ(4, 3, 0))
258 
259 # define V8_HAS_ATTRIBUTE_ALIGNED (V8_GNUC_PREREQ(2, 95, 0))
260 // always_inline is available in gcc 4.0 but not very reliable until 4.4.
261 // Works around "sorry, unimplemented: inlining failed" build errors with
262 // older compilers.
263 # define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (V8_GNUC_PREREQ(4, 4, 0))
264 # define V8_HAS_ATTRIBUTE_DEPRECATED (V8_GNUC_PREREQ(3, 4, 0))
265 # define V8_HAS_ATTRIBUTE_DEPRECATED_MESSAGE (V8_GNUC_PREREQ(4, 5, 0))
266 # define V8_HAS_ATTRIBUTE_NOINLINE (V8_GNUC_PREREQ(3, 4, 0))
267 # define V8_HAS_ATTRIBUTE_UNUSED (V8_GNUC_PREREQ(2, 95, 0))
268 # define V8_HAS_ATTRIBUTE_VISIBILITY (V8_GNUC_PREREQ(4, 3, 0))
269 # define V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT \
270  (!V8_CC_INTEL && V8_GNUC_PREREQ(4, 1, 0))
271 
272 # define V8_HAS_BUILTIN_CLZ (V8_GNUC_PREREQ(3, 4, 0))
273 # define V8_HAS_BUILTIN_CTZ (V8_GNUC_PREREQ(3, 4, 0))
274 # define V8_HAS_BUILTIN_EXPECT (V8_GNUC_PREREQ(2, 96, 0))
275 # define V8_HAS_BUILTIN_FRAME_ADDRESS (V8_GNUC_PREREQ(2, 96, 0))
276 # define V8_HAS_BUILTIN_POPCOUNT (V8_GNUC_PREREQ(3, 4, 0))
277 
278 # if __cplusplus >= 201103L
279 # define V8_HAS_CXX11_ALIGNAS (V8_GNUC_PREREQ(4, 8, 0))
280 # define V8_HAS_CXX11_ALIGNOF (V8_GNUC_PREREQ(4, 8, 0))
281 # endif
282 #endif
283 
284 #if defined(_MSC_VER)
285 # define V8_CC_MSVC 1
286 # define V8_HAS___ALIGNOF 1
287 
288 # define V8_HAS_DECLSPEC_ALIGN 1
289 # define V8_HAS_DECLSPEC_DEPRECATED 1
290 # define V8_HAS_DECLSPEC_NOINLINE 1
291 # define V8_HAS_DECLSPEC_SELECTANY 1
292 # define V8_HAS_DECLSPEC_NORETURN 1
293 
294 # define V8_HAS___FORCEINLINE 1
295 
296 #endif
297 
298 
299 // -----------------------------------------------------------------------------
300 // Helper macros
301 
302 // A macro used to make better inlining. Don't bother for debug builds.
303 // Use like:
304 // V8_INLINE int GetZero() { return 0; }
305 #if !defined(DEBUG) && V8_HAS_ATTRIBUTE_ALWAYS_INLINE
306 # define V8_INLINE inline __attribute__((always_inline))
307 #elif !defined(DEBUG) && V8_HAS___FORCEINLINE
308 # define V8_INLINE __forceinline
309 #else
310 # define V8_INLINE inline
311 #endif
312 
313 
314 // A macro used to tell the compiler to never inline a particular function.
315 // Don't bother for debug builds.
316 // Use like:
317 // V8_NOINLINE int GetMinusOne() { return -1; }
318 #if !defined(DEBUG) && V8_HAS_ATTRIBUTE_NOINLINE
319 # define V8_NOINLINE __attribute__((noinline))
320 #elif !defined(DEBUG) && V8_HAS_DECLSPEC_NOINLINE
321 # define V8_NOINLINE __declspec(noinline)
322 #else
323 # define V8_NOINLINE /* NOT SUPPORTED */
324 #endif
325 
326 
327 // A macro (V8_DEPRECATED) to mark classes or functions as deprecated.
328 #if defined(V8_DEPRECATION_WARNINGS) && V8_HAS_ATTRIBUTE_DEPRECATED_MESSAGE
329 #define V8_DEPRECATED(message, declarator) \
330  declarator __attribute__((deprecated(message)))
331 #elif defined(V8_DEPRECATION_WARNINGS) && V8_HAS_ATTRIBUTE_DEPRECATED
332 #define V8_DEPRECATED(message, declarator) \
333  declarator __attribute__((deprecated))
334 #elif defined(V8_DEPRECATION_WARNINGS) && V8_HAS_DECLSPEC_DEPRECATED
335 #define V8_DEPRECATED(message, declarator) __declspec(deprecated) declarator
336 #else
337 #define V8_DEPRECATED(message, declarator) declarator
338 #endif
339 
340 
341 // A macro (V8_DEPRECATE_SOON) to make it easier to see what will be deprecated.
342 #if defined(V8_IMMINENT_DEPRECATION_WARNINGS) && \
343  V8_HAS_ATTRIBUTE_DEPRECATED_MESSAGE
344 #define V8_DEPRECATE_SOON(message, declarator) \
345  declarator __attribute__((deprecated(message)))
346 #elif defined(V8_IMMINENT_DEPRECATION_WARNINGS) && V8_HAS_ATTRIBUTE_DEPRECATED
347 #define V8_DEPRECATE_SOON(message, declarator) \
348  declarator __attribute__((deprecated))
349 #elif defined(V8_IMMINENT_DEPRECATION_WARNINGS) && V8_HAS_DECLSPEC_DEPRECATED
350 #define V8_DEPRECATE_SOON(message, declarator) __declspec(deprecated) declarator
351 #else
352 #define V8_DEPRECATE_SOON(message, declarator) declarator
353 #endif
354 
355 
356 // A macro to provide the compiler with branch prediction information.
357 #if V8_HAS_BUILTIN_EXPECT
358 # define V8_UNLIKELY(condition) (__builtin_expect(!!(condition), 0))
359 # define V8_LIKELY(condition) (__builtin_expect(!!(condition), 1))
360 #else
361 # define V8_UNLIKELY(condition) (condition)
362 # define V8_LIKELY(condition) (condition)
363 #endif
364 
365 
366 // This macro allows to specify memory alignment for structs, classes, etc.
367 // Use like:
368 // class V8_ALIGNED(16) MyClass { ... };
369 // V8_ALIGNED(32) int array[42];
370 #if V8_HAS_CXX11_ALIGNAS
371 # define V8_ALIGNED(n) alignas(n)
372 #elif V8_HAS_ATTRIBUTE_ALIGNED
373 # define V8_ALIGNED(n) __attribute__((aligned(n)))
374 #elif V8_HAS_DECLSPEC_ALIGN
375 # define V8_ALIGNED(n) __declspec(align(n))
376 #else
377 # define V8_ALIGNED(n) /* NOT SUPPORTED */
378 #endif
379 
380 
381 // This macro is similar to V8_ALIGNED(), but takes a type instead of size
382 // in bytes. If the compiler does not supports using the alignment of the
383 // |type|, it will align according to the |alignment| instead. For example,
384 // Visual Studio C++ cannot combine __declspec(align) and __alignof. The
385 // |alignment| must be a literal that is used as a kind of worst-case fallback
386 // alignment.
387 // Use like:
388 // struct V8_ALIGNAS(AnotherClass, 16) NewClass { ... };
389 // V8_ALIGNAS(double, 8) int array[100];
390 #if V8_HAS_CXX11_ALIGNAS
391 # define V8_ALIGNAS(type, alignment) alignas(type)
392 #elif V8_HAS___ALIGNOF__ && V8_HAS_ATTRIBUTE_ALIGNED
393 # define V8_ALIGNAS(type, alignment) __attribute__((aligned(__alignof__(type))))
394 #else
395 # define V8_ALIGNAS(type, alignment) V8_ALIGNED(alignment)
396 #endif
397 
398 
399 // This macro returns alignment in bytes (an integer power of two) required for
400 // any instance of the given type, which is either complete type, an array type,
401 // or a reference type.
402 // Use like:
403 // size_t alignment = V8_ALIGNOF(double);
404 #if V8_HAS_CXX11_ALIGNOF
405 # define V8_ALIGNOF(type) alignof(type)
406 #elif V8_HAS___ALIGNOF
407 # define V8_ALIGNOF(type) __alignof(type)
408 #elif V8_HAS___ALIGNOF__
409 # define V8_ALIGNOF(type) __alignof__(type)
410 #else
411 // Note that alignment of a type within a struct can be less than the
412 // alignment of the type stand-alone (because of ancient ABIs), so this
413 // should only be used as a last resort.
414 namespace v8 { template <typename T> class AlignOfHelper { char c; T t; }; }
415 # define V8_ALIGNOF(type) (sizeof(::v8::AlignOfHelper<type>) - sizeof(type))
416 #endif
417 
418 // Annotate a function indicating the caller must examine the return value.
419 // Use like:
420 // int foo() V8_WARN_UNUSED_RESULT;
421 #if V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT
422 #define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
423 #else
424 #define V8_WARN_UNUSED_RESULT /* NOT SUPPORTED */
425 #endif
426 
427 #ifdef V8_OS_WIN
428 
429 // Setup for Windows DLL export/import. When building the V8 DLL the
430 // BUILDING_V8_SHARED needs to be defined. When building a program which uses
431 // the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8
432 // static library or building a program which uses the V8 static library neither
433 // BUILDING_V8_SHARED nor USING_V8_SHARED should be defined.
434 #ifdef BUILDING_V8_SHARED
435 # define V8_EXPORT __declspec(dllexport)
436 #elif USING_V8_SHARED
437 # define V8_EXPORT __declspec(dllimport)
438 #else
439 # define V8_EXPORT
440 #endif // BUILDING_V8_SHARED
441 
442 #else // V8_OS_WIN
443 
444 // Setup for Linux shared library export.
445 #if V8_HAS_ATTRIBUTE_VISIBILITY
446 # ifdef BUILDING_V8_SHARED
447 # define V8_EXPORT __attribute__ ((visibility("default")))
448 # else
449 # define V8_EXPORT
450 # endif
451 #else
452 # define V8_EXPORT
453 #endif
454 
455 #endif // V8_OS_WIN
456 
457 // clang-format on
458 
459 #endif // V8CONFIG_H_
Definition: libplatform.h:13