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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 class Isolate; | 119 class Isolate; |
120 class DeclaredAccessorDescriptor; | 120 class DeclaredAccessorDescriptor; |
121 class ObjectOperationDescriptor; | 121 class ObjectOperationDescriptor; |
122 class RawOperationDescriptor; | 122 class RawOperationDescriptor; |
123 class CallHandlerHelper; | 123 class CallHandlerHelper; |
124 class EscapableHandleScope; | 124 class EscapableHandleScope; |
125 template<typename T> class ReturnValue; | 125 template<typename T> class ReturnValue; |
126 | 126 |
127 namespace internal { | 127 namespace internal { |
128 class Arguments; | 128 class Arguments; |
129 class BackgroundParsingTask; | |
130 class CompilationInfo; | |
131 class ExternalStreamingStream; | |
129 class Heap; | 132 class Heap; |
130 class HeapObject; | 133 class HeapObject; |
131 class Isolate; | 134 class Isolate; |
132 class Object; | 135 class Object; |
133 template<typename T> class CustomArguments; | 136 template<typename T> class CustomArguments; |
134 class PropertyCallbackArguments; | 137 class PropertyCallbackArguments; |
135 class FunctionCallbackArguments; | 138 class FunctionCallbackArguments; |
136 class GlobalHandles; | 139 class GlobalHandles; |
137 } | 140 } |
138 | 141 |
(...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1081 Handle<Integer> resource_line_offset; | 1084 Handle<Integer> resource_line_offset; |
1082 Handle<Integer> resource_column_offset; | 1085 Handle<Integer> resource_column_offset; |
1083 Handle<Boolean> resource_is_shared_cross_origin; | 1086 Handle<Boolean> resource_is_shared_cross_origin; |
1084 | 1087 |
1085 // Cached data from previous compilation (if a kConsume*Cache flag is | 1088 // Cached data from previous compilation (if a kConsume*Cache flag is |
1086 // set), or hold newly generated cache data (kProduce*Cache flags) are | 1089 // set), or hold newly generated cache data (kProduce*Cache flags) are |
1087 // set when calling a compile method. | 1090 // set when calling a compile method. |
1088 CachedData* cached_data; | 1091 CachedData* cached_data; |
1089 }; | 1092 }; |
1090 | 1093 |
1094 /** | |
1095 * For streaming incomplete script data to V8. The embedder should implement a | |
1096 * subclass of this class. | |
1097 */ | |
1098 class V8_EXPORT ExternalSourceStream { | |
1099 public: | |
1100 enum Encoding { ONE_BYTE, TWO_BYTE, UTF8, UNKNOWN }; | |
1101 | |
1102 ExternalSourceStream() : encoding(UNKNOWN) {} | |
1103 virtual ~ExternalSourceStream() {} | |
1104 | |
1105 /** | |
1106 * V8 calls this to request the next chunk of data from the embedder. This | |
1107 * function will be called on a background thread, so it's OK to block and | |
1108 * wait for the data, if the embedder doesn't have data yet. Returns the | |
1109 * length of the data returned. The caller takes ownership of the data. | |
1110 */ | |
1111 virtual unsigned GetMoreData(const char** src) = 0; | |
Sven Panne
2014/09/01 09:07:46
I think size_t is more appropriate than unsigned.
marja
2014/09/01 11:58:17
Done.
| |
1112 | |
1113 protected: | |
1114 /** | |
1115 * The embedder should call this as soon as it knows the encoding. It must | |
1116 * be called before the first call to GetMoreData returns. | |
1117 */ | |
1118 void SetEncoding(Encoding e) { encoding = e; } | |
Sven Panne
2014/09/01 09:07:46
What's the rationale behind this two-stage initial
marja
2014/09/01 11:58:17
The original purpose was to allow the embedder pas
| |
1119 | |
1120 private: | |
1121 friend class internal::ExternalStreamingStream; | |
1122 Encoding encoding; | |
1123 }; | |
1124 | |
1125 | |
1126 /** | |
1127 * Source code which can be streamed into V8 in pieces. It will be parsed | |
1128 * while streaming. It can be compiled after the streaming is complete. | |
1129 * StreamedSource must be kept alive while the compilation is ongoing. | |
1130 */ | |
1131 class StreamedSource { | |
1132 public: | |
1133 V8_INLINE explicit StreamedSource(ExternalSourceStream* source_stream); | |
1134 ~StreamedSource(); | |
Sven Panne
2014/09/01 09:07:46
If we don't allow subclassing, we should mark this
marja
2014/09/01 11:58:17
Added V8_FINAL (subclassing this won't make sense;
marja
2014/09/02 12:43:36
Meanwhile, things seem to progress in bleeding edg
| |
1135 | |
1136 // Ownership of the CachedData or its buffers is *not* transferred to the | |
1137 // caller. The CachedData object is alive as long as the StreamedSource | |
1138 // object is alive. | |
1139 V8_INLINE const CachedData* GetCachedData() const; | |
1140 | |
1141 private: | |
1142 friend class ScriptCompiler; | |
1143 friend class internal::BackgroundParsingTask; | |
1144 | |
1145 // Prevent copying. Not implemented. | |
1146 StreamedSource(const StreamedSource&); | |
1147 StreamedSource& operator=(const StreamedSource&); | |
1148 | |
1149 ExternalSourceStream* source_stream; | |
1150 | |
1151 // Cached data generated during compilation (if the generate_cached_data | |
1152 // flag is passed to ScriptCompiler::StartStreamingScript). Streamed scripts | |
1153 // cannot utilize already existing cached data. | |
1154 CachedData* cached_data; | |
1155 | |
1156 internal::CompilationInfo* info; | |
1157 }; | |
1158 | |
1159 /** | |
1160 * A streaming task which the embedder must run on a background thread to | |
1161 * stream scripts into V8. Returned by ScriptCompiler::StartStreamingScript. | |
1162 */ | |
1163 class ScriptStreamingTask { | |
1164 public: | |
1165 virtual ~ScriptStreamingTask() {} | |
1166 virtual void Run() = 0; | |
1167 }; | |
1168 | |
1091 enum CompileOptions { | 1169 enum CompileOptions { |
1092 kNoCompileOptions = 0, | 1170 kNoCompileOptions = 0, |
1093 kProduceParserCache, | 1171 kProduceParserCache, |
1094 kConsumeParserCache, | 1172 kConsumeParserCache, |
1095 kProduceCodeCache, | 1173 kProduceCodeCache, |
1096 kConsumeCodeCache, | 1174 kConsumeCodeCache, |
1097 | 1175 |
1098 // Support the previous API for a transition period. | 1176 // Support the previous API for a transition period. |
1099 kProduceDataToCache | 1177 kProduceDataToCache |
1100 }; | 1178 }; |
1101 | 1179 |
1102 /** | 1180 /** |
1103 * Compiles the specified script (context-independent). | 1181 * Compiles the specified script (context-independent). |
1104 * Cached data as part of the source object can be optionally produced to be | 1182 * Cached data as part of the source object can be optionally produced to be |
1105 * consumed later to speed up compilation of identical source scripts. | 1183 * consumed later to speed up compilation of identical source scripts. |
1106 * | 1184 * |
1107 * Note that when producing cached data, the source must point to NULL for | 1185 * Note that when producing cached data, the source must point to NULL for |
1108 * cached data. When consuming cached data, the cached data must have been | 1186 * cached data. When consuming cached data, the cached data must have been |
1109 * produced by the same version of V8. | 1187 * produced by the same version of V8. |
1110 * | 1188 * |
1111 * \param source Script source code. | 1189 * \param source Script source code. |
1112 * \return Compiled script object (context independent; for running it must be | 1190 * \return Compiled script object (context independent; for running it must be |
1113 * bound to a context). | 1191 * bound to a context). |
1114 */ | 1192 */ |
1115 static Local<UnboundScript> CompileUnbound( | 1193 static Local<UnboundScript> CompileUnbound( |
1116 Isolate* isolate, Source* source, | 1194 Isolate* isolate, Source* source, |
1117 CompileOptions options = kNoCompileOptions); | 1195 CompileOptions options = kNoCompileOptions); |
1118 | 1196 |
1119 /** | 1197 /** |
1198 * Returns a task which streams script data into V8, or NULL if the script | |
1199 * cannot be streamed. The user is responsible of running the task on a | |
1200 * background thread and deleting it. When ran, the task starts parsing the | |
1201 * script, and it will request data from the StreamedSource as needed. When | |
1202 * ScriptStreamingTask::Run exits, all data has been streamed and the script | |
1203 * can be compiled (see Compile below). | |
1204 * | |
1205 * This API allows to start the streaming with as little data as possible, and | |
1206 * the remaining data (for example, the ScriptOrigin) is passed to Compile. | |
1207 */ | |
1208 static ScriptStreamingTask* StartStreamingScript( | |
Sven Panne
2014/09/01 09:07:46
It might be nice to move this function and the one
marja
2014/09/01 11:58:17
The other compile functions are below, as static f
| |
1209 Isolate* isolate, StreamedSource* source, | |
1210 CompileOptions options = kNoCompileOptions); | |
1211 | |
1212 /** | |
1213 * Compiles a streamed script (bound to current context). | |
1214 * | |
1215 * This can only be called after the streaming has finished (the background | |
1216 * task has been run and completed). V8 doesn't construct the source string | |
1217 * during streaming, so the embedder needs to pass the full source here. | |
1218 */ | |
1219 static Local<Script> Compile(Isolate* isolate, StreamedSource* source, | |
1220 Handle<String> full_source_string, | |
1221 const ScriptOrigin& origin); | |
1222 | |
1223 /** | |
1120 * Compiles the specified script (bound to current context). | 1224 * Compiles the specified script (bound to current context). |
1121 * | 1225 * |
1122 * \param source Script source code. | 1226 * \param source Script source code. |
1123 * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile() | 1227 * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile() |
1124 * using pre_data speeds compilation if it's done multiple times. | 1228 * using pre_data speeds compilation if it's done multiple times. |
1125 * Owned by caller, no references are kept when this function returns. | 1229 * Owned by caller, no references are kept when this function returns. |
1126 * \return Compiled script object, bound to the context that was active | 1230 * \return Compiled script object, bound to the context that was active |
1127 * when this function was called. When run it will always use this | 1231 * when this function was called. When run it will always use this |
1128 * context. | 1232 * context. |
1129 */ | 1233 */ |
(...skipping 5125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6255 delete cached_data; | 6359 delete cached_data; |
6256 } | 6360 } |
6257 | 6361 |
6258 | 6362 |
6259 const ScriptCompiler::CachedData* ScriptCompiler::Source::GetCachedData() | 6363 const ScriptCompiler::CachedData* ScriptCompiler::Source::GetCachedData() |
6260 const { | 6364 const { |
6261 return cached_data; | 6365 return cached_data; |
6262 } | 6366 } |
6263 | 6367 |
6264 | 6368 |
6369 ScriptCompiler::StreamedSource::StreamedSource(ExternalSourceStream* stream) | |
6370 : source_stream(stream), cached_data(NULL), info(NULL) {} | |
6371 | |
6372 | |
6373 const ScriptCompiler::CachedData* | |
6374 ScriptCompiler::StreamedSource::GetCachedData() const { | |
6375 return cached_data; | |
6376 } | |
6377 | |
6378 | |
6265 Handle<Boolean> Boolean::New(Isolate* isolate, bool value) { | 6379 Handle<Boolean> Boolean::New(Isolate* isolate, bool value) { |
6266 return value ? True(isolate) : False(isolate); | 6380 return value ? True(isolate) : False(isolate); |
6267 } | 6381 } |
6268 | 6382 |
6269 | 6383 |
6270 void Template::Set(Isolate* isolate, const char* name, v8::Handle<Data> value) { | 6384 void Template::Set(Isolate* isolate, const char* name, v8::Handle<Data> value) { |
6271 Set(v8::String::NewFromUtf8(isolate, name), value); | 6385 Set(v8::String::NewFromUtf8(isolate, name), value); |
6272 } | 6386 } |
6273 | 6387 |
6274 | 6388 |
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6822 */ | 6936 */ |
6823 | 6937 |
6824 | 6938 |
6825 } // namespace v8 | 6939 } // namespace v8 |
6826 | 6940 |
6827 | 6941 |
6828 #undef TYPE_CHECK | 6942 #undef TYPE_CHECK |
6829 | 6943 |
6830 | 6944 |
6831 #endif // V8_H_ | 6945 #endif // V8_H_ |
OLD | NEW |