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