OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** \mainpage V8 API Reference Guide | 5 /** \mainpage V8 API Reference Guide |
6 * | 6 * |
7 * V8 is Google's open source JavaScript engine. | 7 * V8 is Google's open source JavaScript engine. |
8 * | 8 * |
9 * This set of documents provides reference material generated from the | 9 * This set of documents provides reference material generated from the |
10 * V8 header file, include/v8.h. | 10 * V8 header file, include/v8.h. |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 class Isolate; | 118 class Isolate; |
119 class DeclaredAccessorDescriptor; | 119 class DeclaredAccessorDescriptor; |
120 class ObjectOperationDescriptor; | 120 class ObjectOperationDescriptor; |
121 class RawOperationDescriptor; | 121 class RawOperationDescriptor; |
122 class CallHandlerHelper; | 122 class CallHandlerHelper; |
123 class EscapableHandleScope; | 123 class EscapableHandleScope; |
124 template<typename T> class ReturnValue; | 124 template<typename T> class ReturnValue; |
125 | 125 |
126 namespace internal { | 126 namespace internal { |
127 class Arguments; | 127 class Arguments; |
128 class BackgroundParsingTask; | |
129 class CompilationInfo; | |
130 class ExternalStreamingStream; | |
131 class FinalizeParsingTask; | |
128 class Heap; | 132 class Heap; |
129 class HeapObject; | 133 class HeapObject; |
130 class Isolate; | 134 class Isolate; |
131 class Object; | 135 class Object; |
132 template<typename T> class CustomArguments; | 136 template<typename T> class CustomArguments; |
133 class PropertyCallbackArguments; | 137 class PropertyCallbackArguments; |
134 class FunctionCallbackArguments; | 138 class FunctionCallbackArguments; |
135 class GlobalHandles; | 139 class GlobalHandles; |
136 } | 140 } |
137 | 141 |
(...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
938 private: | 942 private: |
939 Handle<Value> resource_name_; | 943 Handle<Value> resource_name_; |
940 Handle<Integer> resource_line_offset_; | 944 Handle<Integer> resource_line_offset_; |
941 Handle<Integer> resource_column_offset_; | 945 Handle<Integer> resource_column_offset_; |
942 Handle<Boolean> resource_is_shared_cross_origin_; | 946 Handle<Boolean> resource_is_shared_cross_origin_; |
943 Handle<Integer> script_id_; | 947 Handle<Integer> script_id_; |
944 }; | 948 }; |
945 | 949 |
946 | 950 |
947 /** | 951 /** |
952 * For streaming incomplete script data to V8. The embedder should implement a | |
953 * subclass of this class. | |
954 */ | |
955 class V8_EXPORT ExternalSourceStream { | |
956 public: | |
957 enum Encoding { ONE_BYTE, TWO_BYTE, UTF8, UNKNOWN }; | |
958 | |
959 ExternalSourceStream() : encoding(UNKNOWN) {} | |
960 virtual ~ExternalSourceStream() {} | |
961 | |
962 /** | |
963 * V8 calls this to request the next chunk of data from the embedder. This | |
964 * function will be called on a background thread, so it's OK to block and | |
965 * wait for the data, if the embedder doesn't have data yet. Returns the | |
966 * length of the data returned. The caller takes ownership of the data. | |
967 */ | |
968 virtual unsigned GetSomeData(const char** src, unsigned position) = 0; | |
jochen (gone - plz use gerrit)
2014/08/13 14:24:45
GetMoreData?
it's a bit odd to pass TWO_BYTE data
marja
2014/08/14 11:29:21
1) This API (the name GetSomeData and passing the
| |
969 | |
970 protected: | |
971 /** | |
972 * The embedder should call this as soon as it knows the encoding. It must be | |
973 * called before the first call to GetSomeData returns. | |
974 */ | |
975 void SetEncoding(Encoding e) { encoding = e; } | |
976 | |
977 private: | |
978 friend class internal::ExternalStreamingStream; | |
979 Encoding encoding; | |
980 }; | |
981 | |
982 | |
983 /** | |
948 * A compiled JavaScript script, not yet tied to a Context. | 984 * A compiled JavaScript script, not yet tied to a Context. |
949 */ | 985 */ |
950 class V8_EXPORT UnboundScript { | 986 class V8_EXPORT UnboundScript { |
951 public: | 987 public: |
952 /** | 988 /** |
953 * Binds the script to the currently entered context. | 989 * Binds the script to the currently entered context. |
954 */ | 990 */ |
955 Local<Script> BindToCurrentContext(); | 991 Local<Script> BindToCurrentContext(); |
956 | 992 |
957 int GetId(); | 993 int GetId(); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1009 return GetUnboundScript()->GetId(); | 1045 return GetUnboundScript()->GetId(); |
1010 } | 1046 } |
1011 }; | 1047 }; |
1012 | 1048 |
1013 | 1049 |
1014 /** | 1050 /** |
1015 * For compiling scripts. | 1051 * For compiling scripts. |
1016 */ | 1052 */ |
1017 class V8_EXPORT ScriptCompiler { | 1053 class V8_EXPORT ScriptCompiler { |
1018 public: | 1054 public: |
1055 class StreamedSource; | |
1056 typedef void (*StreamingCompleteCallback)(StreamedSource*, void*); | |
1057 | |
1019 /** | 1058 /** |
1020 * Compilation data that the embedder can cache and pass back to speed up | 1059 * Compilation data that the embedder can cache and pass back to speed up |
1021 * future compilations. The data is produced if the CompilerOptions passed to | 1060 * future compilations. The data is produced if the CompilerOptions passed to |
1022 * the compilation functions in ScriptCompiler contains produce_data_to_cache | 1061 * the compilation functions in ScriptCompiler contains produce_data_to_cache |
1023 * = true. The data to cache can then can be retrieved from | 1062 * = true. The data to cache can then can be retrieved from |
1024 * UnboundScript. | 1063 * UnboundScript. |
1025 */ | 1064 */ |
1026 struct V8_EXPORT CachedData { | 1065 struct V8_EXPORT CachedData { |
1027 enum BufferPolicy { | 1066 enum BufferPolicy { |
1028 BufferNotOwned, | 1067 BufferNotOwned, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1080 Handle<Integer> resource_line_offset; | 1119 Handle<Integer> resource_line_offset; |
1081 Handle<Integer> resource_column_offset; | 1120 Handle<Integer> resource_column_offset; |
1082 Handle<Boolean> resource_is_shared_cross_origin; | 1121 Handle<Boolean> resource_is_shared_cross_origin; |
1083 | 1122 |
1084 // Cached data from previous compilation (if a kConsume*Cache flag is | 1123 // Cached data from previous compilation (if a kConsume*Cache flag is |
1085 // set), or hold newly generated cache data (kProduce*Cache flags) are | 1124 // set), or hold newly generated cache data (kProduce*Cache flags) are |
1086 // set when calling a compile method. | 1125 // set when calling a compile method. |
1087 CachedData* cached_data; | 1126 CachedData* cached_data; |
1088 }; | 1127 }; |
1089 | 1128 |
1129 /** | |
1130 * Source code which can be streamed into V8 in pieces. It will be parsed | |
1131 * while streaming, and compiled after the streaming is complete. | |
1132 * StreamedSource must be kept alive while the compilation is ongoing. | |
1133 */ | |
1134 class StreamedSource { | |
1135 public: | |
1136 // Source takes ownership of CachedData. | |
1137 V8_INLINE StreamedSource(ExternalSourceStream* source_stream); | |
jochen (gone - plz use gerrit)
2014/08/13 14:24:45
explicit
marja
2014/08/14 11:29:21
Done.
| |
1138 ~StreamedSource(); | |
1139 | |
1140 // Ownership of the CachedData or its buffers is *not* transferred to the | |
1141 // caller. The CachedData object is alive as long as the Source object is | |
jochen (gone - plz use gerrit)
2014/08/13 14:24:45
you mean StreamedSource object?
marja
2014/08/14 11:29:22
Done.
| |
1142 // alive. | |
1143 V8_INLINE const CachedData* GetCachedData() const; | |
1144 | |
1145 private: | |
1146 friend class ScriptCompiler; | |
1147 friend class internal::BackgroundParsingTask; | |
1148 friend class internal::FinalizeParsingTask; | |
1149 | |
1150 // Prevent copying. Not implemented. | |
1151 StreamedSource(const StreamedSource&); | |
1152 StreamedSource& operator=(const StreamedSource&); | |
1153 | |
1154 ExternalSourceStream* source_stream; | |
1155 | |
1156 // Cached data generated during compilation (if the generate_cached_data | |
1157 // flag is passed to ScriptCompiler::StartStreamingScript). Streamed scripts | |
1158 // cannot utilize already existing cached data. | |
1159 CachedData* cached_data; | |
1160 | |
1161 internal::CompilationInfo* info; | |
1162 }; | |
1163 | |
1090 enum CompileOptions { | 1164 enum CompileOptions { |
1091 kNoCompileOptions = 0, | 1165 kNoCompileOptions = 0, |
1092 kProduceParserCache, | 1166 kProduceParserCache, |
1093 kConsumeParserCache, | 1167 kConsumeParserCache, |
1094 kProduceCodeCache, | 1168 kProduceCodeCache, |
1095 kConsumeCodeCache, | 1169 kConsumeCodeCache, |
1096 | 1170 |
1097 // Support the previous API for a transition period. | 1171 // Support the previous API for a transition period. |
1098 kProduceDataToCache | 1172 kProduceDataToCache |
1099 }; | 1173 }; |
1100 | 1174 |
1101 /** | 1175 /** |
1102 * Compiles the specified script (context-independent). | 1176 * Compiles the specified script (context-independent). |
1103 * Cached data as part of the source object can be optionally produced to be | 1177 * Cached data as part of the source object can be optionally produced to be |
1104 * consumed later to speed up compilation of identical source scripts. | 1178 * consumed later to speed up compilation of identical source scripts. |
1105 * | 1179 * |
1106 * Note that when producing cached data, the source must point to NULL for | 1180 * Note that when producing cached data, the source must point to NULL for |
1107 * cached data. When consuming cached data, the cached data must have been | 1181 * cached data. When consuming cached data, the cached data must have been |
1108 * produced by the same version of V8. | 1182 * produced by the same version of V8. |
1109 * | 1183 * |
1110 * \param source Script source code. | 1184 * \param source Script source code. |
1111 * \return Compiled script object (context independent; for running it must be | 1185 * \return Compiled script object (context independent; for running it must be |
1112 * bound to a context). | 1186 * bound to a context). |
1113 */ | 1187 */ |
1114 static Local<UnboundScript> CompileUnbound( | 1188 static Local<UnboundScript> CompileUnbound( |
1115 Isolate* isolate, Source* source, | 1189 Isolate* isolate, Source* source, |
1116 CompileOptions options = kNoCompileOptions); | 1190 CompileOptions options = kNoCompileOptions); |
1117 | 1191 |
1118 /** | 1192 /** |
1193 * Starts streaming script data into V8. This API allows to start the | |
1194 * streaming with as little data as possible, and the remaining data (for | |
1195 * example, the ScriptOrigin) is passed to Compile (see below). The script is | |
1196 * parsed while streaming. When all data has been streamed, the callback | |
1197 * provided by the embedder is called, and the script can be compiled. | |
1198 */ | |
1199 static bool StartStreamingScript(Isolate* isolate, StreamedSource* source, | |
1200 StreamingCompleteCallback callback, | |
1201 void* callback_data, | |
1202 CompileOptions options = kNoCompileOptions); | |
1203 | |
1204 /** | |
1205 * Compiles a streamed script. This can only be called after the streaming has | |
1206 * finished (the callback passed to StartStreamingScript has been called). V8 | |
1207 * doesn't construct the source string as it streams, so the embedder needs to | |
1208 * pass the full source here. | |
1209 */ | |
1210 static Local<Script> Compile(Isolate* isolate, StreamedSource* source, | |
1211 Handle<String> full_source_string, | |
1212 const ScriptOrigin& origin); | |
1213 | |
1214 /** | |
1119 * Compiles the specified script (bound to current context). | 1215 * Compiles the specified script (bound to current context). |
1120 * | 1216 * |
1121 * \param source Script source code. | 1217 * \param source Script source code. |
1122 * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile() | 1218 * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile() |
1123 * using pre_data speeds compilation if it's done multiple times. | 1219 * using pre_data speeds compilation if it's done multiple times. |
1124 * Owned by caller, no references are kept when this function returns. | 1220 * Owned by caller, no references are kept when this function returns. |
1125 * \return Compiled script object, bound to the context that was active | 1221 * \return Compiled script object, bound to the context that was active |
1126 * when this function was called. When run it will always use this | 1222 * when this function was called. When run it will always use this |
1127 * context. | 1223 * context. |
1128 */ | 1224 */ |
(...skipping 5044 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6173 delete cached_data; | 6269 delete cached_data; |
6174 } | 6270 } |
6175 | 6271 |
6176 | 6272 |
6177 const ScriptCompiler::CachedData* ScriptCompiler::Source::GetCachedData() | 6273 const ScriptCompiler::CachedData* ScriptCompiler::Source::GetCachedData() |
6178 const { | 6274 const { |
6179 return cached_data; | 6275 return cached_data; |
6180 } | 6276 } |
6181 | 6277 |
6182 | 6278 |
6279 ScriptCompiler::StreamedSource::StreamedSource(ExternalSourceStream* stream) | |
6280 : source_stream(stream), cached_data(NULL), info(NULL) {} | |
6281 | |
6282 | |
6283 const ScriptCompiler::CachedData* | |
6284 ScriptCompiler::StreamedSource::GetCachedData() const { | |
6285 return cached_data; | |
6286 } | |
6287 | |
6288 | |
6183 Handle<Boolean> Boolean::New(Isolate* isolate, bool value) { | 6289 Handle<Boolean> Boolean::New(Isolate* isolate, bool value) { |
6184 return value ? True(isolate) : False(isolate); | 6290 return value ? True(isolate) : False(isolate); |
6185 } | 6291 } |
6186 | 6292 |
6187 | 6293 |
6188 void Template::Set(Isolate* isolate, const char* name, v8::Handle<Data> value) { | 6294 void Template::Set(Isolate* isolate, const char* name, v8::Handle<Data> value) { |
6189 Set(v8::String::NewFromUtf8(isolate, name), value); | 6295 Set(v8::String::NewFromUtf8(isolate, name), value); |
6190 } | 6296 } |
6191 | 6297 |
6192 | 6298 |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6732 */ | 6838 */ |
6733 | 6839 |
6734 | 6840 |
6735 } // namespace v8 | 6841 } // namespace v8 |
6736 | 6842 |
6737 | 6843 |
6738 #undef TYPE_CHECK | 6844 #undef TYPE_CHECK |
6739 | 6845 |
6740 | 6846 |
6741 #endif // V8_H_ | 6847 #endif // V8_H_ |
OLD | NEW |