Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(788)

Side by Side Diff: include/v8.h

Issue 366153002: Add script streaming API (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: cleanup Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 ExternalStreamingStream;
129 class Heap; 131 class Heap;
130 class HeapObject; 132 class HeapObject;
131 class Isolate; 133 class Isolate;
132 class Object; 134 class Object;
135 class StreamingData;
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
139 142
140 /** 143 /**
141 * General purpose unique identifier. 144 * General purpose unique identifier.
142 */ 145 */
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 };
1101
1102 ExternalSourceStream(Encoding encoding) : encoding(encoding) {}
jochen (gone - plz use gerrit) 2014/09/08 11:27:06 explicit
marja 2014/09/08 16:14:46 (This was removed)
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 * When streaming UTF-8 data, V8 handles multi-byte characters split between
1112 * two data chunks, but doesn't handle multi-byte characters split between
1113 * more than two data chunks. The embedder can avoid this problem by always
1114 * returning at least 4 bytes of data.
1115 */
1116 virtual size_t GetMoreData(const uint8_t** src) = 0;
jochen (gone - plz use gerrit) 2014/09/08 11:27:06 that's kinda odd, a pure virtual interface shouldn
marja 2014/09/08 16:14:47 Done.
1117
1118 private:
1119 friend class internal::ExternalStreamingStream;
1120 const Encoding encoding;
jochen (gone - plz use gerrit) 2014/09/08 11:27:06 or friends, or data members it seems like all thi
marja 2014/09/08 16:14:47 Done.
1121 };
1122
1123
1124 /**
1125 * Source code which can be streamed into V8 in pieces. It will be parsed
1126 * while streaming. It can be compiled after the streaming is complete.
1127 * StreamedSource must be kept alive while the compilation is ongoing.
1128 */
1129 class StreamedSource {
1130 public:
1131 V8_INLINE explicit StreamedSource(ExternalSourceStream* source_stream);
1132 ~StreamedSource();
1133
1134 // Ownership of the CachedData or its buffers is *not* transferred to the
1135 // caller. The CachedData object is alive as long as the StreamedSource
1136 // object is alive.
1137 V8_INLINE const CachedData* GetCachedData() const;
1138
1139 private:
1140 friend class ScriptCompiler;
1141 friend class internal::BackgroundParsingTask;
jochen (gone - plz use gerrit) 2014/09/08 11:27:06 can we do without friends here?
marja 2014/09/08 16:14:47 Added a private implementation and an accessor to
1142
1143 // Prevent copying. Not implemented.
1144 StreamedSource(const StreamedSource&);
1145 StreamedSource& operator=(const StreamedSource&);
1146
1147 ExternalSourceStream* source_stream;
jochen (gone - plz use gerrit) 2014/09/08 11:27:06 members should end in _
marja 2014/09/08 16:14:46 These are now in an internal struct, so not ending
1148
1149 // Cached data generated during compilation (if the generate_cached_data
1150 // flag is passed to ScriptCompiler::StartStreamingScript). Streamed scripts
1151 // cannot utilize already existing cached data.
1152 CachedData* cached_data;
1153
1154 internal::StreamingData* streaming_data;
1155 };
1156
1157 /**
1158 * A streaming task which the embedder must run on a background thread to
1159 * stream scripts into V8. Returned by ScriptCompiler::StartStreamingScript.
1160 */
1161 class ScriptStreamingTask {
1162 public:
1163 virtual ~ScriptStreamingTask() {}
1164 virtual void Run() = 0;
1165 };
1166
1091 enum CompileOptions { 1167 enum CompileOptions {
1092 kNoCompileOptions = 0, 1168 kNoCompileOptions = 0,
1093 kProduceParserCache, 1169 kProduceParserCache,
1094 kConsumeParserCache, 1170 kConsumeParserCache,
1095 kProduceCodeCache, 1171 kProduceCodeCache,
1096 kConsumeCodeCache, 1172 kConsumeCodeCache,
1097 1173
1098 // Support the previous API for a transition period. 1174 // Support the previous API for a transition period.
1099 kProduceDataToCache 1175 kProduceDataToCache
1100 }; 1176 };
(...skipping 22 matching lines...) Expand all
1123 * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile() 1199 * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile()
1124 * using pre_data speeds compilation if it's done multiple times. 1200 * using pre_data speeds compilation if it's done multiple times.
1125 * Owned by caller, no references are kept when this function returns. 1201 * Owned by caller, no references are kept when this function returns.
1126 * \return Compiled script object, bound to the context that was active 1202 * \return Compiled script object, bound to the context that was active
1127 * when this function was called. When run it will always use this 1203 * when this function was called. When run it will always use this
1128 * context. 1204 * context.
1129 */ 1205 */
1130 static Local<Script> Compile( 1206 static Local<Script> Compile(
1131 Isolate* isolate, Source* source, 1207 Isolate* isolate, Source* source,
1132 CompileOptions options = kNoCompileOptions); 1208 CompileOptions options = kNoCompileOptions);
1209
1210 /**
1211 * Returns a task which streams script data into V8, or NULL if the script
1212 * cannot be streamed. The user is responsible for running the task on a
1213 * background thread and deleting it. When ran, the task starts parsing the
1214 * script, and it will request data from the StreamedSource as needed. When
1215 * ScriptStreamingTask::Run exits, all data has been streamed and the script
1216 * can be compiled (see Compile below).
1217 *
1218 * This API allows to start the streaming with as little data as possible, and
1219 * the remaining data (for example, the ScriptOrigin) is passed to Compile.
1220 */
1221 static ScriptStreamingTask* StartStreamingScript(
1222 Isolate* isolate, StreamedSource* source,
1223 CompileOptions options = kNoCompileOptions);
1224
1225 /**
1226 * Compiles a streamed script (bound to current context).
1227 *
1228 * This can only be called after the streaming has finished (the background
1229 * task has been run and completed). V8 doesn't construct the source string
1230 * during streaming, so the embedder needs to pass the full source here.
1231 */
1232 static Local<Script> Compile(Isolate* isolate, StreamedSource* source,
1233 Handle<String> full_source_string,
1234 const ScriptOrigin& origin);
1133 }; 1235 };
1134 1236
1135 1237
1136 /** 1238 /**
1137 * An error message. 1239 * An error message.
1138 */ 1240 */
1139 class V8_EXPORT Message { 1241 class V8_EXPORT Message {
1140 public: 1242 public:
1141 Local<String> Get() const; 1243 Local<String> Get() const;
1142 Local<String> GetSourceLine() const; 1244 Local<String> GetSourceLine() const;
(...skipping 5114 matching lines...) Expand 10 before | Expand all | Expand 10 after
6257 delete cached_data; 6359 delete cached_data;
6258 } 6360 }
6259 6361
6260 6362
6261 const ScriptCompiler::CachedData* ScriptCompiler::Source::GetCachedData() 6363 const ScriptCompiler::CachedData* ScriptCompiler::Source::GetCachedData()
6262 const { 6364 const {
6263 return cached_data; 6365 return cached_data;
6264 } 6366 }
6265 6367
6266 6368
6369 ScriptCompiler::StreamedSource::StreamedSource(ExternalSourceStream* stream)
6370 : source_stream(stream), cached_data(NULL), streaming_data(NULL) {}
6371
6372
6373 const ScriptCompiler::CachedData*
6374 ScriptCompiler::StreamedSource::GetCachedData() const {
6375 return cached_data;
6376 }
6377
6378
6267 Handle<Boolean> Boolean::New(Isolate* isolate, bool value) { 6379 Handle<Boolean> Boolean::New(Isolate* isolate, bool value) {
6268 return value ? True(isolate) : False(isolate); 6380 return value ? True(isolate) : False(isolate);
6269 } 6381 }
6270 6382
6271 6383
6272 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) {
6273 Set(v8::String::NewFromUtf8(isolate, name), value); 6385 Set(v8::String::NewFromUtf8(isolate, name), value);
6274 } 6386 }
6275 6387
6276 6388
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
6824 */ 6936 */
6825 6937
6826 6938
6827 } // namespace v8 6939 } // namespace v8
6828 6940
6829 6941
6830 #undef TYPE_CHECK 6942 #undef TYPE_CHECK
6831 6943
6832 6944
6833 #endif // V8_H_ 6945 #endif // V8_H_
OLDNEW
« no previous file with comments | « BUILD.gn ('k') | src/api.cc » ('j') | src/background-parsing-task.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698