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

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') | src/api.h » ('J')
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 c7364b43f64a030a3c4468de3d343cfa5e0002db..45dd5f8382260b1d72f4aa4daa2e64f8729ba655 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;
@@ -999,99 +1000,156 @@ class ScriptOrigin {
/**
- * A compiled JavaScript script.
+ * A compiled JavaScript script, not yet tied to a Context.
*/
-class V8_EXPORT Script {
+class V8_EXPORT ContextUnboundScript {
dcarney 2014/03/10 15:50:35 maybe just UnboundScript?
marja 2014/03/10 17:58:06 Done.
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> BindToGlobalContext();
dcarney 2014/03/10 15:50:35 should be bindtocurrentcontext
marja 2014/03/10 17:58:06 Done.
/**
- * 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).
+ * Binds the script to the currently entered context and runs it.
*/
- static Local<Script> New(Handle<String> source,
- Handle<Value> file_name);
+ Local<Value> Run();
dcarney 2014/03/10 15:50:35 i don't think this should be here
marja 2014/03/10 17:58:06 This helper was doing BindToCurrentContext()->Run(
+
+ int GetId();
+ Handle<Value> GetScriptName();
/**
- * 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.
+ * Returns zero based line number of the code_pos location in the script.
+ * -1 will be returned if no information available.
*/
- static Local<Script> Compile(Handle<String> source,
- ScriptOrigin* origin = NULL,
- ScriptData* pre_data = NULL);
+ 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 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.
+ * A shorthand for ScriptCompiler::CompileContextBound().
*/
static Local<Script> Compile(Handle<String> source,
- Handle<Value> file_name);
+ ScriptOrigin* origin = NULL);
/**
- * 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::CompileContextBound or
+ * ContextUnboundScript::BindToGlobalContext()).
*/
Local<Value> Run();
/**
- * Returns the script id.
+ * Returns the corresponding context-unbound script.
*/
- int GetId();
+ Local<ContextUnboundScript> GetUnboundScript();
- /**
- * Returns the name value of one Script.
- */
- Handle<Value> GetScriptName();
+ int GetId() {
dcarney 2014/03/10 15:50:35 can we deprecate any of these?
marja 2014/03/10 17:58:06 GetId is the only one used by chromium -> deprecat
+ return 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);
+ 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
+ * ContextUnboundScript.
+ */
+ 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 ContextUnboundScript or
+ * ContextBoundScript.
+ */
+ 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;
+ };
+
+ struct V8_EXPORT CompileOptions {
dcarney 2014/03/10 15:50:35 an enum should be enough here, with kNoCompileOpti
marja 2014/03/10 17:58:06 Done.
+ CompileOptions() : produce_data_to_cache(false) {}
+ bool produce_data_to_cache;
+ };
+
+ /**
+ * 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<ContextUnboundScript> CompileContextUnbound(
+ Isolate* isolate, const Source& source,
+ CompileOptions options = CompileOptions());
+
+ /**
+ * 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> CompileContextBound(
+ Isolate* isolate, const Source& source,
+ CompileOptions options = CompileOptions());
+};
+
+
+/**
* An error message.
*/
class V8_EXPORT Message {
« no previous file with comments | « no previous file | samples/lineprocessor.cc » ('j') | src/api.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698