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

Side by Side Diff: include/v8.h

Issue 186723005: New Compilation API, part 1 (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: . Created 6 years, 9 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
« no previous file with comments | « no previous file | samples/lineprocessor.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 class Integer; 101 class Integer;
102 class Isolate; 102 class Isolate;
103 class Number; 103 class Number;
104 class NumberObject; 104 class NumberObject;
105 class Object; 105 class Object;
106 class ObjectOperationDescriptor; 106 class ObjectOperationDescriptor;
107 class ObjectTemplate; 107 class ObjectTemplate;
108 class Platform; 108 class Platform;
109 class Primitive; 109 class Primitive;
110 class RawOperationDescriptor; 110 class RawOperationDescriptor;
111 class Script;
111 class Signature; 112 class Signature;
112 class StackFrame; 113 class StackFrame;
113 class StackTrace; 114 class StackTrace;
114 class String; 115 class String;
115 class StringObject; 116 class StringObject;
116 class Symbol; 117 class Symbol;
117 class SymbolObject; 118 class SymbolObject;
118 class Private; 119 class Private;
119 class Uint32; 120 class Uint32;
120 class Utils; 121 class Utils;
(...skipping 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after
1139 V8_INLINE Handle<Boolean> ResourceIsSharedCrossOrigin() const; 1140 V8_INLINE Handle<Boolean> ResourceIsSharedCrossOrigin() const;
1140 private: 1141 private:
1141 Handle<Value> resource_name_; 1142 Handle<Value> resource_name_;
1142 Handle<Integer> resource_line_offset_; 1143 Handle<Integer> resource_line_offset_;
1143 Handle<Integer> resource_column_offset_; 1144 Handle<Integer> resource_column_offset_;
1144 Handle<Boolean> resource_is_shared_cross_origin_; 1145 Handle<Boolean> resource_is_shared_cross_origin_;
1145 }; 1146 };
1146 1147
1147 1148
1148 /** 1149 /**
1149 * A compiled JavaScript script. 1150 * A compiled JavaScript script, not yet tied to a Context.
1150 */ 1151 */
1151 class V8_EXPORT Script { 1152 class V8_EXPORT UnboundScript {
1152 public: 1153 public:
1153 /** 1154 /**
1154 * Compiles the specified script (context-independent). 1155 * Binds the script to the currently entered context.
1155 *
1156 * \param source Script source code.
1157 * \param origin Script origin, owned by caller, no references are kept
1158 * when New() returns
1159 * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile()
1160 * using pre_data speeds compilation if it's done multiple times.
1161 * Owned by caller, no references are kept when New() returns.
1162 * \return Compiled script object (context independent; when run it
1163 * will use the currently entered context).
1164 */ 1156 */
1165 static Local<Script> New(Handle<String> source, 1157 Local<Script> BindToCurrentContext();
1166 ScriptOrigin* origin = NULL,
1167 ScriptData* pre_data = NULL);
1168 1158
1169 /**
1170 * Compiles the specified script using the specified file name
1171 * object (typically a string) as the script's origin.
1172 *
1173 * \param source Script source code.
1174 * \param file_name file name object (typically a string) to be used
1175 * as the script's origin.
1176 * \return Compiled script object (context independent; when run it
1177 * will use the currently entered context).
1178 */
1179 static Local<Script> New(Handle<String> source,
1180 Handle<Value> file_name);
1181
1182 /**
1183 * Compiles the specified script (bound to current context).
1184 *
1185 * \param source Script source code.
1186 * \param origin Script origin, owned by caller, no references are kept
1187 * when Compile() returns
1188 * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile()
1189 * using pre_data speeds compilation if it's done multiple times.
1190 * Owned by caller, no references are kept when Compile() returns.
1191 * \return Compiled script object, bound to the context that was active
1192 * when this function was called. When run it will always use this
1193 * context.
1194 */
1195 static Local<Script> Compile(Handle<String> source,
1196 ScriptOrigin* origin = NULL,
1197 ScriptData* pre_data = NULL);
1198
1199 /**
1200 * Compiles the specified script using the specified file name
1201 * object (typically a string) as the script's origin.
1202 *
1203 * \param source Script source code.
1204 * \param file_name File name to use as script's origin
1205 * \return Compiled script object, bound to the context that was active
1206 * when this function was called. When run it will always use this
1207 * context.
1208 */
1209 static Local<Script> Compile(Handle<String> source,
1210 Handle<Value> file_name);
1211
1212 /**
1213 * Runs the script returning the resulting value. If the script is
1214 * context independent (created using ::New) it will be run in the
1215 * currently entered context. If it is context specific (created
1216 * using ::Compile) it will be run in the context in which it was
1217 * compiled.
1218 */
1219 Local<Value> Run();
1220
1221 /**
1222 * Returns the script id.
1223 */
1224 int GetId(); 1159 int GetId();
1225
1226 /**
1227 * Returns the name value of one Script.
1228 */
1229 Handle<Value> GetScriptName(); 1160 Handle<Value> GetScriptName();
1230 1161
1231 /** 1162 /**
1232 * Returns zero based line number of the code_pos location in the script. 1163 * Returns zero based line number of the code_pos location in the script.
1233 * -1 will be returned if no information available. 1164 * -1 will be returned if no information available.
1234 */ 1165 */
1235 int GetLineNumber(int code_pos); 1166 int GetLineNumber(int code_pos);
1236 1167
1237 static const int kNoScriptId = 0; 1168 static const int kNoScriptId = 0;
1238 }; 1169 };
1239 1170
1240 1171
1172 /**
1173 * A compiled JavaScript script, tied to a Context which was active when the
1174 * script was compiled.
1175 */
1176 class V8_EXPORT Script {
1177 public:
1178 /**
1179 * A shorthand for ScriptCompiler::CompileBound().
1180 */
1181 static Local<Script> Compile(Handle<String> source,
1182 ScriptOrigin* origin = NULL);
1183
1184 // To be decprecated, use the Compile above.
1185 static Local<Script> Compile(Handle<String> source,
1186 Handle<String> file_name);
1187
1188 /**
1189 * Runs the script returning the resulting value. It will be run in the
1190 * context in which it was created (ScriptCompiler::CompileBound or
1191 * UnboundScript::BindToGlobalContext()).
1192 */
1193 Local<Value> Run();
1194
1195 /**
1196 * Returns the corresponding context-unbound script.
1197 */
1198 Local<UnboundScript> GetUnboundScript();
1199
1200 // To be deprecated; use GetUnboundScript()->GetId();
1201 int GetId() {
1202 return GetUnboundScript()->GetId();
1203 }
1204
1205 // Use GetUnboundScript()->GetId();
1206 V8_DEPRECATED("Use GetUnboundScript()->GetId()",
1207 Handle<Value> GetScriptName()) {
1208 return GetUnboundScript()->GetScriptName();
1209 }
1210
1211 /**
1212 * Returns zero based line number of the code_pos location in the script.
1213 * -1 will be returned if no information available.
1214 */
1215 V8_DEPRECATED("Use GetUnboundScript()->GetLineNumber()",
1216 int GetLineNumber(int code_pos)) {
1217 return GetUnboundScript()->GetLineNumber(code_pos);
1218 }
1219 };
1220
1221
1222 /**
1223 * For compiling scripts.
1224 */
1225 class V8_EXPORT ScriptCompiler {
1226 public:
1227 /**
1228 * Compilation data that the embedder can cache and pass back to speed up
1229 * future compilations. The data is produced if the CompilerOptions passed to
1230 * the compilation functions in ScriptCompiler contains produce_data_to_cache
1231 * = true. The data to cache can then can be retrieved from
1232 * UnboundScript.
1233 */
1234 struct V8_EXPORT CachedData {
1235 CachedData() : data(NULL), length(0) {}
1236 // Caller keeps the ownership of data and guarantees that the data stays
1237 // alive long enough.
1238 CachedData(const uint8_t* data, int length) : data(data), length(length) {}
1239 // TODO(marja): Async compilation; add constructors which take a callback
1240 // which will be called when V8 no longer needs the data.
1241 const uint8_t* data;
1242 int length;
1243 };
1244
1245 /**
1246 * Source code which can be then compiled to a UnboundScript or
1247 * BoundScript.
1248 */
1249 struct V8_EXPORT Source {
1250 Source(Local<String> source_string, const ScriptOrigin& origin,
1251 const CachedData& cached_data = CachedData());
1252 Source(Local<String> source_string,
1253 const CachedData& cached_data = CachedData());
1254
1255 Local<String> source_string;
1256
1257 // Origin information
1258 Handle<Value> resource_name;
1259 Handle<Integer> resource_line_offset;
1260 Handle<Integer> resource_column_offset;
1261 Handle<Boolean> resource_is_shared_cross_origin;
1262
1263 // Cached data from previous compilation (if any).
1264 CachedData cached_data;
1265 };
1266
1267 enum CompileOptions {
1268 kNoCompileOptions,
1269 kProduceDataToCache = 1 << 0
1270 };
1271
1272 /**
1273 * Compiles the specified script (context-independent).
1274 *
1275 * \param source Script source code.
1276 * \return Compiled script object (context independent; for running it must be
1277 * bound to a context).
1278 */
1279 static Local<UnboundScript> CompileUnbound(
1280 Isolate* isolate, const Source& source,
1281 CompileOptions options = kNoCompileOptions);
1282
1283 /**
1284 * Compiles the specified script (bound to current context).
1285 *
1286 * \param source Script source code.
1287 * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile()
1288 * using pre_data speeds compilation if it's done multiple times.
1289 * Owned by caller, no references are kept when this function returns.
1290 * \return Compiled script object, bound to the context that was active
1291 * when this function was called. When run it will always use this
1292 * context.
1293 */
1294 static Local<Script> Compile(
1295 Isolate* isolate, const Source& source,
1296 CompileOptions options = kNoCompileOptions);
1297 };
1298
1299
1241 /** 1300 /**
1242 * An error message. 1301 * An error message.
1243 */ 1302 */
1244 class V8_EXPORT Message { 1303 class V8_EXPORT Message {
1245 public: 1304 public:
1246 Local<String> Get() const; 1305 Local<String> Get() const;
1247 Local<String> GetSourceLine() const; 1306 Local<String> GetSourceLine() const;
1248 1307
1249 /** 1308 /**
1250 * Returns the resource name for the script from where the function causing 1309 * Returns the resource name for the script from where the function causing
(...skipping 5446 matching lines...) Expand 10 before | Expand all | Expand 10 after
6697 */ 6756 */
6698 6757
6699 6758
6700 } // namespace v8 6759 } // namespace v8
6701 6760
6702 6761
6703 #undef TYPE_CHECK 6762 #undef TYPE_CHECK
6704 6763
6705 6764
6706 #endif // V8_H_ 6765 #endif // V8_H_
OLDNEW
« no previous file with comments | « no previous file | samples/lineprocessor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698