The data contained in this repository can be downloaded to your computer using one of several clients.
Please see the documentation of your version control software client for more information.

Please select the desired protocol below to get the URL.

This URL has Read-Only access.

Statistics
| Branch: | Revision:

main_repo / deps / v8 / src / factory.h @ f230a1cf

History | View | Annotate | Download (26 KB)

1
// Copyright 2012 the V8 project authors. All rights reserved.
2
// Redistribution and use in source and binary forms, with or without
3
// modification, are permitted provided that the following conditions are
4
// met:
5
//
6
//     * Redistributions of source code must retain the above copyright
7
//       notice, this list of conditions and the following disclaimer.
8
//     * Redistributions in binary form must reproduce the above
9
//       copyright notice, this list of conditions and the following
10
//       disclaimer in the documentation and/or other materials provided
11
//       with the distribution.
12
//     * Neither the name of Google Inc. nor the names of its
13
//       contributors may be used to endorse or promote products derived
14
//       from this software without specific prior written permission.
15
//
16
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27

    
28
#ifndef V8_FACTORY_H_
29
#define V8_FACTORY_H_
30

    
31
#include "globals.h"
32
#include "handles.h"
33
#include "heap.h"
34

    
35
namespace v8 {
36
namespace internal {
37

    
38
// Interface for handle based allocation.
39

    
40
class Factory {
41
 public:
42
  // Allocate a new boxed value.
43
  Handle<Box> NewBox(
44
      Handle<Object> value,
45
      PretenureFlag pretenure = NOT_TENURED);
46

    
47
  // Allocate a new uninitialized fixed array.
48
  Handle<FixedArray> NewFixedArray(
49
      int size,
50
      PretenureFlag pretenure = NOT_TENURED);
51

    
52
  // Allocate a new fixed array with non-existing entries (the hole).
53
  Handle<FixedArray> NewFixedArrayWithHoles(
54
      int size,
55
      PretenureFlag pretenure = NOT_TENURED);
56

    
57
  // Allocate a new uninitialized fixed double array.
58
  Handle<FixedDoubleArray> NewFixedDoubleArray(
59
      int size,
60
      PretenureFlag pretenure = NOT_TENURED);
61

    
62
  Handle<ConstantPoolArray> NewConstantPoolArray(
63
      int number_of_int64_entries,
64
      int number_of_ptr_entries,
65
      int number_of_int32_entries);
66

    
67
  Handle<SeededNumberDictionary> NewSeededNumberDictionary(
68
      int at_least_space_for);
69

    
70
  Handle<UnseededNumberDictionary> NewUnseededNumberDictionary(
71
      int at_least_space_for);
72

    
73
  Handle<NameDictionary> NewNameDictionary(int at_least_space_for);
74

    
75
  Handle<ObjectHashSet> NewObjectHashSet(int at_least_space_for);
76

    
77
  Handle<ObjectHashTable> NewObjectHashTable(int at_least_space_for);
78

    
79
  Handle<WeakHashTable> NewWeakHashTable(int at_least_space_for);
80

    
81
  Handle<DescriptorArray> NewDescriptorArray(int number_of_descriptors,
82
                                             int slack = 0);
83
  Handle<DeoptimizationInputData> NewDeoptimizationInputData(
84
      int deopt_entry_count,
85
      PretenureFlag pretenure);
86
  Handle<DeoptimizationOutputData> NewDeoptimizationOutputData(
87
      int deopt_entry_count,
88
      PretenureFlag pretenure);
89
  // Allocates a pre-tenured empty AccessorPair.
90
  Handle<AccessorPair> NewAccessorPair();
91

    
92
  Handle<TypeFeedbackInfo> NewTypeFeedbackInfo();
93

    
94
  Handle<String> InternalizeUtf8String(Vector<const char> str);
95
  Handle<String> InternalizeUtf8String(const char* str) {
96
    return InternalizeUtf8String(CStrVector(str));
97
  }
98
  Handle<String> InternalizeString(Handle<String> str);
99
  Handle<String> InternalizeOneByteString(Vector<const uint8_t> str);
100
  Handle<String> InternalizeOneByteString(Handle<SeqOneByteString>,
101
                                   int from,
102
                                   int length);
103
  Handle<String> InternalizeTwoByteString(Vector<const uc16> str);
104

    
105

    
106
  // String creation functions.  Most of the string creation functions take
107
  // a Heap::PretenureFlag argument to optionally request that they be
108
  // allocated in the old generation.  The pretenure flag defaults to
109
  // DONT_TENURE.
110
  //
111
  // Creates a new String object.  There are two String encodings: ASCII and
112
  // two byte.  One should choose between the three string factory functions
113
  // based on the encoding of the string buffer that the string is
114
  // initialized from.
115
  //   - ...FromAscii initializes the string from a buffer that is ASCII
116
  //     encoded (it does not check that the buffer is ASCII encoded) and
117
  //     the result will be ASCII encoded.
118
  //   - ...FromUtf8 initializes the string from a buffer that is UTF-8
119
  //     encoded.  If the characters are all single-byte characters, the
120
  //     result will be ASCII encoded, otherwise it will converted to two
121
  //     byte.
122
  //   - ...FromTwoByte initializes the string from a buffer that is two
123
  //     byte encoded.  If the characters are all single-byte characters,
124
  //     the result will be converted to ASCII, otherwise it will be left as
125
  //     two byte.
126
  //
127
  // ASCII strings are pretenured when used as keys in the SourceCodeCache.
128
  Handle<String> NewStringFromOneByte(
129
      Vector<const uint8_t> str,
130
      PretenureFlag pretenure = NOT_TENURED);
131
  // TODO(dcarney): remove this function.
132
  inline Handle<String> NewStringFromAscii(
133
      Vector<const char> str,
134
      PretenureFlag pretenure = NOT_TENURED) {
135
    return NewStringFromOneByte(Vector<const uint8_t>::cast(str), pretenure);
136
  }
137

    
138
  // UTF8 strings are pretenured when used for regexp literal patterns and
139
  // flags in the parser.
140
  Handle<String> NewStringFromUtf8(
141
      Vector<const char> str,
142
      PretenureFlag pretenure = NOT_TENURED);
143

    
144
  Handle<String> NewStringFromTwoByte(
145
      Vector<const uc16> str,
146
      PretenureFlag pretenure = NOT_TENURED);
147

    
148
  // Allocates and partially initializes an ASCII or TwoByte String. The
149
  // characters of the string are uninitialized. Currently used in regexp code
150
  // only, where they are pretenured.
151
  Handle<SeqOneByteString> NewRawOneByteString(
152
      int length,
153
      PretenureFlag pretenure = NOT_TENURED);
154
  Handle<SeqTwoByteString> NewRawTwoByteString(
155
      int length,
156
      PretenureFlag pretenure = NOT_TENURED);
157

    
158
  // Create a new cons string object which consists of a pair of strings.
159
  Handle<String> NewConsString(Handle<String> first,
160
                               Handle<String> second);
161

    
162
  // Create a new sequential string containing the concatenation of the inputs.
163
  Handle<String> NewFlatConcatString(Handle<String> first,
164
                                     Handle<String> second);
165

    
166
  // Create a new string object which holds a substring of a string.
167
  Handle<String> NewSubString(Handle<String> str,
168
                              int begin,
169
                              int end);
170

    
171
  // Create a new string object which holds a proper substring of a string.
172
  Handle<String> NewProperSubString(Handle<String> str,
173
                                    int begin,
174
                                    int end);
175

    
176
  // Creates a new external String object.  There are two String encodings
177
  // in the system: ASCII and two byte.  Unlike other String types, it does
178
  // not make sense to have a UTF-8 factory function for external strings,
179
  // because we cannot change the underlying buffer.
180
  Handle<String> NewExternalStringFromAscii(
181
      const ExternalAsciiString::Resource* resource);
182
  Handle<String> NewExternalStringFromTwoByte(
183
      const ExternalTwoByteString::Resource* resource);
184

    
185
  // Create a symbol.
186
  Handle<Symbol> NewSymbol();
187

    
188
  // Create a global (but otherwise uninitialized) context.
189
  Handle<Context> NewNativeContext();
190

    
191
  // Create a global context.
192
  Handle<Context> NewGlobalContext(Handle<JSFunction> function,
193
                                   Handle<ScopeInfo> scope_info);
194

    
195
  // Create a module context.
196
  Handle<Context> NewModuleContext(Handle<ScopeInfo> scope_info);
197

    
198
  // Create a function context.
199
  Handle<Context> NewFunctionContext(int length, Handle<JSFunction> function);
200

    
201
  // Create a catch context.
202
  Handle<Context> NewCatchContext(Handle<JSFunction> function,
203
                                  Handle<Context> previous,
204
                                  Handle<String> name,
205
                                  Handle<Object> thrown_object);
206

    
207
  // Create a 'with' context.
208
  Handle<Context> NewWithContext(Handle<JSFunction> function,
209
                                 Handle<Context> previous,
210
                                 Handle<JSObject> extension);
211

    
212
  // Create a block context.
213
  Handle<Context> NewBlockContext(Handle<JSFunction> function,
214
                                  Handle<Context> previous,
215
                                  Handle<ScopeInfo> scope_info);
216

    
217
  // Return the internalized version of the passed in string.
218
  Handle<String> InternalizedStringFromString(Handle<String> value);
219

    
220
  // Allocate a new struct.  The struct is pretenured (allocated directly in
221
  // the old generation).
222
  Handle<Struct> NewStruct(InstanceType type);
223

    
224
  Handle<DeclaredAccessorDescriptor> NewDeclaredAccessorDescriptor();
225

    
226
  Handle<DeclaredAccessorInfo> NewDeclaredAccessorInfo();
227

    
228
  Handle<ExecutableAccessorInfo> NewExecutableAccessorInfo();
229

    
230
  Handle<Script> NewScript(Handle<String> source);
231

    
232
  // Foreign objects are pretenured when allocated by the bootstrapper.
233
  Handle<Foreign> NewForeign(Address addr,
234
                             PretenureFlag pretenure = NOT_TENURED);
235

    
236
  // Allocate a new foreign object.  The foreign is pretenured (allocated
237
  // directly in the old generation).
238
  Handle<Foreign> NewForeign(const AccessorDescriptor* foreign);
239

    
240
  Handle<ByteArray> NewByteArray(int length,
241
                                 PretenureFlag pretenure = NOT_TENURED);
242

    
243
  Handle<ExternalArray> NewExternalArray(
244
      int length,
245
      ExternalArrayType array_type,
246
      void* external_pointer,
247
      PretenureFlag pretenure = NOT_TENURED);
248

    
249
  Handle<Cell> NewCell(Handle<Object> value);
250

    
251
  Handle<PropertyCell> NewPropertyCellWithHole();
252

    
253
  Handle<PropertyCell> NewPropertyCell(Handle<Object> value);
254

    
255
  Handle<AllocationSite> NewAllocationSite();
256

    
257
  Handle<Map> NewMap(
258
      InstanceType type,
259
      int instance_size,
260
      ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND);
261

    
262
  Handle<JSObject> NewFunctionPrototype(Handle<JSFunction> function);
263

    
264
  Handle<Map> CopyWithPreallocatedFieldDescriptors(Handle<Map> map);
265

    
266
  // Copy the map adding more inobject properties if possible without
267
  // overflowing the instance size.
268
  Handle<Map> CopyMap(Handle<Map> map, int extra_inobject_props);
269
  Handle<Map> CopyMap(Handle<Map> map);
270

    
271
  Handle<Map> GetElementsTransitionMap(Handle<JSObject> object,
272
                                       ElementsKind elements_kind);
273

    
274
  Handle<FixedArray> CopyFixedArray(Handle<FixedArray> array);
275

    
276
  Handle<FixedArray> CopySizeFixedArray(Handle<FixedArray> array,
277
                                        int new_length,
278
                                        PretenureFlag pretenure = NOT_TENURED);
279

    
280
  Handle<FixedDoubleArray> CopyFixedDoubleArray(
281
      Handle<FixedDoubleArray> array);
282

    
283
  Handle<ConstantPoolArray> CopyConstantPoolArray(
284
      Handle<ConstantPoolArray> array);
285

    
286
  // Numbers (e.g. literals) are pretenured by the parser.
287
  Handle<Object> NewNumber(double value,
288
                           PretenureFlag pretenure = NOT_TENURED);
289

    
290
  Handle<Object> NewNumberFromInt(int32_t value,
291
                                  PretenureFlag pretenure = NOT_TENURED);
292
  Handle<Object> NewNumberFromUint(uint32_t value,
293
                                  PretenureFlag pretenure = NOT_TENURED);
294
  inline Handle<Object> NewNumberFromSize(size_t value,
295
                                   PretenureFlag pretenure = NOT_TENURED);
296
  Handle<HeapNumber> NewHeapNumber(double value,
297
                                   PretenureFlag pretenure = NOT_TENURED);
298

    
299

    
300
  // These objects are used by the api to create env-independent data
301
  // structures in the heap.
302
  Handle<JSObject> NewNeanderObject();
303

    
304
  Handle<JSObject> NewArgumentsObject(Handle<Object> callee, int length);
305

    
306
  // JS objects are pretenured when allocated by the bootstrapper and
307
  // runtime.
308
  Handle<JSObject> NewJSObject(Handle<JSFunction> constructor,
309
                               PretenureFlag pretenure = NOT_TENURED);
310

    
311
  // Global objects are pretenured and initialized based on a constructor.
312
  Handle<GlobalObject> NewGlobalObject(Handle<JSFunction> constructor);
313

    
314
  // JS objects are pretenured when allocated by the bootstrapper and
315
  // runtime.
316
  Handle<JSObject> NewJSObjectFromMap(Handle<Map> map,
317
                                      PretenureFlag pretenure = NOT_TENURED,
318
                                      bool allocate_properties = true);
319

    
320
  Handle<JSObject> NewJSObjectFromMapForDeoptimizer(
321
      Handle<Map> map, PretenureFlag pretenure = NOT_TENURED);
322

    
323
  // JS modules are pretenured.
324
  Handle<JSModule> NewJSModule(Handle<Context> context,
325
                               Handle<ScopeInfo> scope_info);
326

    
327
  // JS arrays are pretenured when allocated by the parser.
328
  Handle<JSArray> NewJSArray(
329
      int capacity,
330
      ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND,
331
      PretenureFlag pretenure = NOT_TENURED);
332

    
333
  Handle<JSArray> NewJSArrayWithElements(
334
      Handle<FixedArrayBase> elements,
335
      ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND,
336
      PretenureFlag pretenure = NOT_TENURED);
337

    
338
  void SetElementsCapacityAndLength(Handle<JSArray> array,
339
                                    int capacity,
340
                                    int length);
341

    
342
  void SetContent(Handle<JSArray> array, Handle<FixedArrayBase> elements);
343

    
344
  Handle<JSArrayBuffer> NewJSArrayBuffer();
345

    
346
  Handle<JSTypedArray> NewJSTypedArray(ExternalArrayType type);
347

    
348
  Handle<JSDataView> NewJSDataView();
349

    
350
  Handle<JSProxy> NewJSProxy(Handle<Object> handler, Handle<Object> prototype);
351

    
352
  // Change the type of the argument into a JS object/function and reinitialize.
353
  void BecomeJSObject(Handle<JSReceiver> object);
354
  void BecomeJSFunction(Handle<JSReceiver> object);
355

    
356
  Handle<JSFunction> NewFunction(Handle<String> name,
357
                                 Handle<Object> prototype);
358

    
359
  Handle<JSFunction> NewFunctionWithoutPrototype(
360
      Handle<String> name,
361
      LanguageMode language_mode);
362

    
363
  Handle<JSFunction> NewFunction(Handle<Object> super, bool is_global);
364

    
365
  Handle<JSFunction> BaseNewFunctionFromSharedFunctionInfo(
366
      Handle<SharedFunctionInfo> function_info,
367
      Handle<Map> function_map,
368
      PretenureFlag pretenure);
369

    
370
  Handle<JSFunction> NewFunctionFromSharedFunctionInfo(
371
      Handle<SharedFunctionInfo> function_info,
372
      Handle<Context> context,
373
      PretenureFlag pretenure = TENURED);
374

    
375
  Handle<ScopeInfo> NewScopeInfo(int length);
376

    
377
  Handle<JSObject> NewExternal(void* value);
378

    
379
  Handle<Code> NewCode(const CodeDesc& desc,
380
                       Code::Flags flags,
381
                       Handle<Object> self_reference,
382
                       bool immovable = false,
383
                       bool crankshafted = false,
384
                       int prologue_offset = Code::kPrologueOffsetNotSet);
385

    
386
  Handle<Code> CopyCode(Handle<Code> code);
387

    
388
  Handle<Code> CopyCode(Handle<Code> code, Vector<byte> reloc_info);
389

    
390
  Handle<Object> ToObject(Handle<Object> object);
391
  Handle<Object> ToObject(Handle<Object> object,
392
                          Handle<Context> native_context);
393

    
394
  // Interface for creating error objects.
395

    
396
  Handle<Object> NewError(const char* maker, const char* message,
397
                          Handle<JSArray> args);
398
  Handle<String> EmergencyNewError(const char* message, Handle<JSArray> args);
399
  Handle<Object> NewError(const char* maker, const char* message,
400
                          Vector< Handle<Object> > args);
401
  Handle<Object> NewError(const char* message,
402
                          Vector< Handle<Object> > args);
403
  Handle<Object> NewError(Handle<String> message);
404
  Handle<Object> NewError(const char* constructor,
405
                          Handle<String> message);
406

    
407
  Handle<Object> NewTypeError(const char* message,
408
                              Vector< Handle<Object> > args);
409
  Handle<Object> NewTypeError(Handle<String> message);
410

    
411
  Handle<Object> NewRangeError(const char* message,
412
                               Vector< Handle<Object> > args);
413
  Handle<Object> NewRangeError(Handle<String> message);
414

    
415
  Handle<Object> NewSyntaxError(const char* message, Handle<JSArray> args);
416
  Handle<Object> NewSyntaxError(Handle<String> message);
417

    
418
  Handle<Object> NewReferenceError(const char* message,
419
                                   Vector< Handle<Object> > args);
420
  Handle<Object> NewReferenceError(Handle<String> message);
421

    
422
  Handle<Object> NewEvalError(const char* message,
423
                              Vector< Handle<Object> > args);
424

    
425

    
426
  Handle<JSFunction> NewFunction(Handle<String> name,
427
                                 InstanceType type,
428
                                 int instance_size,
429
                                 Handle<Code> code,
430
                                 bool force_initial_map);
431

    
432
  Handle<JSFunction> NewFunction(Handle<Map> function_map,
433
      Handle<SharedFunctionInfo> shared, Handle<Object> prototype);
434

    
435

    
436
  Handle<JSFunction> NewFunctionWithPrototype(Handle<String> name,
437
                                              InstanceType type,
438
                                              int instance_size,
439
                                              Handle<JSObject> prototype,
440
                                              Handle<Code> code,
441
                                              bool force_initial_map);
442

    
443
  Handle<JSFunction> NewFunctionWithoutPrototype(Handle<String> name,
444
                                                 Handle<Code> code);
445

    
446
  Handle<String> NumberToString(Handle<Object> number);
447
  Handle<String> Uint32ToString(uint32_t value);
448

    
449
  enum ApiInstanceType {
450
    JavaScriptObject,
451
    InnerGlobalObject,
452
    OuterGlobalObject
453
  };
454

    
455
  Handle<JSFunction> CreateApiFunction(
456
      Handle<FunctionTemplateInfo> data,
457
      ApiInstanceType type = JavaScriptObject);
458

    
459
  Handle<JSFunction> InstallMembers(Handle<JSFunction> function);
460

    
461
  // Installs interceptors on the instance.  'desc' is a function template,
462
  // and instance is an object instance created by the function of this
463
  // function template.
464
  void ConfigureInstance(Handle<FunctionTemplateInfo> desc,
465
                         Handle<JSObject> instance,
466
                         bool* pending_exception);
467

    
468
#define ROOT_ACCESSOR(type, name, camel_name)                                  \
469
  inline Handle<type> name() {                                                 \
470
    return Handle<type>(BitCast<type**>(                                       \
471
        &isolate()->heap()->roots_[Heap::k##camel_name##RootIndex]));          \
472
  }
473
  ROOT_LIST(ROOT_ACCESSOR)
474
#undef ROOT_ACCESSOR
475

    
476
#define STRUCT_MAP_ACCESSOR(NAME, Name, name)                                  \
477
  inline Handle<Map> name##_map() {                                            \
478
    return Handle<Map>(BitCast<Map**>(                                         \
479
        &isolate()->heap()->roots_[Heap::k##Name##MapRootIndex]));             \
480
    }
481
  STRUCT_LIST(STRUCT_MAP_ACCESSOR)
482
#undef STRUCT_MAP_ACCESSOR
483

    
484
#define STRING_ACCESSOR(name, str)                                             \
485
  inline Handle<String> name() {                                               \
486
    return Handle<String>(BitCast<String**>(                                   \
487
        &isolate()->heap()->roots_[Heap::k##name##RootIndex]));                \
488
  }
489
  INTERNALIZED_STRING_LIST(STRING_ACCESSOR)
490
#undef STRING_ACCESSOR
491

    
492
  Handle<String> hidden_string() {
493
    return Handle<String>(&isolate()->heap()->hidden_string_);
494
  }
495

    
496
  Handle<SharedFunctionInfo> NewSharedFunctionInfo(
497
      Handle<String> name,
498
      int number_of_literals,
499
      bool is_generator,
500
      Handle<Code> code,
501
      Handle<ScopeInfo> scope_info);
502
  Handle<SharedFunctionInfo> NewSharedFunctionInfo(Handle<String> name);
503

    
504
  Handle<JSMessageObject> NewJSMessageObject(
505
      Handle<String> type,
506
      Handle<JSArray> arguments,
507
      int start_position,
508
      int end_position,
509
      Handle<Object> script,
510
      Handle<Object> stack_trace,
511
      Handle<Object> stack_frames);
512

    
513
  Handle<SeededNumberDictionary> DictionaryAtNumberPut(
514
      Handle<SeededNumberDictionary>,
515
      uint32_t key,
516
      Handle<Object> value);
517

    
518
  Handle<UnseededNumberDictionary> DictionaryAtNumberPut(
519
      Handle<UnseededNumberDictionary>,
520
      uint32_t key,
521
      Handle<Object> value);
522

    
523
#ifdef ENABLE_DEBUGGER_SUPPORT
524
  Handle<DebugInfo> NewDebugInfo(Handle<SharedFunctionInfo> shared);
525
#endif
526

    
527
  // Return a map using the map cache in the native context.
528
  // The key the an ordered set of property names.
529
  Handle<Map> ObjectLiteralMapFromCache(Handle<Context> context,
530
                                        Handle<FixedArray> keys);
531

    
532
  // Creates a new FixedArray that holds the data associated with the
533
  // atom regexp and stores it in the regexp.
534
  void SetRegExpAtomData(Handle<JSRegExp> regexp,
535
                         JSRegExp::Type type,
536
                         Handle<String> source,
537
                         JSRegExp::Flags flags,
538
                         Handle<Object> match_pattern);
539

    
540
  // Creates a new FixedArray that holds the data associated with the
541
  // irregexp regexp and stores it in the regexp.
542
  void SetRegExpIrregexpData(Handle<JSRegExp> regexp,
543
                             JSRegExp::Type type,
544
                             Handle<String> source,
545
                             JSRegExp::Flags flags,
546
                             int capture_count);
547

    
548
  // Returns the value for a known global constant (a property of the global
549
  // object which is neither configurable nor writable) like 'undefined'.
550
  // Returns a null handle when the given name is unknown.
551
  Handle<Object> GlobalConstantFor(Handle<String> name);
552

    
553
  // Converts the given boolean condition to JavaScript boolean value.
554
  Handle<Object> ToBoolean(bool value);
555

    
556
 private:
557
  Isolate* isolate() { return reinterpret_cast<Isolate*>(this); }
558

    
559
  Handle<JSFunction> NewFunctionHelper(Handle<String> name,
560
                                       Handle<Object> prototype);
561

    
562
  Handle<JSFunction> NewFunctionWithoutPrototypeHelper(
563
      Handle<String> name,
564
      LanguageMode language_mode);
565

    
566
  // Create a new map cache.
567
  Handle<MapCache> NewMapCache(int at_least_space_for);
568

    
569
  // Update the map cache in the native context with (keys, map)
570
  Handle<MapCache> AddToMapCache(Handle<Context> context,
571
                                 Handle<FixedArray> keys,
572
                                 Handle<Map> map);
573
};
574

    
575

    
576
Handle<Object> Factory::NewNumberFromSize(size_t value,
577
                                          PretenureFlag pretenure) {
578
  if (Smi::IsValid(static_cast<intptr_t>(value))) {
579
    return Handle<Object>(Smi::FromIntptr(static_cast<intptr_t>(value)),
580
                          isolate());
581
  } else {
582
    return NewNumber(static_cast<double>(value), pretenure);
583
  }
584
}
585

    
586

    
587
// Used to "safely" transition from pointer-based runtime code to Handle-based
588
// runtime code. When a GC happens during the called Handle-based code, a
589
// failure object is returned to the pointer-based code to cause it abort and
590
// re-trigger a gc of it's own. Since this double-gc will cause the Handle-based
591
// code to be called twice, it must be idempotent.
592
class IdempotentPointerToHandleCodeTrampoline {
593
 public:
594
  explicit IdempotentPointerToHandleCodeTrampoline(Isolate* isolate)
595
      : isolate_(isolate) {}
596

    
597
  template<typename R>
598
  MUST_USE_RESULT MaybeObject* Call(R (*function)()) {
599
    int collections = isolate_->heap()->gc_count();
600
    (*function)();
601
    return (collections == isolate_->heap()->gc_count())
602
        ? isolate_->heap()->true_value()
603
        : reinterpret_cast<MaybeObject*>(Failure::RetryAfterGC());
604
  }
605

    
606
  template<typename R>
607
  MUST_USE_RESULT MaybeObject* CallWithReturnValue(R (*function)()) {
608
    int collections = isolate_->heap()->gc_count();
609
    Object* result = (*function)();
610
    return (collections == isolate_->heap()->gc_count())
611
        ? result
612
        : reinterpret_cast<MaybeObject*>(Failure::RetryAfterGC());
613
  }
614

    
615
  template<typename R, typename P1>
616
  MUST_USE_RESULT MaybeObject* Call(R (*function)(P1), P1 p1) {
617
    int collections = isolate_->heap()->gc_count();
618
    (*function)(p1);
619
    return (collections == isolate_->heap()->gc_count())
620
        ? isolate_->heap()->true_value()
621
        : reinterpret_cast<MaybeObject*>(Failure::RetryAfterGC());
622
  }
623

    
624
  template<typename R, typename P1>
625
  MUST_USE_RESULT MaybeObject* CallWithReturnValue(
626
      R (*function)(P1),
627
      P1 p1) {
628
    int collections = isolate_->heap()->gc_count();
629
    Object* result = (*function)(p1);
630
    return (collections == isolate_->heap()->gc_count())
631
        ? result
632
        : reinterpret_cast<MaybeObject*>(Failure::RetryAfterGC());
633
  }
634

    
635
  template<typename R, typename P1, typename P2>
636
  MUST_USE_RESULT MaybeObject* Call(
637
      R (*function)(P1, P2),
638
      P1 p1,
639
      P2 p2) {
640
    int collections = isolate_->heap()->gc_count();
641
    (*function)(p1, p2);
642
    return (collections == isolate_->heap()->gc_count())
643
        ? isolate_->heap()->true_value()
644
        : reinterpret_cast<MaybeObject*>(Failure::RetryAfterGC());
645
  }
646

    
647
  template<typename R, typename P1, typename P2>
648
  MUST_USE_RESULT MaybeObject* CallWithReturnValue(
649
      R (*function)(P1, P2),
650
      P1 p1,
651
      P2 p2) {
652
    int collections = isolate_->heap()->gc_count();
653
    Object* result = (*function)(p1, p2);
654
    return (collections == isolate_->heap()->gc_count())
655
        ? result
656
        : reinterpret_cast<MaybeObject*>(Failure::RetryAfterGC());
657
  }
658

    
659
  template<typename R, typename P1, typename P2, typename P3, typename P4,
660
           typename P5, typename P6, typename P7>
661
  MUST_USE_RESULT MaybeObject* CallWithReturnValue(
662
      R (*function)(P1, P2, P3, P4, P5, P6, P7),
663
      P1 p1,
664
      P2 p2,
665
      P3 p3,
666
      P4 p4,
667
      P5 p5,
668
      P6 p6,
669
      P7 p7) {
670
    int collections = isolate_->heap()->gc_count();
671
    Handle<Object> result = (*function)(p1, p2, p3, p4, p5, p6, p7);
672
    return (collections == isolate_->heap()->gc_count())
673
        ? *result
674
        : reinterpret_cast<MaybeObject*>(Failure::RetryAfterGC());
675
  }
676

    
677
 private:
678
  Isolate* isolate_;
679
};
680

    
681

    
682
} }  // namespace v8::internal
683

    
684
#endif  // V8_FACTORY_H_