JSContextRef.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * Copyright (C) 2006 Apple Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
  14. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
  17. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  21. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  23. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #ifndef JSContextRef_h
  26. #define JSContextRef_h
  27. #include <JavaScriptCore/JSObjectRef.h>
  28. #include <JavaScriptCore/JSValueRef.h>
  29. #include <JavaScriptCore/WebKitAvailability.h>
  30. #ifndef __cplusplus
  31. #include <stdbool.h>
  32. #endif
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /*!
  37. @function
  38. @abstract Creates a JavaScript context group.
  39. @discussion A JSContextGroup associates JavaScript contexts with one another.
  40. Contexts in the same group may share and exchange JavaScript objects. Sharing and/or exchanging
  41. JavaScript objects between contexts in different groups will produce undefined behavior.
  42. When objects from the same context group are used in multiple threads, explicit
  43. synchronization is required.
  44. A JSContextGroup may need to run deferred tasks on a run loop, such as garbage collection
  45. or resolving WebAssembly compilations. By default, calling JSContextGroupCreate will use
  46. the run loop of the thread it was called on. Currently, there is no API to change a
  47. JSContextGroup's run loop once it has been created.
  48. @result The created JSContextGroup.
  49. */
  50. JS_EXPORT JSContextGroupRef JSContextGroupCreate(void) JSC_API_AVAILABLE(macosx(10.6), ios(7.0));
  51. /*!
  52. @function
  53. @abstract Retains a JavaScript context group.
  54. @param group The JSContextGroup to retain.
  55. @result A JSContextGroup that is the same as group.
  56. */
  57. JS_EXPORT JSContextGroupRef JSContextGroupRetain(JSContextGroupRef group) JSC_API_AVAILABLE(macosx(10.6), ios(7.0));
  58. /*!
  59. @function
  60. @abstract Releases a JavaScript context group.
  61. @param group The JSContextGroup to release.
  62. */
  63. JS_EXPORT void JSContextGroupRelease(JSContextGroupRef group) JSC_API_AVAILABLE(macosx(10.6), ios(7.0));
  64. /*!
  65. @function
  66. @abstract Creates a global JavaScript execution context.
  67. @discussion JSGlobalContextCreate allocates a global object and populates it with all the
  68. built-in JavaScript objects, such as Object, Function, String, and Array.
  69. In WebKit version 4.0 and later, the context is created in a unique context group.
  70. Therefore, scripts may execute in it concurrently with scripts executing in other contexts.
  71. However, you may not use values created in the context in other contexts.
  72. @param globalObjectClass The class to use when creating the global object. Pass
  73. NULL to use the default object class.
  74. @result A JSGlobalContext with a global object of class globalObjectClass.
  75. */
  76. JS_EXPORT JSGlobalContextRef JSGlobalContextCreate(JSClassRef globalObjectClass) JSC_API_AVAILABLE(macosx(10.5), ios(7.0));
  77. /*!
  78. @function
  79. @abstract Creates a global JavaScript execution context in the context group provided.
  80. @discussion JSGlobalContextCreateInGroup allocates a global object and populates it with
  81. all the built-in JavaScript objects, such as Object, Function, String, and Array.
  82. @param globalObjectClass The class to use when creating the global object. Pass
  83. NULL to use the default object class.
  84. @param group The context group to use. The created global context retains the group.
  85. Pass NULL to create a unique group for the context.
  86. @result A JSGlobalContext with a global object of class globalObjectClass and a context
  87. group equal to group.
  88. */
  89. JS_EXPORT JSGlobalContextRef JSGlobalContextCreateInGroup(JSContextGroupRef group, JSClassRef globalObjectClass) JSC_API_AVAILABLE(macosx(10.6), ios(7.0));
  90. /*!
  91. @function
  92. @abstract Retains a global JavaScript execution context.
  93. @param ctx The JSGlobalContext to retain.
  94. @result A JSGlobalContext that is the same as ctx.
  95. */
  96. JS_EXPORT JSGlobalContextRef JSGlobalContextRetain(JSGlobalContextRef ctx);
  97. /*!
  98. @function
  99. @abstract Releases a global JavaScript execution context.
  100. @param ctx The JSGlobalContext to release.
  101. */
  102. JS_EXPORT void JSGlobalContextRelease(JSGlobalContextRef ctx);
  103. /*!
  104. @function
  105. @abstract Gets the global object of a JavaScript execution context.
  106. @param ctx The JSContext whose global object you want to get.
  107. @result ctx's global object.
  108. */
  109. JS_EXPORT JSObjectRef JSContextGetGlobalObject(JSContextRef ctx);
  110. /*!
  111. @function
  112. @abstract Gets the context group to which a JavaScript execution context belongs.
  113. @param ctx The JSContext whose group you want to get.
  114. @result ctx's group.
  115. */
  116. JS_EXPORT JSContextGroupRef JSContextGetGroup(JSContextRef ctx) JSC_API_AVAILABLE(macosx(10.6), ios(7.0));
  117. /*!
  118. @function
  119. @abstract Gets the global context of a JavaScript execution context.
  120. @param ctx The JSContext whose global context you want to get.
  121. @result ctx's global context.
  122. */
  123. JS_EXPORT JSGlobalContextRef JSContextGetGlobalContext(JSContextRef ctx) JSC_API_AVAILABLE(macosx(10.7), ios(7.0));
  124. /*!
  125. @function
  126. @abstract Gets a copy of the name of a context.
  127. @param ctx The JSGlobalContext whose name you want to get.
  128. @result The name for ctx.
  129. @discussion A JSGlobalContext's name is exposed for remote debugging to make it
  130. easier to identify the context you would like to attach to.
  131. */
  132. JS_EXPORT JSStringRef JSGlobalContextCopyName(JSGlobalContextRef ctx) JSC_API_AVAILABLE(macosx(10.10), ios(8.0));
  133. /*!
  134. @function
  135. @abstract Sets the remote debugging name for a context.
  136. @param ctx The JSGlobalContext that you want to name.
  137. @param name The remote debugging name to set on ctx.
  138. */
  139. JS_EXPORT void JSGlobalContextSetName(JSGlobalContextRef ctx, JSStringRef name) JSC_API_AVAILABLE(macosx(10.10), ios(8.0));
  140. #ifdef __cplusplus
  141. }
  142. #endif
  143. #endif /* JSContextRef_h */