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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | samples/lineprocessor.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index 9bda3dc9faa7bfa79190c1483345d93057120349..5bc9bf827ce0d733cc617f946dc6b6d7d5fdb2af 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -108,6 +108,7 @@ class ObjectTemplate;
class Platform;
class Primitive;
class RawOperationDescriptor;
+class Script;
class Signature;
class StackFrame;
class StackTrace;
@@ -1146,95 +1147,153 @@ class ScriptOrigin {
/**
- * A compiled JavaScript script.
+ * A compiled JavaScript script, not yet tied to a Context.
*/
-class V8_EXPORT Script {
+class V8_EXPORT UnboundScript {
public:
/**
- * Compiles the specified script (context-independent).
- *
- * \param source Script source code.
- * \param origin Script origin, owned by caller, no references are kept
- * when New() returns
- * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile()
- * using pre_data speeds compilation if it's done multiple times.
- * Owned by caller, no references are kept when New() returns.
- * \return Compiled script object (context independent; when run it
- * will use the currently entered context).
+ * Binds the script to the currently entered context.
*/
- static Local<Script> New(Handle<String> source,
- ScriptOrigin* origin = NULL,
- ScriptData* pre_data = NULL);
+ Local<Script> BindToCurrentContext();
+
+ int GetId();
+ Handle<Value> GetScriptName();
/**
- * Compiles the specified script using the specified file name
- * object (typically a string) as the script's origin.
- *
- * \param source Script source code.
- * \param file_name file name object (typically a string) to be used
- * as the script's origin.
- * \return Compiled script object (context independent; when run it
- * will use the currently entered context).
+ * Returns zero based line number of the code_pos location in the script.
+ * -1 will be returned if no information available.
*/
- static Local<Script> New(Handle<String> source,
- Handle<Value> file_name);
+ int GetLineNumber(int code_pos);
+
+ static const int kNoScriptId = 0;
+};
+
+/**
+ * A compiled JavaScript script, tied to a Context which was active when the
+ * script was compiled.
+ */
+class V8_EXPORT Script {
+ public:
/**
- * Compiles the specified script (bound to current context).
- *
- * \param source Script source code.
- * \param origin Script origin, owned by caller, no references are kept
- * when Compile() returns
- * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile()
- * using pre_data speeds compilation if it's done multiple times.
- * Owned by caller, no references are kept when Compile() returns.
- * \return Compiled script object, bound to the context that was active
- * when this function was called. When run it will always use this
- * context.
+ * A shorthand for ScriptCompiler::CompileBound().
*/
static Local<Script> Compile(Handle<String> source,
- ScriptOrigin* origin = NULL,
- ScriptData* pre_data = NULL);
+ ScriptOrigin* origin = NULL);
- /**
- * Compiles the specified script using the specified file name
- * object (typically a string) as the script's origin.
- *
- * \param source Script source code.
- * \param file_name File name to use as script's origin
- * \return Compiled script object, bound to the context that was active
- * when this function was called. When run it will always use this
- * context.
- */
+ // To be decprecated, use the Compile above.
static Local<Script> Compile(Handle<String> source,
- Handle<Value> file_name);
+ Handle<String> file_name);
/**
- * Runs the script returning the resulting value. If the script is
- * context independent (created using ::New) it will be run in the
- * currently entered context. If it is context specific (created
- * using ::Compile) it will be run in the context in which it was
- * compiled.
+ * Runs the script returning the resulting value. It will be run in the
+ * context in which it was created (ScriptCompiler::CompileBound or
+ * UnboundScript::BindToGlobalContext()).
*/
Local<Value> Run();
/**
- * Returns the script id.
+ * Returns the corresponding context-unbound script.
*/
- int GetId();
+ Local<UnboundScript> GetUnboundScript();
- /**
- * Returns the name value of one Script.
- */
- Handle<Value> GetScriptName();
+ // To be deprecated; use GetUnboundScript()->GetId();
+ int GetId() {
+ return GetUnboundScript()->GetId();
+ }
+
+ // Use GetUnboundScript()->GetId();
+ V8_DEPRECATED("Use GetUnboundScript()->GetId()",
+ Handle<Value> GetScriptName()) {
+ return GetUnboundScript()->GetScriptName();
+ }
/**
* Returns zero based line number of the code_pos location in the script.
* -1 will be returned if no information available.
*/
- int GetLineNumber(int code_pos);
+ V8_DEPRECATED("Use GetUnboundScript()->GetLineNumber()",
+ int GetLineNumber(int code_pos)) {
+ return GetUnboundScript()->GetLineNumber(code_pos);
+ }
+};
- static const int kNoScriptId = 0;
+
+/**
+ * For compiling scripts.
+ */
+class V8_EXPORT ScriptCompiler {
+ public:
+ /**
+ * Compilation data that the embedder can cache and pass back to speed up
+ * future compilations. The data is produced if the CompilerOptions passed to
+ * the compilation functions in ScriptCompiler contains produce_data_to_cache
+ * = true. The data to cache can then can be retrieved from
+ * UnboundScript.
+ */
+ struct V8_EXPORT CachedData {
+ CachedData() : data(NULL), length(0) {}
+ // Caller keeps the ownership of data and guarantees that the data stays
+ // alive long enough.
+ CachedData(const uint8_t* data, int length) : data(data), length(length) {}
+ // TODO(marja): Async compilation; add constructors which take a callback
+ // which will be called when V8 no longer needs the data.
+ const uint8_t* data;
+ int length;
+ };
+
+ /**
+ * Source code which can be then compiled to a UnboundScript or
+ * BoundScript.
+ */
+ struct V8_EXPORT Source {
+ Source(Local<String> source_string, const ScriptOrigin& origin,
+ const CachedData& cached_data = CachedData());
+ Source(Local<String> source_string,
+ const CachedData& cached_data = CachedData());
+
+ Local<String> source_string;
+
+ // Origin information
+ Handle<Value> resource_name;
+ Handle<Integer> resource_line_offset;
+ Handle<Integer> resource_column_offset;
+ Handle<Boolean> resource_is_shared_cross_origin;
+
+ // Cached data from previous compilation (if any).
+ CachedData cached_data;
+ };
+
+ enum CompileOptions {
+ kNoCompileOptions,
+ kProduceDataToCache = 1 << 0
+ };
+
+ /**
+ * Compiles the specified script (context-independent).
+ *
+ * \param source Script source code.
+ * \return Compiled script object (context independent; for running it must be
+ * bound to a context).
+ */
+ static Local<UnboundScript> CompileUnbound(
+ Isolate* isolate, const Source& source,
+ CompileOptions options = kNoCompileOptions);
+
+ /**
+ * Compiles the specified script (bound to current context).
+ *
+ * \param source Script source code.
+ * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile()
+ * using pre_data speeds compilation if it's done multiple times.
+ * Owned by caller, no references are kept when this function returns.
+ * \return Compiled script object, bound to the context that was active
+ * when this function was called. When run it will always use this
+ * context.
+ */
+ static Local<Script> Compile(
+ Isolate* isolate, const Source& source,
+ CompileOptions options = kNoCompileOptions);
};
« 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