OLD | NEW |
---|---|
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 Loading... | |
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 871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
992 V8_INLINE Handle<Boolean> ResourceIsSharedCrossOrigin() const; | 993 V8_INLINE Handle<Boolean> ResourceIsSharedCrossOrigin() const; |
993 private: | 994 private: |
994 Handle<Value> resource_name_; | 995 Handle<Value> resource_name_; |
995 Handle<Integer> resource_line_offset_; | 996 Handle<Integer> resource_line_offset_; |
996 Handle<Integer> resource_column_offset_; | 997 Handle<Integer> resource_column_offset_; |
997 Handle<Boolean> resource_is_shared_cross_origin_; | 998 Handle<Boolean> resource_is_shared_cross_origin_; |
998 }; | 999 }; |
999 | 1000 |
1000 | 1001 |
1001 /** | 1002 /** |
1002 * A compiled JavaScript script. | 1003 * A compiled JavaScript script, not yet tied to a Context. |
1003 */ | 1004 */ |
1004 class V8_EXPORT Script { | 1005 class V8_EXPORT ContextUnboundScript { |
dcarney
2014/03/10 15:50:35
maybe just UnboundScript?
marja
2014/03/10 17:58:06
Done.
| |
1005 public: | 1006 public: |
1006 /** | 1007 /** |
1007 * Compiles the specified script (context-independent). | 1008 * Binds the script to the currently entered context. |
1008 * | |
1009 * \param source Script source code. | |
1010 * \param origin Script origin, owned by caller, no references are kept | |
1011 * when New() returns | |
1012 * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile() | |
1013 * using pre_data speeds compilation if it's done multiple times. | |
1014 * Owned by caller, no references are kept when New() returns. | |
1015 * \return Compiled script object (context independent; when run it | |
1016 * will use the currently entered context). | |
1017 */ | 1009 */ |
1018 static Local<Script> New(Handle<String> source, | 1010 Local<Script> BindToGlobalContext(); |
dcarney
2014/03/10 15:50:35
should be bindtocurrentcontext
marja
2014/03/10 17:58:06
Done.
| |
1019 ScriptOrigin* origin = NULL, | |
1020 ScriptData* pre_data = NULL); | |
1021 | 1011 |
1022 /** | 1012 /** |
1023 * Compiles the specified script using the specified file name | 1013 * Binds the script to the currently entered context and runs it. |
1024 * object (typically a string) as the script's origin. | |
1025 * | |
1026 * \param source Script source code. | |
1027 * \param file_name file name object (typically a string) to be used | |
1028 * as the script's origin. | |
1029 * \return Compiled script object (context independent; when run it | |
1030 * will use the currently entered context). | |
1031 */ | |
1032 static Local<Script> New(Handle<String> source, | |
1033 Handle<Value> file_name); | |
1034 | |
1035 /** | |
1036 * Compiles the specified script (bound to current context). | |
1037 * | |
1038 * \param source Script source code. | |
1039 * \param origin Script origin, owned by caller, no references are kept | |
1040 * when Compile() returns | |
1041 * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile() | |
1042 * using pre_data speeds compilation if it's done multiple times. | |
1043 * Owned by caller, no references are kept when Compile() returns. | |
1044 * \return Compiled script object, bound to the context that was active | |
1045 * when this function was called. When run it will always use this | |
1046 * context. | |
1047 */ | |
1048 static Local<Script> Compile(Handle<String> source, | |
1049 ScriptOrigin* origin = NULL, | |
1050 ScriptData* pre_data = NULL); | |
1051 | |
1052 /** | |
1053 * Compiles the specified script using the specified file name | |
1054 * object (typically a string) as the script's origin. | |
1055 * | |
1056 * \param source Script source code. | |
1057 * \param file_name File name to use as script's origin | |
1058 * \return Compiled script object, bound to the context that was active | |
1059 * when this function was called. When run it will always use this | |
1060 * context. | |
1061 */ | |
1062 static Local<Script> Compile(Handle<String> source, | |
1063 Handle<Value> file_name); | |
1064 | |
1065 /** | |
1066 * Runs the script returning the resulting value. If the script is | |
1067 * context independent (created using ::New) it will be run in the | |
1068 * currently entered context. If it is context specific (created | |
1069 * using ::Compile) it will be run in the context in which it was | |
1070 * compiled. | |
1071 */ | 1014 */ |
1072 Local<Value> Run(); | 1015 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(
| |
1073 | 1016 |
1074 /** | |
1075 * Returns the script id. | |
1076 */ | |
1077 int GetId(); | 1017 int GetId(); |
1078 | |
1079 /** | |
1080 * Returns the name value of one Script. | |
1081 */ | |
1082 Handle<Value> GetScriptName(); | 1018 Handle<Value> GetScriptName(); |
1083 | 1019 |
1084 /** | 1020 /** |
1085 * Returns zero based line number of the code_pos location in the script. | 1021 * Returns zero based line number of the code_pos location in the script. |
1086 * -1 will be returned if no information available. | 1022 * -1 will be returned if no information available. |
1087 */ | 1023 */ |
1088 int GetLineNumber(int code_pos); | 1024 int GetLineNumber(int code_pos); |
1089 | 1025 |
1090 static const int kNoScriptId = 0; | 1026 static const int kNoScriptId = 0; |
1091 }; | 1027 }; |
1092 | 1028 |
1093 | 1029 |
1094 /** | 1030 /** |
1031 * A compiled JavaScript script, tied to a Context which was active when the | |
1032 * script was compiled. | |
1033 */ | |
1034 class V8_EXPORT Script { | |
1035 public: | |
1036 /** | |
1037 * A shorthand for ScriptCompiler::CompileContextBound(). | |
1038 */ | |
1039 static Local<Script> Compile(Handle<String> source, | |
1040 ScriptOrigin* origin = NULL); | |
1041 | |
1042 /** | |
1043 * Runs the script returning the resulting value. It will be run in the | |
1044 * context in which it was created (ScriptCompiler::CompileContextBound or | |
1045 * ContextUnboundScript::BindToGlobalContext()). | |
1046 */ | |
1047 Local<Value> Run(); | |
1048 | |
1049 /** | |
1050 * Returns the corresponding context-unbound script. | |
1051 */ | |
1052 Local<ContextUnboundScript> GetUnboundScript(); | |
1053 | |
1054 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
| |
1055 return GetUnboundScript()->GetId(); | |
1056 } | |
1057 | |
1058 Handle<Value> GetScriptName() { | |
1059 return GetUnboundScript()->GetScriptName(); | |
1060 } | |
1061 | |
1062 /** | |
1063 * Returns zero based line number of the code_pos location in the script. | |
1064 * -1 will be returned if no information available. | |
1065 */ | |
1066 int GetLineNumber(int code_pos) { | |
1067 return GetUnboundScript()->GetLineNumber(code_pos); | |
1068 } | |
1069 | |
1070 static const int kNoScriptId = 0; | |
1071 }; | |
1072 | |
1073 | |
1074 /** | |
1075 * For compiling scripts. | |
1076 */ | |
1077 class V8_EXPORT ScriptCompiler { | |
1078 public: | |
1079 /** | |
1080 * Compilation data that the embedder can cache and pass back to speed up | |
1081 * future compilations. The data is produced if the CompilerOptions passed to | |
1082 * the compilation functions in ScriptCompiler contains produce_data_to_cache | |
1083 * = true. The data to cache can then can be retrieved from | |
1084 * ContextUnboundScript. | |
1085 */ | |
1086 struct V8_EXPORT CachedData { | |
1087 CachedData() : data(NULL), length(0) {} | |
1088 // Caller keeps the ownership of data and guarantees that the data stays | |
1089 // alive long enough. | |
1090 CachedData(const uint8_t* data, int length) : data(data), length(length) {} | |
1091 // TODO(marja): Async compilation; add constructors which take a callback | |
1092 // which will be called when V8 no longer needs the data. | |
1093 const uint8_t* data; | |
1094 int length; | |
1095 }; | |
1096 | |
1097 /** | |
1098 * Source code which can be then compiled to a ContextUnboundScript or | |
1099 * ContextBoundScript. | |
1100 */ | |
1101 struct V8_EXPORT Source { | |
1102 Source(Local<String> source_string, const ScriptOrigin& origin, | |
1103 const CachedData& cached_data = CachedData()); | |
1104 Source(Local<String> source_string, | |
1105 const CachedData& cached_data = CachedData()); | |
1106 | |
1107 Local<String> source_string; | |
1108 | |
1109 // Origin information | |
1110 Handle<Value> resource_name; | |
1111 Handle<Integer> resource_line_offset; | |
1112 Handle<Integer> resource_column_offset; | |
1113 Handle<Boolean> resource_is_shared_cross_origin; | |
1114 | |
1115 // Cached data from previous compilation (if any). | |
1116 CachedData cached_data; | |
1117 }; | |
1118 | |
1119 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.
| |
1120 CompileOptions() : produce_data_to_cache(false) {} | |
1121 bool produce_data_to_cache; | |
1122 }; | |
1123 | |
1124 /** | |
1125 * Compiles the specified script (context-independent). | |
1126 * | |
1127 * \param source Script source code. | |
1128 * \return Compiled script object (context independent; for running it must be | |
1129 * bound to a context). | |
1130 */ | |
1131 static Local<ContextUnboundScript> CompileContextUnbound( | |
1132 Isolate* isolate, const Source& source, | |
1133 CompileOptions options = CompileOptions()); | |
1134 | |
1135 /** | |
1136 * Compiles the specified script (bound to current context). | |
1137 * | |
1138 * \param source Script source code. | |
1139 * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile() | |
1140 * using pre_data speeds compilation if it's done multiple times. | |
1141 * Owned by caller, no references are kept when this function returns. | |
1142 * \return Compiled script object, bound to the context that was active | |
1143 * when this function was called. When run it will always use this | |
1144 * context. | |
1145 */ | |
1146 static Local<Script> CompileContextBound( | |
1147 Isolate* isolate, const Source& source, | |
1148 CompileOptions options = CompileOptions()); | |
1149 }; | |
1150 | |
1151 | |
1152 /** | |
1095 * An error message. | 1153 * An error message. |
1096 */ | 1154 */ |
1097 class V8_EXPORT Message { | 1155 class V8_EXPORT Message { |
1098 public: | 1156 public: |
1099 Local<String> Get() const; | 1157 Local<String> Get() const; |
1100 Local<String> GetSourceLine() const; | 1158 Local<String> GetSourceLine() const; |
1101 | 1159 |
1102 /** | 1160 /** |
1103 * Returns the resource name for the script from where the function causing | 1161 * Returns the resource name for the script from where the function causing |
1104 * the error originates. | 1162 * the error originates. |
(...skipping 5352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6457 */ | 6515 */ |
6458 | 6516 |
6459 | 6517 |
6460 } // namespace v8 | 6518 } // namespace v8 |
6461 | 6519 |
6462 | 6520 |
6463 #undef TYPE_CHECK | 6521 #undef TYPE_CHECK |
6464 | 6522 |
6465 | 6523 |
6466 #endif // V8_H_ | 6524 #endif // V8_H_ |
OLD | NEW |