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 1079 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1090 class V8_EXPORT ScriptCompiler { | 1090 class V8_EXPORT ScriptCompiler { |
1091 public: | 1091 public: |
1092 /** | 1092 /** |
1093 * Compilation data that the embedder can cache and pass back to speed up | 1093 * Compilation data that the embedder can cache and pass back to speed up |
1094 * future compilations. The data is produced if the CompilerOptions passed to | 1094 * future compilations. The data is produced if the CompilerOptions passed to |
1095 * the compilation functions in ScriptCompiler contains produce_data_to_cache | 1095 * the compilation functions in ScriptCompiler contains produce_data_to_cache |
1096 * = true. The data to cache can then can be retrieved from | 1096 * = true. The data to cache can then can be retrieved from |
1097 * UnboundScript. | 1097 * UnboundScript. |
1098 */ | 1098 */ |
1099 struct V8_EXPORT CachedData { | 1099 struct V8_EXPORT CachedData { |
1100 CachedData() : data(NULL), length(0) {} | 1100 CachedData() : data(NULL), length(0), owns_buffer(false) {} |
1101 // Caller keeps the ownership of data and guarantees that the data stays | 1101 // Caller keeps the ownership of data and guarantees that the data stays |
1102 // alive long enough. | 1102 // alive long enough. |
1103 CachedData(const uint8_t* data, int length) : data(data), length(length) {} | 1103 CachedData(const uint8_t* data, int length, bool owns_buffer = false); |
dcarney
2014/03/18 14:34:44
make enum
marja
2014/03/18 16:11:05
Done.
| |
1104 ~CachedData(); | |
1104 // TODO(marja): Async compilation; add constructors which take a callback | 1105 // TODO(marja): Async compilation; add constructors which take a callback |
1105 // which will be called when V8 no longer needs the data. | 1106 // which will be called when V8 no longer needs the data. |
1106 const uint8_t* data; | 1107 const uint8_t* data; |
1107 int length; | 1108 int length; |
1109 bool owns_buffer; | |
1110 | |
1111 private: | |
1112 // Prevent copying. Not implemented. | |
1113 CachedData(const CachedData&); | |
1108 }; | 1114 }; |
1109 | 1115 |
1110 /** | 1116 /** |
1111 * Source code which can be then compiled to a UnboundScript or | 1117 * Source code which can be then compiled to a UnboundScript or |
1112 * BoundScript. | 1118 * BoundScript. |
1113 */ | 1119 */ |
1114 struct V8_EXPORT Source { | 1120 class V8_EXPORT Source { |
1121 public: | |
1122 // Source takes ownership of CachedData. | |
1115 Source(Local<String> source_string, const ScriptOrigin& origin, | 1123 Source(Local<String> source_string, const ScriptOrigin& origin, |
1116 const CachedData& cached_data = CachedData()); | 1124 CachedData* cached_data = NULL); |
1117 Source(Local<String> source_string, | 1125 Source(Local<String> source_string, CachedData* cached_data = NULL); |
1118 const CachedData& cached_data = CachedData()); | 1126 ~Source(); |
1127 | |
1128 // Ownership of the CachedData or its buffers is *not* transferred to the | |
1129 // caller. The CachedData object is alive as long as the Source object is | |
1130 // alive. | |
1131 const CachedData* GetCachedData() const; | |
1132 | |
1133 private: | |
1134 friend class ScriptCompiler; | |
1135 // Prevent copying. Not implemented. | |
1136 Source(const Source&); | |
1119 | 1137 |
1120 Local<String> source_string; | 1138 Local<String> source_string; |
1121 | 1139 |
1122 // Origin information | 1140 // Origin information |
1123 Handle<Value> resource_name; | 1141 Handle<Value> resource_name; |
1124 Handle<Integer> resource_line_offset; | 1142 Handle<Integer> resource_line_offset; |
1125 Handle<Integer> resource_column_offset; | 1143 Handle<Integer> resource_column_offset; |
1126 Handle<Boolean> resource_is_shared_cross_origin; | 1144 Handle<Boolean> resource_is_shared_cross_origin; |
1127 | 1145 |
1128 // Cached data from previous compilation (if any). | 1146 // Cached data from previous compilation (if any), or generated during |
1129 CachedData cached_data; | 1147 // compilation (if the generate_cached_data flag is passed to |
1148 // ScriptCompiler). | |
1149 CachedData* cached_data; | |
1130 }; | 1150 }; |
1131 | 1151 |
1132 enum CompileOptions { | 1152 enum CompileOptions { |
1133 kNoCompileOptions, | 1153 kNoCompileOptions, |
1134 kProduceDataToCache = 1 << 0 | 1154 kProduceDataToCache = 1 << 0 |
1135 }; | 1155 }; |
1136 | 1156 |
1137 /** | 1157 /** |
1138 * Compiles the specified script (context-independent). | 1158 * Compiles the specified script (context-independent). |
1139 * | 1159 * |
1140 * \param source Script source code. | 1160 * \param source Script source code. |
1141 * \return Compiled script object (context independent; for running it must be | 1161 * \return Compiled script object (context independent; for running it must be |
1142 * bound to a context). | 1162 * bound to a context). |
1143 */ | 1163 */ |
1144 static Local<UnboundScript> CompileUnbound( | 1164 static Local<UnboundScript> CompileUnbound( |
1145 Isolate* isolate, const Source& source, | 1165 Isolate* isolate, Source* source, |
1146 CompileOptions options = kNoCompileOptions); | 1166 CompileOptions options = kNoCompileOptions); |
1147 | 1167 |
1148 /** | 1168 /** |
1149 * Compiles the specified script (bound to current context). | 1169 * Compiles the specified script (bound to current context). |
1150 * | 1170 * |
1151 * \param source Script source code. | 1171 * \param source Script source code. |
1152 * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile() | 1172 * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile() |
1153 * using pre_data speeds compilation if it's done multiple times. | 1173 * using pre_data speeds compilation if it's done multiple times. |
1154 * Owned by caller, no references are kept when this function returns. | 1174 * Owned by caller, no references are kept when this function returns. |
1155 * \return Compiled script object, bound to the context that was active | 1175 * \return Compiled script object, bound to the context that was active |
1156 * when this function was called. When run it will always use this | 1176 * when this function was called. When run it will always use this |
1157 * context. | 1177 * context. |
1158 */ | 1178 */ |
1159 static Local<Script> Compile( | 1179 static Local<Script> Compile( |
1160 Isolate* isolate, const Source& source, | 1180 Isolate* isolate, Source* source, |
1161 CompileOptions options = kNoCompileOptions); | 1181 CompileOptions options = kNoCompileOptions); |
1162 }; | 1182 }; |
1163 | 1183 |
1164 | 1184 |
1165 /** | 1185 /** |
1166 * An error message. | 1186 * An error message. |
1167 */ | 1187 */ |
1168 class V8_EXPORT Message { | 1188 class V8_EXPORT Message { |
1169 public: | 1189 public: |
1170 Local<String> Get() const; | 1190 Local<String> Get() const; |
(...skipping 5371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6542 */ | 6562 */ |
6543 | 6563 |
6544 | 6564 |
6545 } // namespace v8 | 6565 } // namespace v8 |
6546 | 6566 |
6547 | 6567 |
6548 #undef TYPE_CHECK | 6568 #undef TYPE_CHECK |
6549 | 6569 |
6550 | 6570 |
6551 #endif // V8_H_ | 6571 #endif // V8_H_ |
OLD | NEW |