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 enum BufferPolicy { |
1101 BufferNotOwned, | |
1102 BufferOwned | |
1103 }; | |
1104 | |
1105 CachedData() : data(NULL), length(0), buffer_policy(BufferNotOwned) {} | |
1101 // Caller keeps the ownership of data and guarantees that the data stays | 1106 // Caller keeps the ownership of data and guarantees that the data stays |
1102 // alive long enough. | 1107 // alive long enough. |
Sven Panne
2014/03/19 12:04:52
I think the comment is out of date. Furthermore, w
marja
2014/03/19 12:23:48
Updated the comment to be:
If buffer_policy is Bu
| |
1103 CachedData(const uint8_t* data, int length) : data(data), length(length) {} | 1108 CachedData(const uint8_t* data, int length, |
1109 BufferPolicy buffer_policy = BufferNotOwned); | |
1110 ~CachedData(); | |
1104 // TODO(marja): Async compilation; add constructors which take a callback | 1111 // TODO(marja): Async compilation; add constructors which take a callback |
1105 // which will be called when V8 no longer needs the data. | 1112 // which will be called when V8 no longer needs the data. |
1106 const uint8_t* data; | 1113 const uint8_t* data; |
1107 int length; | 1114 int length; |
1115 BufferPolicy buffer_policy; | |
1116 | |
1117 private: | |
1118 // Prevent copying. Not implemented. | |
1119 CachedData(const CachedData&); | |
1108 }; | 1120 }; |
1109 | 1121 |
1110 /** | 1122 /** |
1111 * Source code which can be then compiled to a UnboundScript or | 1123 * Source code which can be then compiled to a UnboundScript or |
1112 * BoundScript. | 1124 * BoundScript. |
1113 */ | 1125 */ |
1114 struct V8_EXPORT Source { | 1126 class V8_EXPORT Source { |
1127 public: | |
1128 // Source takes ownership of CachedData. | |
1115 Source(Local<String> source_string, const ScriptOrigin& origin, | 1129 Source(Local<String> source_string, const ScriptOrigin& origin, |
1116 const CachedData& cached_data = CachedData()); | 1130 CachedData* cached_data = NULL); |
1117 Source(Local<String> source_string, | 1131 Source(Local<String> source_string, CachedData* cached_data = NULL); |
1118 const CachedData& cached_data = CachedData()); | 1132 ~Source(); |
1133 | |
1134 // Ownership of the CachedData or its buffers is *not* transferred to the | |
1135 // caller. The CachedData object is alive as long as the Source object is | |
1136 // alive. | |
1137 const CachedData* GetCachedData() const; | |
1138 | |
1139 private: | |
1140 friend class ScriptCompiler; | |
1141 // Prevent copying. Not implemented. | |
1142 Source(const Source&); | |
1119 | 1143 |
1120 Local<String> source_string; | 1144 Local<String> source_string; |
1121 | 1145 |
1122 // Origin information | 1146 // Origin information |
1123 Handle<Value> resource_name; | 1147 Handle<Value> resource_name; |
1124 Handle<Integer> resource_line_offset; | 1148 Handle<Integer> resource_line_offset; |
1125 Handle<Integer> resource_column_offset; | 1149 Handle<Integer> resource_column_offset; |
1126 Handle<Boolean> resource_is_shared_cross_origin; | 1150 Handle<Boolean> resource_is_shared_cross_origin; |
1127 | 1151 |
1128 // Cached data from previous compilation (if any). | 1152 // Cached data from previous compilation (if any), or generated during |
1129 CachedData cached_data; | 1153 // compilation (if the generate_cached_data flag is passed to |
1154 // ScriptCompiler). | |
1155 CachedData* cached_data; | |
1130 }; | 1156 }; |
1131 | 1157 |
1132 enum CompileOptions { | 1158 enum CompileOptions { |
1133 kNoCompileOptions, | 1159 kNoCompileOptions, |
1134 kProduceDataToCache = 1 << 0 | 1160 kProduceDataToCache = 1 << 0 |
1135 }; | 1161 }; |
1136 | 1162 |
1137 /** | 1163 /** |
1138 * Compiles the specified script (context-independent). | 1164 * Compiles the specified script (context-independent). |
1139 * | 1165 * |
1140 * \param source Script source code. | 1166 * \param source Script source code. |
1141 * \return Compiled script object (context independent; for running it must be | 1167 * \return Compiled script object (context independent; for running it must be |
1142 * bound to a context). | 1168 * bound to a context). |
1143 */ | 1169 */ |
1144 static Local<UnboundScript> CompileUnbound( | 1170 static Local<UnboundScript> CompileUnbound( |
1145 Isolate* isolate, const Source& source, | 1171 Isolate* isolate, Source* source, |
1146 CompileOptions options = kNoCompileOptions); | 1172 CompileOptions options = kNoCompileOptions); |
1147 | 1173 |
1148 /** | 1174 /** |
1149 * Compiles the specified script (bound to current context). | 1175 * Compiles the specified script (bound to current context). |
1150 * | 1176 * |
1151 * \param source Script source code. | 1177 * \param source Script source code. |
1152 * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile() | 1178 * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile() |
1153 * using pre_data speeds compilation if it's done multiple times. | 1179 * using pre_data speeds compilation if it's done multiple times. |
1154 * Owned by caller, no references are kept when this function returns. | 1180 * Owned by caller, no references are kept when this function returns. |
1155 * \return Compiled script object, bound to the context that was active | 1181 * \return Compiled script object, bound to the context that was active |
1156 * when this function was called. When run it will always use this | 1182 * when this function was called. When run it will always use this |
1157 * context. | 1183 * context. |
1158 */ | 1184 */ |
1159 static Local<Script> Compile( | 1185 static Local<Script> Compile( |
1160 Isolate* isolate, const Source& source, | 1186 Isolate* isolate, Source* source, |
1161 CompileOptions options = kNoCompileOptions); | 1187 CompileOptions options = kNoCompileOptions); |
1162 }; | 1188 }; |
1163 | 1189 |
1164 | 1190 |
1165 /** | 1191 /** |
1166 * An error message. | 1192 * An error message. |
1167 */ | 1193 */ |
1168 class V8_EXPORT Message { | 1194 class V8_EXPORT Message { |
1169 public: | 1195 public: |
1170 Local<String> Get() const; | 1196 Local<String> Get() const; |
(...skipping 5371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6542 */ | 6568 */ |
6543 | 6569 |
6544 | 6570 |
6545 } // namespace v8 | 6571 } // namespace v8 |
6546 | 6572 |
6547 | 6573 |
6548 #undef TYPE_CHECK | 6574 #undef TYPE_CHECK |
6549 | 6575 |
6550 | 6576 |
6551 #endif // V8_H_ | 6577 #endif // V8_H_ |
OLD | NEW |