00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef V8_FACTORY_H_
00029 #define V8_FACTORY_H_
00030
00031 #include "heap.h"
00032
00033 namespace v8 { namespace internal {
00034
00035
00036
00037
00038 class Factory : public AllStatic {
00039 public:
00040
00041 static Handle<FixedArray> NewFixedArray(
00042 int size,
00043 PretenureFlag pretenure = NOT_TENURED);
00044
00045
00046 static Handle<FixedArray> NewFixedArrayWithHoles(int size);
00047
00048 static Handle<Dictionary> NewDictionary(int at_least_space_for);
00049
00050 static Handle<DescriptorArray> NewDescriptorArray(int number_of_descriptors);
00051
00052 static Handle<String> LookupSymbol(Vector<const char> str);
00053 static Handle<String> LookupAsciiSymbol(const char* str) {
00054 return LookupSymbol(CStrVector(str));
00055 }
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 static Handle<String> NewStringFromAscii(
00081 Vector<const char> str,
00082 PretenureFlag pretenure = NOT_TENURED);
00083
00084
00085
00086 static Handle<String> NewStringFromUtf8(
00087 Vector<const char> str,
00088 PretenureFlag pretenure = NOT_TENURED);
00089
00090 static Handle<String> NewStringFromTwoByte(Vector<const uc16> str);
00091
00092
00093
00094
00095 static Handle<String> NewRawTwoByteString(
00096 int length,
00097 PretenureFlag pretenure = NOT_TENURED);
00098
00099
00100 static Handle<String> NewConsString(Handle<String> first,
00101 Handle<String> second);
00102
00103
00104
00105 static Handle<String> NewStringSlice(Handle<String> str, int begin, int end);
00106
00107
00108
00109
00110
00111 static Handle<String> NewExternalStringFromAscii(
00112 ExternalAsciiString::Resource* resource);
00113 static Handle<String> NewExternalStringFromTwoByte(
00114 ExternalTwoByteString::Resource* resource);
00115
00116
00117 static Handle<Context> NewGlobalContext();
00118
00119
00120 static Handle<Context> NewFunctionContext(int length,
00121 Handle<JSFunction> closure);
00122
00123
00124 static Handle<Context> NewWithContext(Handle<Context> previous,
00125 Handle<JSObject> extension);
00126
00127
00128 static Handle<String> SymbolFromString(Handle<String> value);
00129
00130
00131
00132 static Handle<Struct> NewStruct(InstanceType type);
00133
00134 static Handle<AccessorInfo> NewAccessorInfo();
00135
00136 static Handle<Script> NewScript(Handle<String> source);
00137
00138
00139 static Handle<Proxy> NewProxy(Address addr,
00140 PretenureFlag pretenure = NOT_TENURED);
00141
00142
00143
00144 static Handle<Proxy> NewProxy(const AccessorDescriptor* proxy);
00145
00146 static Handle<ByteArray> NewByteArray(int length);
00147
00148 static Handle<Map> NewMap(InstanceType type, int instance_size);
00149
00150 static Handle<JSObject> NewFunctionPrototype(Handle<JSFunction> function);
00151
00152 static Handle<Map> CopyMap(Handle<Map> map);
00153
00154 static Handle<Map> CopyMapDropTransitions(Handle<Map> map);
00155
00156 static Handle<FixedArray> CopyFixedArray(Handle<FixedArray> array);
00157
00158
00159 static Handle<Object> NewNumber(double value,
00160 PretenureFlag pretenure = NOT_TENURED);
00161
00162 static Handle<Object> NewNumberFromInt(int value);
00163
00164
00165
00166 static Handle<JSObject> NewNeanderObject();
00167
00168 static Handle<JSObject> NewArgumentsObject(Handle<Object> callee, int length);
00169
00170
00171
00172 static Handle<JSObject> NewJSObject(Handle<JSFunction> constructor,
00173 PretenureFlag pretenure = NOT_TENURED);
00174
00175
00176
00177 static Handle<JSObject> NewJSObjectFromMap(Handle<Map> map);
00178
00179
00180
00181 static Handle<JSObject> NewObjectLiteral(int expected_number_of_properties);
00182
00183
00184
00185 static Handle<JSArray> NewArrayLiteral(int length);
00186
00187
00188 static Handle<JSArray> NewJSArray(int init_length,
00189 PretenureFlag pretenure = NOT_TENURED);
00190
00191 static Handle<JSArray> NewJSArrayWithElements(
00192 Handle<FixedArray> elements,
00193 PretenureFlag pretenure = NOT_TENURED);
00194
00195 static Handle<JSFunction> NewFunction(Handle<String> name,
00196 Handle<Object> prototype);
00197
00198 static Handle<JSFunction> NewFunction(Handle<Object> super, bool is_global);
00199
00200 static Handle<JSFunction> NewFunctionFromBoilerplate(
00201 Handle<JSFunction> boilerplate,
00202 Handle<Context> context);
00203
00204 static Handle<Code> NewCode(const CodeDesc& desc, ScopeInfo<>* sinfo,
00205 Code::Flags flags);
00206
00207 static Handle<Code> CopyCode(Handle<Code> code);
00208
00209 static Handle<Object> ToObject(Handle<Object> object,
00210 Handle<Context> global_context);
00211
00212
00213
00214 static Handle<Object> NewError(const char* maker, const char* type,
00215 Handle<JSArray> args);
00216 static Handle<Object> NewError(const char* maker, const char* type,
00217 Vector< Handle<Object> > args);
00218 static Handle<Object> NewError(const char* type,
00219 Vector< Handle<Object> > args);
00220 static Handle<Object> NewError(Handle<String> message);
00221 static Handle<Object> NewError(const char* constructor,
00222 Handle<String> message);
00223
00224 static Handle<Object> NewTypeError(const char* type,
00225 Vector< Handle<Object> > args);
00226 static Handle<Object> NewTypeError(Handle<String> message);
00227
00228 static Handle<Object> NewRangeError(const char* type,
00229 Vector< Handle<Object> > args);
00230 static Handle<Object> NewRangeError(Handle<String> message);
00231
00232 static Handle<Object> NewSyntaxError(const char* type, Handle<JSArray> args);
00233 static Handle<Object> NewSyntaxError(Handle<String> message);
00234
00235 static Handle<Object> NewReferenceError(const char* type,
00236 Vector< Handle<Object> > args);
00237 static Handle<Object> NewReferenceError(Handle<String> message);
00238
00239 static Handle<Object> NewEvalError(const char* type,
00240 Vector< Handle<Object> > args);
00241
00242
00243 static Handle<JSFunction> NewFunction(Handle<String> name,
00244 InstanceType type,
00245 int instance_size,
00246 Handle<Code> code,
00247 bool force_initial_map);
00248
00249 static Handle<JSFunction> NewFunctionBoilerplate(Handle<String> name,
00250 int number_of_literals,
00251 bool contains_array_literal,
00252 Handle<Code> code);
00253
00254 static Handle<JSFunction> NewFunctionBoilerplate(Handle<String> name);
00255
00256 static Handle<JSFunction> NewFunction(Handle<Map> function_map,
00257 Handle<SharedFunctionInfo> shared, Handle<Object> prototype);
00258
00259
00260 static Handle<JSFunction> NewFunctionWithPrototype(Handle<String> name,
00261 InstanceType type,
00262 int instance_size,
00263 Handle<JSObject> prototype,
00264 Handle<Code> code,
00265 bool force_initial_map);
00266
00267 static Handle<DescriptorArray> CopyAppendProxyDescriptor(
00268 Handle<DescriptorArray> array,
00269 Handle<String> key,
00270 Handle<Object> value,
00271 PropertyAttributes attributes);
00272
00273 enum ApiInstanceType {
00274 JavaScriptObject,
00275 InnerGlobalObject,
00276 OuterGlobalObject
00277 };
00278
00279 static Handle<JSFunction> CreateApiFunction(
00280 Handle<FunctionTemplateInfo> data,
00281 ApiInstanceType type = JavaScriptObject);
00282
00283 static Handle<JSFunction> InstallMembers(Handle<JSFunction> function);
00284
00285
00286
00287
00288 static void ConfigureInstance(Handle<FunctionTemplateInfo> desc,
00289 Handle<JSObject> instance,
00290 bool* pending_exception);
00291
00292 #define ROOT_ACCESSOR(type, name) \
00293 static Handle<type> name() { return Handle<type>(&Heap::name##_); }
00294 ROOT_LIST(ROOT_ACCESSOR)
00295 #undef ROOT_ACCESSOR_ACCESSOR
00296
00297 #define SYMBOL_ACCESSOR(name, str) \
00298 static Handle<String> name() { return Handle<String>(&Heap::name##_); }
00299 SYMBOL_LIST(SYMBOL_ACCESSOR)
00300 #undef SYMBOL_ACCESSOR
00301
00302 static Handle<SharedFunctionInfo> NewSharedFunctionInfo(Handle<String> name);
00303
00304 static Handle<Dictionary> DictionaryAtNumberPut(Handle<Dictionary>,
00305 uint32_t key,
00306 Handle<Object> value);
00307
00308 static Handle<DebugInfo> NewDebugInfo(Handle<SharedFunctionInfo> shared);
00309
00310
00311
00312
00313 static Handle<Map> ObjectLiteralMapFromCache(Handle<Context> context,
00314 Handle<FixedArray> keys);
00315
00316
00317
00318 static void SetRegExpData(Handle<JSRegExp> regexp,
00319 JSRegExp::Type type,
00320 Handle<String> source,
00321 JSRegExp::Flags flags,
00322 Handle<Object> data);
00323
00324 private:
00325 static Handle<JSFunction> NewFunctionHelper(Handle<String> name,
00326 Handle<Object> prototype);
00327
00328 static Handle<DescriptorArray> CopyAppendCallbackDescriptors(
00329 Handle<DescriptorArray> array,
00330 Handle<Object> descriptors);
00331
00332 static Handle<JSFunction> BaseNewFunctionFromBoilerplate(
00333 Handle<JSFunction> boilerplate,
00334 Handle<Map> function_map);
00335
00336
00337 static Handle<MapCache> NewMapCache(int at_least_space_for);
00338
00339
00340 static Handle<MapCache> AddToMapCache(Handle<Context> context,
00341 Handle<FixedArray> keys,
00342 Handle<Map> map);
00343 };
00344
00345
00346 } }
00347
00348 #endif // V8_FACTORY_H_