~evarlast/ubuntu/utopic/mongodb/upstart-workaround-debian-bug-718702

« back to all changes in this revision

Viewing changes to src/third_party/v8/src/factory.cc

  • Committer: Package Import Robot
  • Author(s): James Page, James Page, Robie Basak
  • Date: 2013-05-29 17:44:42 UTC
  • mfrom: (44.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20130529174442-z0a4qmoww4y0t458
Tags: 1:2.4.3-1ubuntu1
[ James Page ]
* Merge from Debian unstable, remaining changes:
  - Enable SSL support:
    + d/control: Add libssl-dev to BD's.
    + d/rules: Enabled --ssl option.
    + d/mongodb.conf: Add example SSL configuration options.
  - d/mongodb-server.mongodb.upstart: Add upstart configuration.
  - d/rules: Don't strip binaries during scons build for Ubuntu.
  - d/control: Add armhf to target archs.
  - d/p/SConscript.client.patch: fixup install of client libraries.
  - d/p/0010-install-libs-to-usr-lib-not-usr-lib64-Closes-588557.patch:
    Install libraries to lib not lib64.
* Dropped changes:
  - d/p/arm-support.patch: Included in Debian.
  - d/p/double-alignment.patch: Included in Debian.
  - d/rules,control: Debian also builds with avaliable system libraries
    now.
* Fix FTBFS due to gcc and boost upgrades in saucy:
  - d/p/0008-ignore-unused-local-typedefs.patch: Add -Wno-unused-typedefs
    to unbreak building with g++-4.8.
  - d/p/0009-boost-1.53.patch: Fixup signed/unsigned casting issue.

[ Robie Basak ]
* d/p/0011-Use-a-signed-char-to-store-BSONType-enumerations.patch: Fixup
  build failure on ARM due to missing signed'ness of char cast.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#include "v8.h"
 
29
 
 
30
#include "api.h"
 
31
#include "debug.h"
 
32
#include "execution.h"
 
33
#include "factory.h"
 
34
#include "macro-assembler.h"
 
35
#include "objects.h"
 
36
#include "objects-visiting.h"
 
37
#include "platform.h"
 
38
#include "scopeinfo.h"
 
39
 
 
40
namespace v8 {
 
41
namespace internal {
 
42
 
 
43
 
 
44
Handle<FixedArray> Factory::NewFixedArray(int size, PretenureFlag pretenure) {
 
45
  ASSERT(0 <= size);
 
46
  CALL_HEAP_FUNCTION(
 
47
      isolate(),
 
48
      isolate()->heap()->AllocateFixedArray(size, pretenure),
 
49
      FixedArray);
 
50
}
 
51
 
 
52
 
 
53
Handle<FixedArray> Factory::NewFixedArrayWithHoles(int size,
 
54
                                                   PretenureFlag pretenure) {
 
55
  ASSERT(0 <= size);
 
56
  CALL_HEAP_FUNCTION(
 
57
      isolate(),
 
58
      isolate()->heap()->AllocateFixedArrayWithHoles(size, pretenure),
 
59
      FixedArray);
 
60
}
 
61
 
 
62
 
 
63
Handle<FixedDoubleArray> Factory::NewFixedDoubleArray(int size,
 
64
                                                      PretenureFlag pretenure) {
 
65
  ASSERT(0 <= size);
 
66
  CALL_HEAP_FUNCTION(
 
67
      isolate(),
 
68
      isolate()->heap()->AllocateUninitializedFixedDoubleArray(size, pretenure),
 
69
      FixedDoubleArray);
 
70
}
 
71
 
 
72
 
 
73
Handle<StringDictionary> Factory::NewStringDictionary(int at_least_space_for) {
 
74
  ASSERT(0 <= at_least_space_for);
 
75
  CALL_HEAP_FUNCTION(isolate(),
 
76
                     StringDictionary::Allocate(at_least_space_for),
 
77
                     StringDictionary);
 
78
}
 
79
 
 
80
 
 
81
Handle<SeededNumberDictionary> Factory::NewSeededNumberDictionary(
 
82
    int at_least_space_for) {
 
83
  ASSERT(0 <= at_least_space_for);
 
84
  CALL_HEAP_FUNCTION(isolate(),
 
85
                     SeededNumberDictionary::Allocate(at_least_space_for),
 
86
                     SeededNumberDictionary);
 
87
}
 
88
 
 
89
 
 
90
Handle<UnseededNumberDictionary> Factory::NewUnseededNumberDictionary(
 
91
    int at_least_space_for) {
 
92
  ASSERT(0 <= at_least_space_for);
 
93
  CALL_HEAP_FUNCTION(isolate(),
 
94
                     UnseededNumberDictionary::Allocate(at_least_space_for),
 
95
                     UnseededNumberDictionary);
 
96
}
 
97
 
 
98
 
 
99
Handle<ObjectHashSet> Factory::NewObjectHashSet(int at_least_space_for) {
 
100
  ASSERT(0 <= at_least_space_for);
 
101
  CALL_HEAP_FUNCTION(isolate(),
 
102
                     ObjectHashSet::Allocate(at_least_space_for),
 
103
                     ObjectHashSet);
 
104
}
 
105
 
 
106
 
 
107
Handle<ObjectHashTable> Factory::NewObjectHashTable(int at_least_space_for) {
 
108
  ASSERT(0 <= at_least_space_for);
 
109
  CALL_HEAP_FUNCTION(isolate(),
 
110
                     ObjectHashTable::Allocate(at_least_space_for),
 
111
                     ObjectHashTable);
 
112
}
 
113
 
 
114
 
 
115
Handle<DescriptorArray> Factory::NewDescriptorArray(int number_of_descriptors) {
 
116
  ASSERT(0 <= number_of_descriptors);
 
117
  CALL_HEAP_FUNCTION(isolate(),
 
118
                     DescriptorArray::Allocate(number_of_descriptors,
 
119
                                               DescriptorArray::MAY_BE_SHARED),
 
120
                     DescriptorArray);
 
121
}
 
122
 
 
123
 
 
124
Handle<DeoptimizationInputData> Factory::NewDeoptimizationInputData(
 
125
    int deopt_entry_count,
 
126
    PretenureFlag pretenure) {
 
127
  ASSERT(deopt_entry_count > 0);
 
128
  CALL_HEAP_FUNCTION(isolate(),
 
129
                     DeoptimizationInputData::Allocate(deopt_entry_count,
 
130
                                                       pretenure),
 
131
                     DeoptimizationInputData);
 
132
}
 
133
 
 
134
 
 
135
Handle<DeoptimizationOutputData> Factory::NewDeoptimizationOutputData(
 
136
    int deopt_entry_count,
 
137
    PretenureFlag pretenure) {
 
138
  ASSERT(deopt_entry_count > 0);
 
139
  CALL_HEAP_FUNCTION(isolate(),
 
140
                     DeoptimizationOutputData::Allocate(deopt_entry_count,
 
141
                                                        pretenure),
 
142
                     DeoptimizationOutputData);
 
143
}
 
144
 
 
145
 
 
146
Handle<AccessorPair> Factory::NewAccessorPair() {
 
147
  CALL_HEAP_FUNCTION(isolate(),
 
148
                     isolate()->heap()->AllocateAccessorPair(),
 
149
                     AccessorPair);
 
150
}
 
151
 
 
152
 
 
153
Handle<TypeFeedbackInfo> Factory::NewTypeFeedbackInfo() {
 
154
  CALL_HEAP_FUNCTION(isolate(),
 
155
                     isolate()->heap()->AllocateTypeFeedbackInfo(),
 
156
                     TypeFeedbackInfo);
 
157
}
 
158
 
 
159
 
 
160
// Symbols are created in the old generation (data space).
 
161
Handle<String> Factory::LookupSymbol(Vector<const char> string) {
 
162
  CALL_HEAP_FUNCTION(isolate(),
 
163
                     isolate()->heap()->LookupSymbol(string),
 
164
                     String);
 
165
}
 
166
 
 
167
// Symbols are created in the old generation (data space).
 
168
Handle<String> Factory::LookupSymbol(Handle<String> string) {
 
169
  CALL_HEAP_FUNCTION(isolate(),
 
170
                     isolate()->heap()->LookupSymbol(*string),
 
171
                     String);
 
172
}
 
173
 
 
174
Handle<String> Factory::LookupAsciiSymbol(Vector<const char> string) {
 
175
  CALL_HEAP_FUNCTION(isolate(),
 
176
                     isolate()->heap()->LookupAsciiSymbol(string),
 
177
                     String);
 
178
}
 
179
 
 
180
 
 
181
Handle<String> Factory::LookupAsciiSymbol(Handle<SeqAsciiString> string,
 
182
                                          int from,
 
183
                                          int length) {
 
184
  CALL_HEAP_FUNCTION(isolate(),
 
185
                     isolate()->heap()->LookupAsciiSymbol(string,
 
186
                                                          from,
 
187
                                                          length),
 
188
                     String);
 
189
}
 
190
 
 
191
 
 
192
Handle<String> Factory::LookupTwoByteSymbol(Vector<const uc16> string) {
 
193
  CALL_HEAP_FUNCTION(isolate(),
 
194
                     isolate()->heap()->LookupTwoByteSymbol(string),
 
195
                     String);
 
196
}
 
197
 
 
198
 
 
199
Handle<String> Factory::NewStringFromAscii(Vector<const char> string,
 
200
                                           PretenureFlag pretenure) {
 
201
  CALL_HEAP_FUNCTION(
 
202
      isolate(),
 
203
      isolate()->heap()->AllocateStringFromAscii(string, pretenure),
 
204
      String);
 
205
}
 
206
 
 
207
Handle<String> Factory::NewStringFromUtf8(Vector<const char> string,
 
208
                                          PretenureFlag pretenure) {
 
209
  CALL_HEAP_FUNCTION(
 
210
      isolate(),
 
211
      isolate()->heap()->AllocateStringFromUtf8(string, pretenure),
 
212
      String);
 
213
}
 
214
 
 
215
 
 
216
Handle<String> Factory::NewStringFromTwoByte(Vector<const uc16> string,
 
217
                                             PretenureFlag pretenure) {
 
218
  CALL_HEAP_FUNCTION(
 
219
      isolate(),
 
220
      isolate()->heap()->AllocateStringFromTwoByte(string, pretenure),
 
221
      String);
 
222
}
 
223
 
 
224
 
 
225
Handle<SeqAsciiString> Factory::NewRawAsciiString(int length,
 
226
                                                  PretenureFlag pretenure) {
 
227
  CALL_HEAP_FUNCTION(
 
228
      isolate(),
 
229
      isolate()->heap()->AllocateRawAsciiString(length, pretenure),
 
230
      SeqAsciiString);
 
231
}
 
232
 
 
233
 
 
234
Handle<SeqTwoByteString> Factory::NewRawTwoByteString(int length,
 
235
                                                      PretenureFlag pretenure) {
 
236
  CALL_HEAP_FUNCTION(
 
237
      isolate(),
 
238
      isolate()->heap()->AllocateRawTwoByteString(length, pretenure),
 
239
      SeqTwoByteString);
 
240
}
 
241
 
 
242
 
 
243
Handle<String> Factory::NewConsString(Handle<String> first,
 
244
                                      Handle<String> second) {
 
245
  CALL_HEAP_FUNCTION(isolate(),
 
246
                     isolate()->heap()->AllocateConsString(*first, *second),
 
247
                     String);
 
248
}
 
249
 
 
250
 
 
251
Handle<String> Factory::NewSubString(Handle<String> str,
 
252
                                     int begin,
 
253
                                     int end) {
 
254
  CALL_HEAP_FUNCTION(isolate(),
 
255
                     str->SubString(begin, end),
 
256
                     String);
 
257
}
 
258
 
 
259
 
 
260
Handle<String> Factory::NewProperSubString(Handle<String> str,
 
261
                                           int begin,
 
262
                                           int end) {
 
263
  ASSERT(begin > 0 || end < str->length());
 
264
  CALL_HEAP_FUNCTION(isolate(),
 
265
                     isolate()->heap()->AllocateSubString(*str, begin, end),
 
266
                     String);
 
267
}
 
268
 
 
269
 
 
270
Handle<String> Factory::NewExternalStringFromAscii(
 
271
    const ExternalAsciiString::Resource* resource) {
 
272
  CALL_HEAP_FUNCTION(
 
273
      isolate(),
 
274
      isolate()->heap()->AllocateExternalStringFromAscii(resource),
 
275
      String);
 
276
}
 
277
 
 
278
 
 
279
Handle<String> Factory::NewExternalStringFromTwoByte(
 
280
    const ExternalTwoByteString::Resource* resource) {
 
281
  CALL_HEAP_FUNCTION(
 
282
      isolate(),
 
283
      isolate()->heap()->AllocateExternalStringFromTwoByte(resource),
 
284
      String);
 
285
}
 
286
 
 
287
 
 
288
Handle<Context> Factory::NewGlobalContext() {
 
289
  CALL_HEAP_FUNCTION(
 
290
      isolate(),
 
291
      isolate()->heap()->AllocateGlobalContext(),
 
292
      Context);
 
293
}
 
294
 
 
295
 
 
296
Handle<Context> Factory::NewModuleContext(Handle<ScopeInfo> scope_info) {
 
297
  CALL_HEAP_FUNCTION(
 
298
      isolate(),
 
299
      isolate()->heap()->AllocateModuleContext(*scope_info),
 
300
      Context);
 
301
}
 
302
 
 
303
 
 
304
Handle<Context> Factory::NewFunctionContext(int length,
 
305
                                            Handle<JSFunction> function) {
 
306
  CALL_HEAP_FUNCTION(
 
307
      isolate(),
 
308
      isolate()->heap()->AllocateFunctionContext(length, *function),
 
309
      Context);
 
310
}
 
311
 
 
312
 
 
313
Handle<Context> Factory::NewCatchContext(Handle<JSFunction> function,
 
314
                                         Handle<Context> previous,
 
315
                                         Handle<String> name,
 
316
                                         Handle<Object> thrown_object) {
 
317
  CALL_HEAP_FUNCTION(
 
318
      isolate(),
 
319
      isolate()->heap()->AllocateCatchContext(*function,
 
320
                                              *previous,
 
321
                                              *name,
 
322
                                              *thrown_object),
 
323
      Context);
 
324
}
 
325
 
 
326
 
 
327
Handle<Context> Factory::NewWithContext(Handle<JSFunction> function,
 
328
                                        Handle<Context> previous,
 
329
                                        Handle<JSObject> extension) {
 
330
  CALL_HEAP_FUNCTION(
 
331
      isolate(),
 
332
      isolate()->heap()->AllocateWithContext(*function, *previous, *extension),
 
333
      Context);
 
334
}
 
335
 
 
336
 
 
337
Handle<Context> Factory::NewBlockContext(Handle<JSFunction> function,
 
338
                                         Handle<Context> previous,
 
339
                                         Handle<ScopeInfo> scope_info) {
 
340
  CALL_HEAP_FUNCTION(
 
341
      isolate(),
 
342
      isolate()->heap()->AllocateBlockContext(*function,
 
343
                                              *previous,
 
344
                                              *scope_info),
 
345
      Context);
 
346
}
 
347
 
 
348
 
 
349
Handle<Struct> Factory::NewStruct(InstanceType type) {
 
350
  CALL_HEAP_FUNCTION(
 
351
      isolate(),
 
352
      isolate()->heap()->AllocateStruct(type),
 
353
      Struct);
 
354
}
 
355
 
 
356
 
 
357
Handle<AccessorInfo> Factory::NewAccessorInfo() {
 
358
  Handle<AccessorInfo> info =
 
359
      Handle<AccessorInfo>::cast(NewStruct(ACCESSOR_INFO_TYPE));
 
360
  info->set_flag(0);  // Must clear the flag, it was initialized as undefined.
 
361
  return info;
 
362
}
 
363
 
 
364
 
 
365
Handle<Script> Factory::NewScript(Handle<String> source) {
 
366
  // Generate id for this script.
 
367
  int id;
 
368
  Heap* heap = isolate()->heap();
 
369
  if (heap->last_script_id()->IsUndefined()) {
 
370
    // Script ids start from one.
 
371
    id = 1;
 
372
  } else {
 
373
    // Increment id, wrap when positive smi is exhausted.
 
374
    id = Smi::cast(heap->last_script_id())->value();
 
375
    id++;
 
376
    if (!Smi::IsValid(id)) {
 
377
      id = 0;
 
378
    }
 
379
  }
 
380
  heap->SetLastScriptId(Smi::FromInt(id));
 
381
 
 
382
  // Create and initialize script object.
 
383
  Handle<Foreign> wrapper = NewForeign(0, TENURED);
 
384
  Handle<Script> script = Handle<Script>::cast(NewStruct(SCRIPT_TYPE));
 
385
  script->set_source(*source);
 
386
  script->set_name(heap->undefined_value());
 
387
  script->set_id(heap->last_script_id());
 
388
  script->set_line_offset(Smi::FromInt(0));
 
389
  script->set_column_offset(Smi::FromInt(0));
 
390
  script->set_data(heap->undefined_value());
 
391
  script->set_context_data(heap->undefined_value());
 
392
  script->set_type(Smi::FromInt(Script::TYPE_NORMAL));
 
393
  script->set_compilation_type(Smi::FromInt(Script::COMPILATION_TYPE_HOST));
 
394
  script->set_compilation_state(
 
395
      Smi::FromInt(Script::COMPILATION_STATE_INITIAL));
 
396
  script->set_wrapper(*wrapper);
 
397
  script->set_line_ends(heap->undefined_value());
 
398
  script->set_eval_from_shared(heap->undefined_value());
 
399
  script->set_eval_from_instructions_offset(Smi::FromInt(0));
 
400
 
 
401
  return script;
 
402
}
 
403
 
 
404
 
 
405
Handle<Foreign> Factory::NewForeign(Address addr, PretenureFlag pretenure) {
 
406
  CALL_HEAP_FUNCTION(isolate(),
 
407
                     isolate()->heap()->AllocateForeign(addr, pretenure),
 
408
                     Foreign);
 
409
}
 
410
 
 
411
 
 
412
Handle<Foreign> Factory::NewForeign(const AccessorDescriptor* desc) {
 
413
  return NewForeign((Address) desc, TENURED);
 
414
}
 
415
 
 
416
 
 
417
Handle<ByteArray> Factory::NewByteArray(int length, PretenureFlag pretenure) {
 
418
  ASSERT(0 <= length);
 
419
  CALL_HEAP_FUNCTION(
 
420
      isolate(),
 
421
      isolate()->heap()->AllocateByteArray(length, pretenure),
 
422
      ByteArray);
 
423
}
 
424
 
 
425
 
 
426
Handle<ExternalArray> Factory::NewExternalArray(int length,
 
427
                                                ExternalArrayType array_type,
 
428
                                                void* external_pointer,
 
429
                                                PretenureFlag pretenure) {
 
430
  ASSERT(0 <= length);
 
431
  CALL_HEAP_FUNCTION(
 
432
      isolate(),
 
433
      isolate()->heap()->AllocateExternalArray(length,
 
434
                                               array_type,
 
435
                                               external_pointer,
 
436
                                               pretenure),
 
437
      ExternalArray);
 
438
}
 
439
 
 
440
 
 
441
Handle<JSGlobalPropertyCell> Factory::NewJSGlobalPropertyCell(
 
442
    Handle<Object> value) {
 
443
  CALL_HEAP_FUNCTION(
 
444
      isolate(),
 
445
      isolate()->heap()->AllocateJSGlobalPropertyCell(*value),
 
446
      JSGlobalPropertyCell);
 
447
}
 
448
 
 
449
 
 
450
Handle<Map> Factory::NewMap(InstanceType type,
 
451
                            int instance_size,
 
452
                            ElementsKind elements_kind) {
 
453
  CALL_HEAP_FUNCTION(
 
454
      isolate(),
 
455
      isolate()->heap()->AllocateMap(type, instance_size, elements_kind),
 
456
      Map);
 
457
}
 
458
 
 
459
 
 
460
Handle<JSObject> Factory::NewFunctionPrototype(Handle<JSFunction> function) {
 
461
  CALL_HEAP_FUNCTION(
 
462
      isolate(),
 
463
      isolate()->heap()->AllocateFunctionPrototype(*function),
 
464
      JSObject);
 
465
}
 
466
 
 
467
 
 
468
Handle<Map> Factory::CopyWithPreallocatedFieldDescriptors(Handle<Map> src) {
 
469
  CALL_HEAP_FUNCTION(
 
470
      isolate(), src->CopyWithPreallocatedFieldDescriptors(), Map);
 
471
}
 
472
 
 
473
 
 
474
Handle<Map> Factory::CopyMap(Handle<Map> src,
 
475
                             int extra_inobject_properties) {
 
476
  Handle<Map> copy = CopyWithPreallocatedFieldDescriptors(src);
 
477
  // Check that we do not overflow the instance size when adding the
 
478
  // extra inobject properties.
 
479
  int instance_size_delta = extra_inobject_properties * kPointerSize;
 
480
  int max_instance_size_delta =
 
481
      JSObject::kMaxInstanceSize - copy->instance_size();
 
482
  if (instance_size_delta > max_instance_size_delta) {
 
483
    // If the instance size overflows, we allocate as many properties
 
484
    // as we can as inobject properties.
 
485
    instance_size_delta = max_instance_size_delta;
 
486
    extra_inobject_properties = max_instance_size_delta >> kPointerSizeLog2;
 
487
  }
 
488
  // Adjust the map with the extra inobject properties.
 
489
  int inobject_properties =
 
490
      copy->inobject_properties() + extra_inobject_properties;
 
491
  copy->set_inobject_properties(inobject_properties);
 
492
  copy->set_unused_property_fields(inobject_properties);
 
493
  copy->set_instance_size(copy->instance_size() + instance_size_delta);
 
494
  copy->set_visitor_id(StaticVisitorBase::GetVisitorId(*copy));
 
495
  return copy;
 
496
}
 
497
 
 
498
 
 
499
Handle<Map> Factory::CopyMap(Handle<Map> src) {
 
500
  CALL_HEAP_FUNCTION(isolate(), src->Copy(DescriptorArray::MAY_BE_SHARED), Map);
 
501
}
 
502
 
 
503
 
 
504
Handle<Map> Factory::GetElementsTransitionMap(
 
505
    Handle<JSObject> src,
 
506
    ElementsKind elements_kind) {
 
507
  Isolate* i = isolate();
 
508
  CALL_HEAP_FUNCTION(i,
 
509
                     src->GetElementsTransitionMap(i, elements_kind),
 
510
                     Map);
 
511
}
 
512
 
 
513
 
 
514
Handle<FixedArray> Factory::CopyFixedArray(Handle<FixedArray> array) {
 
515
  CALL_HEAP_FUNCTION(isolate(), array->Copy(), FixedArray);
 
516
}
 
517
 
 
518
 
 
519
Handle<FixedDoubleArray> Factory::CopyFixedDoubleArray(
 
520
    Handle<FixedDoubleArray> array) {
 
521
  CALL_HEAP_FUNCTION(isolate(), array->Copy(), FixedDoubleArray);
 
522
}
 
523
 
 
524
 
 
525
Handle<JSFunction> Factory::BaseNewFunctionFromSharedFunctionInfo(
 
526
    Handle<SharedFunctionInfo> function_info,
 
527
    Handle<Map> function_map,
 
528
    PretenureFlag pretenure) {
 
529
  CALL_HEAP_FUNCTION(
 
530
      isolate(),
 
531
      isolate()->heap()->AllocateFunction(*function_map,
 
532
                                          *function_info,
 
533
                                          isolate()->heap()->the_hole_value(),
 
534
                                          pretenure),
 
535
                     JSFunction);
 
536
}
 
537
 
 
538
 
 
539
Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo(
 
540
    Handle<SharedFunctionInfo> function_info,
 
541
    Handle<Context> context,
 
542
    PretenureFlag pretenure) {
 
543
  Handle<JSFunction> result = BaseNewFunctionFromSharedFunctionInfo(
 
544
      function_info,
 
545
      function_info->is_classic_mode()
 
546
          ? isolate()->function_map()
 
547
          : isolate()->strict_mode_function_map(),
 
548
      pretenure);
 
549
 
 
550
  if (function_info->ic_age() != isolate()->heap()->global_ic_age()) {
 
551
    function_info->ResetForNewContext(isolate()->heap()->global_ic_age());
 
552
  }
 
553
 
 
554
  result->set_context(*context);
 
555
 
 
556
  int index = function_info->SearchOptimizedCodeMap(context->global_context());
 
557
  if (!function_info->bound() && index < 0) {
 
558
    int number_of_literals = function_info->num_literals();
 
559
    Handle<FixedArray> literals = NewFixedArray(number_of_literals, pretenure);
 
560
    if (number_of_literals > 0) {
 
561
      // Store the global context in the literals array prefix. This
 
562
      // context will be used when creating object, regexp and array
 
563
      // literals in this function.
 
564
      literals->set(JSFunction::kLiteralGlobalContextIndex,
 
565
                    context->global_context());
 
566
    }
 
567
    result->set_literals(*literals);
 
568
  }
 
569
 
 
570
  if (index > 0) {
 
571
    // Caching of optimized code enabled and optimized code found.
 
572
    function_info->InstallFromOptimizedCodeMap(*result, index);
 
573
    return result;
 
574
  }
 
575
 
 
576
  if (V8::UseCrankshaft() &&
 
577
      FLAG_always_opt &&
 
578
      result->is_compiled() &&
 
579
      !function_info->is_toplevel() &&
 
580
      function_info->allows_lazy_compilation() &&
 
581
      !function_info->optimization_disabled()) {
 
582
    result->MarkForLazyRecompilation();
 
583
  }
 
584
  return result;
 
585
}
 
586
 
 
587
 
 
588
Handle<Object> Factory::NewNumber(double value,
 
589
                                  PretenureFlag pretenure) {
 
590
  CALL_HEAP_FUNCTION(
 
591
      isolate(),
 
592
      isolate()->heap()->NumberFromDouble(value, pretenure), Object);
 
593
}
 
594
 
 
595
 
 
596
Handle<Object> Factory::NewNumberFromInt(int32_t value,
 
597
                                         PretenureFlag pretenure) {
 
598
  CALL_HEAP_FUNCTION(
 
599
      isolate(),
 
600
      isolate()->heap()->NumberFromInt32(value, pretenure), Object);
 
601
}
 
602
 
 
603
 
 
604
Handle<Object> Factory::NewNumberFromUint(uint32_t value,
 
605
                                         PretenureFlag pretenure) {
 
606
  CALL_HEAP_FUNCTION(
 
607
      isolate(),
 
608
      isolate()->heap()->NumberFromUint32(value, pretenure), Object);
 
609
}
 
610
 
 
611
 
 
612
Handle<JSObject> Factory::NewNeanderObject() {
 
613
  CALL_HEAP_FUNCTION(
 
614
      isolate(),
 
615
      isolate()->heap()->AllocateJSObjectFromMap(
 
616
          isolate()->heap()->neander_map()),
 
617
      JSObject);
 
618
}
 
619
 
 
620
 
 
621
Handle<Object> Factory::NewTypeError(const char* type,
 
622
                                     Vector< Handle<Object> > args) {
 
623
  return NewError("MakeTypeError", type, args);
 
624
}
 
625
 
 
626
 
 
627
Handle<Object> Factory::NewTypeError(Handle<String> message) {
 
628
  return NewError("$TypeError", message);
 
629
}
 
630
 
 
631
 
 
632
Handle<Object> Factory::NewRangeError(const char* type,
 
633
                                      Vector< Handle<Object> > args) {
 
634
  return NewError("MakeRangeError", type, args);
 
635
}
 
636
 
 
637
 
 
638
Handle<Object> Factory::NewRangeError(Handle<String> message) {
 
639
  return NewError("$RangeError", message);
 
640
}
 
641
 
 
642
 
 
643
Handle<Object> Factory::NewSyntaxError(const char* type, Handle<JSArray> args) {
 
644
  return NewError("MakeSyntaxError", type, args);
 
645
}
 
646
 
 
647
 
 
648
Handle<Object> Factory::NewSyntaxError(Handle<String> message) {
 
649
  return NewError("$SyntaxError", message);
 
650
}
 
651
 
 
652
 
 
653
Handle<Object> Factory::NewReferenceError(const char* type,
 
654
                                          Vector< Handle<Object> > args) {
 
655
  return NewError("MakeReferenceError", type, args);
 
656
}
 
657
 
 
658
 
 
659
Handle<Object> Factory::NewReferenceError(Handle<String> message) {
 
660
  return NewError("$ReferenceError", message);
 
661
}
 
662
 
 
663
 
 
664
Handle<Object> Factory::NewError(const char* maker, const char* type,
 
665
    Vector< Handle<Object> > args) {
 
666
  v8::HandleScope scope;  // Instantiate a closeable HandleScope for EscapeFrom.
 
667
  Handle<FixedArray> array = NewFixedArray(args.length());
 
668
  for (int i = 0; i < args.length(); i++) {
 
669
    array->set(i, *args[i]);
 
670
  }
 
671
  Handle<JSArray> object = NewJSArrayWithElements(array);
 
672
  Handle<Object> result = NewError(maker, type, object);
 
673
  return result.EscapeFrom(&scope);
 
674
}
 
675
 
 
676
 
 
677
Handle<Object> Factory::NewEvalError(const char* type,
 
678
                                     Vector< Handle<Object> > args) {
 
679
  return NewError("MakeEvalError", type, args);
 
680
}
 
681
 
 
682
 
 
683
Handle<Object> Factory::NewError(const char* type,
 
684
                                 Vector< Handle<Object> > args) {
 
685
  return NewError("MakeError", type, args);
 
686
}
 
687
 
 
688
 
 
689
Handle<String> Factory::EmergencyNewError(const char* type,
 
690
                                          Handle<JSArray> args) {
 
691
  const int kBufferSize = 1000;
 
692
  char buffer[kBufferSize];
 
693
  size_t space = kBufferSize;
 
694
  char* p = &buffer[0];
 
695
 
 
696
  Vector<char> v(buffer, kBufferSize);
 
697
  OS::StrNCpy(v, type, space);
 
698
  space -= Min(space, strlen(type));
 
699
  p = &buffer[kBufferSize] - space;
 
700
 
 
701
  for (unsigned i = 0; i < ARRAY_SIZE(args); i++) {
 
702
    if (space > 0) {
 
703
      *p++ = ' ';
 
704
      space--;
 
705
      if (space > 0) {
 
706
        MaybeObject* maybe_arg = args->GetElement(i);
 
707
        Handle<String> arg_str(reinterpret_cast<String*>(maybe_arg));
 
708
        const char* arg = *arg_str->ToCString();
 
709
        Vector<char> v2(p, static_cast<int>(space));
 
710
        OS::StrNCpy(v2, arg, space);
 
711
        space -= Min(space, strlen(arg));
 
712
        p = &buffer[kBufferSize] - space;
 
713
      }
 
714
    }
 
715
  }
 
716
  if (space > 0) {
 
717
    *p = '\0';
 
718
  } else {
 
719
    buffer[kBufferSize - 1] = '\0';
 
720
  }
 
721
  Handle<String> error_string = NewStringFromUtf8(CStrVector(buffer), TENURED);
 
722
  return error_string;
 
723
}
 
724
 
 
725
 
 
726
Handle<Object> Factory::NewError(const char* maker,
 
727
                                 const char* type,
 
728
                                 Handle<JSArray> args) {
 
729
  Handle<String> make_str = LookupAsciiSymbol(maker);
 
730
  Handle<Object> fun_obj(
 
731
      isolate()->js_builtins_object()->GetPropertyNoExceptionThrown(*make_str));
 
732
  // If the builtins haven't been properly configured yet this error
 
733
  // constructor may not have been defined.  Bail out.
 
734
  if (!fun_obj->IsJSFunction()) {
 
735
    return EmergencyNewError(type, args);
 
736
  }
 
737
  Handle<JSFunction> fun = Handle<JSFunction>::cast(fun_obj);
 
738
  Handle<Object> type_obj = LookupAsciiSymbol(type);
 
739
  Handle<Object> argv[] = { type_obj, args };
 
740
 
 
741
  // Invoke the JavaScript factory method. If an exception is thrown while
 
742
  // running the factory method, use the exception as the result.
 
743
  bool caught_exception;
 
744
  Handle<Object> result = Execution::TryCall(fun,
 
745
                                             isolate()->js_builtins_object(),
 
746
                                             ARRAY_SIZE(argv),
 
747
                                             argv,
 
748
                                             &caught_exception);
 
749
  return result;
 
750
}
 
751
 
 
752
 
 
753
Handle<Object> Factory::NewError(Handle<String> message) {
 
754
  return NewError("$Error", message);
 
755
}
 
756
 
 
757
 
 
758
Handle<Object> Factory::NewError(const char* constructor,
 
759
                                 Handle<String> message) {
 
760
  Handle<String> constr = LookupAsciiSymbol(constructor);
 
761
  Handle<JSFunction> fun = Handle<JSFunction>(
 
762
      JSFunction::cast(isolate()->js_builtins_object()->
 
763
                       GetPropertyNoExceptionThrown(*constr)));
 
764
  Handle<Object> argv[] = { message };
 
765
 
 
766
  // Invoke the JavaScript factory method. If an exception is thrown while
 
767
  // running the factory method, use the exception as the result.
 
768
  bool caught_exception;
 
769
  Handle<Object> result = Execution::TryCall(fun,
 
770
                                             isolate()->js_builtins_object(),
 
771
                                             ARRAY_SIZE(argv),
 
772
                                             argv,
 
773
                                             &caught_exception);
 
774
  return result;
 
775
}
 
776
 
 
777
 
 
778
Handle<JSFunction> Factory::NewFunction(Handle<String> name,
 
779
                                        InstanceType type,
 
780
                                        int instance_size,
 
781
                                        Handle<Code> code,
 
782
                                        bool force_initial_map) {
 
783
  // Allocate the function
 
784
  Handle<JSFunction> function = NewFunction(name, the_hole_value());
 
785
 
 
786
  // Set up the code pointer in both the shared function info and in
 
787
  // the function itself.
 
788
  function->shared()->set_code(*code);
 
789
  function->set_code(*code);
 
790
 
 
791
  if (force_initial_map ||
 
792
      type != JS_OBJECT_TYPE ||
 
793
      instance_size != JSObject::kHeaderSize) {
 
794
    Handle<Map> initial_map = NewMap(type, instance_size);
 
795
    Handle<JSObject> prototype = NewFunctionPrototype(function);
 
796
    initial_map->set_prototype(*prototype);
 
797
    function->set_initial_map(*initial_map);
 
798
    initial_map->set_constructor(*function);
 
799
  } else {
 
800
    ASSERT(!function->has_initial_map());
 
801
    ASSERT(!function->has_prototype());
 
802
  }
 
803
 
 
804
  return function;
 
805
}
 
806
 
 
807
 
 
808
Handle<JSFunction> Factory::NewFunctionWithPrototype(Handle<String> name,
 
809
                                                     InstanceType type,
 
810
                                                     int instance_size,
 
811
                                                     Handle<JSObject> prototype,
 
812
                                                     Handle<Code> code,
 
813
                                                     bool force_initial_map) {
 
814
  // Allocate the function.
 
815
  Handle<JSFunction> function = NewFunction(name, prototype);
 
816
 
 
817
  // Set up the code pointer in both the shared function info and in
 
818
  // the function itself.
 
819
  function->shared()->set_code(*code);
 
820
  function->set_code(*code);
 
821
 
 
822
  if (force_initial_map ||
 
823
      type != JS_OBJECT_TYPE ||
 
824
      instance_size != JSObject::kHeaderSize) {
 
825
    Handle<Map> initial_map = NewMap(type,
 
826
                                     instance_size,
 
827
                                     GetInitialFastElementsKind());
 
828
    function->set_initial_map(*initial_map);
 
829
    initial_map->set_constructor(*function);
 
830
  }
 
831
 
 
832
  // Set function.prototype and give the prototype a constructor
 
833
  // property that refers to the function.
 
834
  SetPrototypeProperty(function, prototype);
 
835
  // Currently safe because it is only invoked from Genesis.
 
836
  CHECK_NOT_EMPTY_HANDLE(isolate(),
 
837
                         JSObject::SetLocalPropertyIgnoreAttributes(
 
838
                             prototype, constructor_symbol(),
 
839
                             function, DONT_ENUM));
 
840
  return function;
 
841
}
 
842
 
 
843
 
 
844
Handle<JSFunction> Factory::NewFunctionWithoutPrototype(Handle<String> name,
 
845
                                                        Handle<Code> code) {
 
846
  Handle<JSFunction> function = NewFunctionWithoutPrototype(name,
 
847
                                                            CLASSIC_MODE);
 
848
  function->shared()->set_code(*code);
 
849
  function->set_code(*code);
 
850
  ASSERT(!function->has_initial_map());
 
851
  ASSERT(!function->has_prototype());
 
852
  return function;
 
853
}
 
854
 
 
855
 
 
856
Handle<ScopeInfo> Factory::NewScopeInfo(int length) {
 
857
  CALL_HEAP_FUNCTION(
 
858
      isolate(),
 
859
      isolate()->heap()->AllocateScopeInfo(length),
 
860
      ScopeInfo);
 
861
}
 
862
 
 
863
 
 
864
Handle<Code> Factory::NewCode(const CodeDesc& desc,
 
865
                              Code::Flags flags,
 
866
                              Handle<Object> self_ref,
 
867
                              bool immovable) {
 
868
  CALL_HEAP_FUNCTION(isolate(),
 
869
                     isolate()->heap()->CreateCode(
 
870
                         desc, flags, self_ref, immovable),
 
871
                     Code);
 
872
}
 
873
 
 
874
 
 
875
Handle<Code> Factory::CopyCode(Handle<Code> code) {
 
876
  CALL_HEAP_FUNCTION(isolate(),
 
877
                     isolate()->heap()->CopyCode(*code),
 
878
                     Code);
 
879
}
 
880
 
 
881
 
 
882
Handle<Code> Factory::CopyCode(Handle<Code> code, Vector<byte> reloc_info) {
 
883
  CALL_HEAP_FUNCTION(isolate(),
 
884
                     isolate()->heap()->CopyCode(*code, reloc_info),
 
885
                     Code);
 
886
}
 
887
 
 
888
 
 
889
Handle<String> Factory::SymbolFromString(Handle<String> value) {
 
890
  CALL_HEAP_FUNCTION(isolate(),
 
891
                     isolate()->heap()->LookupSymbol(*value), String);
 
892
}
 
893
 
 
894
 
 
895
Handle<JSObject> Factory::NewJSObject(Handle<JSFunction> constructor,
 
896
                                      PretenureFlag pretenure) {
 
897
  CALL_HEAP_FUNCTION(
 
898
      isolate(),
 
899
      isolate()->heap()->AllocateJSObject(*constructor, pretenure), JSObject);
 
900
}
 
901
 
 
902
 
 
903
Handle<JSModule> Factory::NewJSModule(Handle<Context> context,
 
904
                                      Handle<ScopeInfo> scope_info) {
 
905
  CALL_HEAP_FUNCTION(
 
906
      isolate(),
 
907
      isolate()->heap()->AllocateJSModule(*context, *scope_info), JSModule);
 
908
}
 
909
 
 
910
 
 
911
Handle<GlobalObject> Factory::NewGlobalObject(
 
912
    Handle<JSFunction> constructor) {
 
913
  CALL_HEAP_FUNCTION(isolate(),
 
914
                     isolate()->heap()->AllocateGlobalObject(*constructor),
 
915
                     GlobalObject);
 
916
}
 
917
 
 
918
 
 
919
 
 
920
Handle<JSObject> Factory::NewJSObjectFromMap(Handle<Map> map) {
 
921
  CALL_HEAP_FUNCTION(
 
922
      isolate(),
 
923
      isolate()->heap()->AllocateJSObjectFromMap(*map, NOT_TENURED),
 
924
      JSObject);
 
925
}
 
926
 
 
927
 
 
928
Handle<JSArray> Factory::NewJSArray(int capacity,
 
929
                                    ElementsKind elements_kind,
 
930
                                    PretenureFlag pretenure) {
 
931
  CALL_HEAP_FUNCTION(isolate(),
 
932
                     isolate()->heap()->AllocateJSArrayAndStorage(
 
933
                         elements_kind,
 
934
                         0,
 
935
                         capacity,
 
936
                         INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE,
 
937
                         pretenure),
 
938
                     JSArray);
 
939
}
 
940
 
 
941
 
 
942
Handle<JSArray> Factory::NewJSArrayWithElements(Handle<FixedArrayBase> elements,
 
943
                                                ElementsKind elements_kind,
 
944
                                                PretenureFlag pretenure) {
 
945
  CALL_HEAP_FUNCTION(
 
946
      isolate(),
 
947
      isolate()->heap()->AllocateJSArrayWithElements(*elements,
 
948
                                                     elements_kind,
 
949
                                                     pretenure),
 
950
      JSArray);
 
951
}
 
952
 
 
953
 
 
954
void Factory::SetElementsCapacityAndLength(Handle<JSArray> array,
 
955
                                           int capacity,
 
956
                                           int length) {
 
957
  ElementsAccessor* accessor = array->GetElementsAccessor();
 
958
  CALL_HEAP_FUNCTION_VOID(
 
959
      isolate(),
 
960
      accessor->SetCapacityAndLength(*array, capacity, length));
 
961
}
 
962
 
 
963
 
 
964
void Factory::SetContent(Handle<JSArray> array,
 
965
                         Handle<FixedArrayBase> elements) {
 
966
  CALL_HEAP_FUNCTION_VOID(
 
967
      isolate(),
 
968
      array->SetContent(*elements));
 
969
}
 
970
 
 
971
 
 
972
void Factory::EnsureCanContainHeapObjectElements(Handle<JSArray> array) {
 
973
  CALL_HEAP_FUNCTION_VOID(
 
974
      isolate(),
 
975
      array->EnsureCanContainHeapObjectElements());
 
976
}
 
977
 
 
978
 
 
979
void Factory::EnsureCanContainElements(Handle<JSArray> array,
 
980
                                       Handle<FixedArrayBase> elements,
 
981
                                       uint32_t length,
 
982
                                       EnsureElementsMode mode) {
 
983
  CALL_HEAP_FUNCTION_VOID(
 
984
      isolate(),
 
985
      array->EnsureCanContainElements(*elements, length, mode));
 
986
}
 
987
 
 
988
 
 
989
Handle<JSProxy> Factory::NewJSProxy(Handle<Object> handler,
 
990
                                    Handle<Object> prototype) {
 
991
  CALL_HEAP_FUNCTION(
 
992
      isolate(),
 
993
      isolate()->heap()->AllocateJSProxy(*handler, *prototype),
 
994
      JSProxy);
 
995
}
 
996
 
 
997
 
 
998
void Factory::BecomeJSObject(Handle<JSReceiver> object) {
 
999
  CALL_HEAP_FUNCTION_VOID(
 
1000
      isolate(),
 
1001
      isolate()->heap()->ReinitializeJSReceiver(
 
1002
          *object, JS_OBJECT_TYPE, JSObject::kHeaderSize));
 
1003
}
 
1004
 
 
1005
 
 
1006
void Factory::BecomeJSFunction(Handle<JSReceiver> object) {
 
1007
  CALL_HEAP_FUNCTION_VOID(
 
1008
      isolate(),
 
1009
      isolate()->heap()->ReinitializeJSReceiver(
 
1010
          *object, JS_FUNCTION_TYPE, JSFunction::kSize));
 
1011
}
 
1012
 
 
1013
 
 
1014
void Factory::SetIdentityHash(Handle<JSObject> object, Smi* hash) {
 
1015
  CALL_HEAP_FUNCTION_VOID(
 
1016
      isolate(),
 
1017
      object->SetIdentityHash(hash, ALLOW_CREATION));
 
1018
}
 
1019
 
 
1020
 
 
1021
Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo(
 
1022
    Handle<String> name,
 
1023
    int number_of_literals,
 
1024
    Handle<Code> code,
 
1025
    Handle<ScopeInfo> scope_info) {
 
1026
  Handle<SharedFunctionInfo> shared = NewSharedFunctionInfo(name);
 
1027
  shared->set_code(*code);
 
1028
  shared->set_scope_info(*scope_info);
 
1029
  int literals_array_size = number_of_literals;
 
1030
  // If the function contains object, regexp or array literals,
 
1031
  // allocate extra space for a literals array prefix containing the
 
1032
  // context.
 
1033
  if (number_of_literals > 0) {
 
1034
    literals_array_size += JSFunction::kLiteralsPrefixSize;
 
1035
  }
 
1036
  shared->set_num_literals(literals_array_size);
 
1037
  return shared;
 
1038
}
 
1039
 
 
1040
 
 
1041
Handle<JSMessageObject> Factory::NewJSMessageObject(
 
1042
    Handle<String> type,
 
1043
    Handle<JSArray> arguments,
 
1044
    int start_position,
 
1045
    int end_position,
 
1046
    Handle<Object> script,
 
1047
    Handle<Object> stack_trace,
 
1048
    Handle<Object> stack_frames) {
 
1049
  CALL_HEAP_FUNCTION(isolate(),
 
1050
                     isolate()->heap()->AllocateJSMessageObject(*type,
 
1051
                         *arguments,
 
1052
                         start_position,
 
1053
                         end_position,
 
1054
                         *script,
 
1055
                         *stack_trace,
 
1056
                         *stack_frames),
 
1057
                     JSMessageObject);
 
1058
}
 
1059
 
 
1060
Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo(Handle<String> name) {
 
1061
  CALL_HEAP_FUNCTION(isolate(),
 
1062
                     isolate()->heap()->AllocateSharedFunctionInfo(*name),
 
1063
                     SharedFunctionInfo);
 
1064
}
 
1065
 
 
1066
 
 
1067
Handle<String> Factory::NumberToString(Handle<Object> number) {
 
1068
  CALL_HEAP_FUNCTION(isolate(),
 
1069
                     isolate()->heap()->NumberToString(*number), String);
 
1070
}
 
1071
 
 
1072
 
 
1073
Handle<String> Factory::Uint32ToString(uint32_t value) {
 
1074
  CALL_HEAP_FUNCTION(isolate(),
 
1075
                     isolate()->heap()->Uint32ToString(value), String);
 
1076
}
 
1077
 
 
1078
 
 
1079
Handle<SeededNumberDictionary> Factory::DictionaryAtNumberPut(
 
1080
    Handle<SeededNumberDictionary> dictionary,
 
1081
    uint32_t key,
 
1082
    Handle<Object> value) {
 
1083
  CALL_HEAP_FUNCTION(isolate(),
 
1084
                     dictionary->AtNumberPut(key, *value),
 
1085
                     SeededNumberDictionary);
 
1086
}
 
1087
 
 
1088
 
 
1089
Handle<UnseededNumberDictionary> Factory::DictionaryAtNumberPut(
 
1090
    Handle<UnseededNumberDictionary> dictionary,
 
1091
    uint32_t key,
 
1092
    Handle<Object> value) {
 
1093
  CALL_HEAP_FUNCTION(isolate(),
 
1094
                     dictionary->AtNumberPut(key, *value),
 
1095
                     UnseededNumberDictionary);
 
1096
}
 
1097
 
 
1098
 
 
1099
Handle<JSFunction> Factory::NewFunctionHelper(Handle<String> name,
 
1100
                                              Handle<Object> prototype) {
 
1101
  Handle<SharedFunctionInfo> function_share = NewSharedFunctionInfo(name);
 
1102
  CALL_HEAP_FUNCTION(
 
1103
      isolate(),
 
1104
      isolate()->heap()->AllocateFunction(*isolate()->function_map(),
 
1105
                                          *function_share,
 
1106
                                          *prototype),
 
1107
      JSFunction);
 
1108
}
 
1109
 
 
1110
 
 
1111
Handle<JSFunction> Factory::NewFunction(Handle<String> name,
 
1112
                                        Handle<Object> prototype) {
 
1113
  Handle<JSFunction> fun = NewFunctionHelper(name, prototype);
 
1114
  fun->set_context(isolate()->context()->global_context());
 
1115
  return fun;
 
1116
}
 
1117
 
 
1118
 
 
1119
Handle<JSFunction> Factory::NewFunctionWithoutPrototypeHelper(
 
1120
    Handle<String> name,
 
1121
    LanguageMode language_mode) {
 
1122
  Handle<SharedFunctionInfo> function_share = NewSharedFunctionInfo(name);
 
1123
  Handle<Map> map = (language_mode == CLASSIC_MODE)
 
1124
      ? isolate()->function_without_prototype_map()
 
1125
      : isolate()->strict_mode_function_without_prototype_map();
 
1126
  CALL_HEAP_FUNCTION(isolate(),
 
1127
                     isolate()->heap()->AllocateFunction(
 
1128
                         *map,
 
1129
                         *function_share,
 
1130
                         *the_hole_value()),
 
1131
                     JSFunction);
 
1132
}
 
1133
 
 
1134
 
 
1135
Handle<JSFunction> Factory::NewFunctionWithoutPrototype(
 
1136
    Handle<String> name,
 
1137
    LanguageMode language_mode) {
 
1138
  Handle<JSFunction> fun =
 
1139
      NewFunctionWithoutPrototypeHelper(name, language_mode);
 
1140
  fun->set_context(isolate()->context()->global_context());
 
1141
  return fun;
 
1142
}
 
1143
 
 
1144
 
 
1145
Handle<Object> Factory::ToObject(Handle<Object> object) {
 
1146
  CALL_HEAP_FUNCTION(isolate(), object->ToObject(), Object);
 
1147
}
 
1148
 
 
1149
 
 
1150
Handle<Object> Factory::ToObject(Handle<Object> object,
 
1151
                                 Handle<Context> global_context) {
 
1152
  CALL_HEAP_FUNCTION(isolate(), object->ToObject(*global_context), Object);
 
1153
}
 
1154
 
 
1155
 
 
1156
#ifdef ENABLE_DEBUGGER_SUPPORT
 
1157
Handle<DebugInfo> Factory::NewDebugInfo(Handle<SharedFunctionInfo> shared) {
 
1158
  // Get the original code of the function.
 
1159
  Handle<Code> code(shared->code());
 
1160
 
 
1161
  // Create a copy of the code before allocating the debug info object to avoid
 
1162
  // allocation while setting up the debug info object.
 
1163
  Handle<Code> original_code(*Factory::CopyCode(code));
 
1164
 
 
1165
  // Allocate initial fixed array for active break points before allocating the
 
1166
  // debug info object to avoid allocation while setting up the debug info
 
1167
  // object.
 
1168
  Handle<FixedArray> break_points(
 
1169
      NewFixedArray(Debug::kEstimatedNofBreakPointsInFunction));
 
1170
 
 
1171
  // Create and set up the debug info object. Debug info contains function, a
 
1172
  // copy of the original code, the executing code and initial fixed array for
 
1173
  // active break points.
 
1174
  Handle<DebugInfo> debug_info =
 
1175
      Handle<DebugInfo>::cast(NewStruct(DEBUG_INFO_TYPE));
 
1176
  debug_info->set_shared(*shared);
 
1177
  debug_info->set_original_code(*original_code);
 
1178
  debug_info->set_code(*code);
 
1179
  debug_info->set_break_points(*break_points);
 
1180
 
 
1181
  // Link debug info to function.
 
1182
  shared->set_debug_info(*debug_info);
 
1183
 
 
1184
  return debug_info;
 
1185
}
 
1186
#endif
 
1187
 
 
1188
 
 
1189
Handle<JSObject> Factory::NewArgumentsObject(Handle<Object> callee,
 
1190
                                             int length) {
 
1191
  CALL_HEAP_FUNCTION(
 
1192
      isolate(),
 
1193
      isolate()->heap()->AllocateArgumentsObject(*callee, length), JSObject);
 
1194
}
 
1195
 
 
1196
 
 
1197
Handle<JSFunction> Factory::CreateApiFunction(
 
1198
    Handle<FunctionTemplateInfo> obj, ApiInstanceType instance_type) {
 
1199
  Handle<Code> code = isolate()->builtins()->HandleApiCall();
 
1200
  Handle<Code> construct_stub = isolate()->builtins()->JSConstructStubApi();
 
1201
 
 
1202
  int internal_field_count = 0;
 
1203
  if (!obj->instance_template()->IsUndefined()) {
 
1204
    Handle<ObjectTemplateInfo> instance_template =
 
1205
        Handle<ObjectTemplateInfo>(
 
1206
            ObjectTemplateInfo::cast(obj->instance_template()));
 
1207
    internal_field_count =
 
1208
        Smi::cast(instance_template->internal_field_count())->value();
 
1209
  }
 
1210
 
 
1211
  int instance_size = kPointerSize * internal_field_count;
 
1212
  InstanceType type = INVALID_TYPE;
 
1213
  switch (instance_type) {
 
1214
    case JavaScriptObject:
 
1215
      type = JS_OBJECT_TYPE;
 
1216
      instance_size += JSObject::kHeaderSize;
 
1217
      break;
 
1218
    case InnerGlobalObject:
 
1219
      type = JS_GLOBAL_OBJECT_TYPE;
 
1220
      instance_size += JSGlobalObject::kSize;
 
1221
      break;
 
1222
    case OuterGlobalObject:
 
1223
      type = JS_GLOBAL_PROXY_TYPE;
 
1224
      instance_size += JSGlobalProxy::kSize;
 
1225
      break;
 
1226
    default:
 
1227
      break;
 
1228
  }
 
1229
  ASSERT(type != INVALID_TYPE);
 
1230
 
 
1231
  Handle<JSFunction> result =
 
1232
      NewFunction(Factory::empty_symbol(),
 
1233
                  type,
 
1234
                  instance_size,
 
1235
                  code,
 
1236
                  true);
 
1237
  // Set class name.
 
1238
  Handle<Object> class_name = Handle<Object>(obj->class_name());
 
1239
  if (class_name->IsString()) {
 
1240
    result->shared()->set_instance_class_name(*class_name);
 
1241
    result->shared()->set_name(*class_name);
 
1242
  }
 
1243
 
 
1244
  Handle<Map> map = Handle<Map>(result->initial_map());
 
1245
 
 
1246
  // Mark as undetectable if needed.
 
1247
  if (obj->undetectable()) {
 
1248
    map->set_is_undetectable();
 
1249
  }
 
1250
 
 
1251
  // Mark as hidden for the __proto__ accessor if needed.
 
1252
  if (obj->hidden_prototype()) {
 
1253
    map->set_is_hidden_prototype();
 
1254
  }
 
1255
 
 
1256
  // Mark as needs_access_check if needed.
 
1257
  if (obj->needs_access_check()) {
 
1258
    map->set_is_access_check_needed(true);
 
1259
  }
 
1260
 
 
1261
  // Set interceptor information in the map.
 
1262
  if (!obj->named_property_handler()->IsUndefined()) {
 
1263
    map->set_has_named_interceptor();
 
1264
  }
 
1265
  if (!obj->indexed_property_handler()->IsUndefined()) {
 
1266
    map->set_has_indexed_interceptor();
 
1267
  }
 
1268
 
 
1269
  // Set instance call-as-function information in the map.
 
1270
  if (!obj->instance_call_handler()->IsUndefined()) {
 
1271
    map->set_has_instance_call_handler();
 
1272
  }
 
1273
 
 
1274
  result->shared()->set_function_data(*obj);
 
1275
  result->shared()->set_construct_stub(*construct_stub);
 
1276
  result->shared()->DontAdaptArguments();
 
1277
 
 
1278
  // Recursively copy parent templates' accessors, 'data' may be modified.
 
1279
  while (true) {
 
1280
    Handle<Object> props = Handle<Object>(obj->property_accessors());
 
1281
    if (!props->IsUndefined()) {
 
1282
      Map::CopyAppendCallbackDescriptors(map, props);
 
1283
    }
 
1284
    Handle<Object> parent = Handle<Object>(obj->parent_template());
 
1285
    if (parent->IsUndefined()) break;
 
1286
    obj = Handle<FunctionTemplateInfo>::cast(parent);
 
1287
  }
 
1288
 
 
1289
  ASSERT(result->shared()->IsApiFunction());
 
1290
  return result;
 
1291
}
 
1292
 
 
1293
 
 
1294
Handle<MapCache> Factory::NewMapCache(int at_least_space_for) {
 
1295
  CALL_HEAP_FUNCTION(isolate(),
 
1296
                     MapCache::Allocate(at_least_space_for), MapCache);
 
1297
}
 
1298
 
 
1299
 
 
1300
MUST_USE_RESULT static MaybeObject* UpdateMapCacheWith(Context* context,
 
1301
                                                       FixedArray* keys,
 
1302
                                                       Map* map) {
 
1303
  Object* result;
 
1304
  { MaybeObject* maybe_result =
 
1305
        MapCache::cast(context->map_cache())->Put(keys, map);
 
1306
    if (!maybe_result->ToObject(&result)) return maybe_result;
 
1307
  }
 
1308
  context->set_map_cache(MapCache::cast(result));
 
1309
  return result;
 
1310
}
 
1311
 
 
1312
 
 
1313
Handle<MapCache> Factory::AddToMapCache(Handle<Context> context,
 
1314
                                        Handle<FixedArray> keys,
 
1315
                                        Handle<Map> map) {
 
1316
  CALL_HEAP_FUNCTION(isolate(),
 
1317
                     UpdateMapCacheWith(*context, *keys, *map), MapCache);
 
1318
}
 
1319
 
 
1320
 
 
1321
Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> context,
 
1322
                                               Handle<FixedArray> keys) {
 
1323
  if (context->map_cache()->IsUndefined()) {
 
1324
    // Allocate the new map cache for the global context.
 
1325
    Handle<MapCache> new_cache = NewMapCache(24);
 
1326
    context->set_map_cache(*new_cache);
 
1327
  }
 
1328
  // Check to see whether there is a matching element in the cache.
 
1329
  Handle<MapCache> cache =
 
1330
      Handle<MapCache>(MapCache::cast(context->map_cache()));
 
1331
  Handle<Object> result = Handle<Object>(cache->Lookup(*keys));
 
1332
  if (result->IsMap()) return Handle<Map>::cast(result);
 
1333
  // Create a new map and add it to the cache.
 
1334
  Handle<Map> map =
 
1335
      CopyMap(Handle<Map>(context->object_function()->initial_map()),
 
1336
              keys->length());
 
1337
  AddToMapCache(context, keys, map);
 
1338
  return Handle<Map>(map);
 
1339
}
 
1340
 
 
1341
 
 
1342
void Factory::SetRegExpAtomData(Handle<JSRegExp> regexp,
 
1343
                                JSRegExp::Type type,
 
1344
                                Handle<String> source,
 
1345
                                JSRegExp::Flags flags,
 
1346
                                Handle<Object> data) {
 
1347
  Handle<FixedArray> store = NewFixedArray(JSRegExp::kAtomDataSize);
 
1348
 
 
1349
  store->set(JSRegExp::kTagIndex, Smi::FromInt(type));
 
1350
  store->set(JSRegExp::kSourceIndex, *source);
 
1351
  store->set(JSRegExp::kFlagsIndex, Smi::FromInt(flags.value()));
 
1352
  store->set(JSRegExp::kAtomPatternIndex, *data);
 
1353
  regexp->set_data(*store);
 
1354
}
 
1355
 
 
1356
void Factory::SetRegExpIrregexpData(Handle<JSRegExp> regexp,
 
1357
                                    JSRegExp::Type type,
 
1358
                                    Handle<String> source,
 
1359
                                    JSRegExp::Flags flags,
 
1360
                                    int capture_count) {
 
1361
  Handle<FixedArray> store = NewFixedArray(JSRegExp::kIrregexpDataSize);
 
1362
  Smi* uninitialized = Smi::FromInt(JSRegExp::kUninitializedValue);
 
1363
  store->set(JSRegExp::kTagIndex, Smi::FromInt(type));
 
1364
  store->set(JSRegExp::kSourceIndex, *source);
 
1365
  store->set(JSRegExp::kFlagsIndex, Smi::FromInt(flags.value()));
 
1366
  store->set(JSRegExp::kIrregexpASCIICodeIndex, uninitialized);
 
1367
  store->set(JSRegExp::kIrregexpUC16CodeIndex, uninitialized);
 
1368
  store->set(JSRegExp::kIrregexpASCIICodeSavedIndex, uninitialized);
 
1369
  store->set(JSRegExp::kIrregexpUC16CodeSavedIndex, uninitialized);
 
1370
  store->set(JSRegExp::kIrregexpMaxRegisterCountIndex, Smi::FromInt(0));
 
1371
  store->set(JSRegExp::kIrregexpCaptureCountIndex,
 
1372
             Smi::FromInt(capture_count));
 
1373
  regexp->set_data(*store);
 
1374
}
 
1375
 
 
1376
 
 
1377
 
 
1378
void Factory::ConfigureInstance(Handle<FunctionTemplateInfo> desc,
 
1379
                                Handle<JSObject> instance,
 
1380
                                bool* pending_exception) {
 
1381
  // Configure the instance by adding the properties specified by the
 
1382
  // instance template.
 
1383
  Handle<Object> instance_template = Handle<Object>(desc->instance_template());
 
1384
  if (!instance_template->IsUndefined()) {
 
1385
    Execution::ConfigureInstance(instance,
 
1386
                                 instance_template,
 
1387
                                 pending_exception);
 
1388
  } else {
 
1389
    *pending_exception = false;
 
1390
  }
 
1391
}
 
1392
 
 
1393
 
 
1394
Handle<Object> Factory::GlobalConstantFor(Handle<String> name) {
 
1395
  Heap* h = isolate()->heap();
 
1396
  if (name->Equals(h->undefined_symbol())) return undefined_value();
 
1397
  if (name->Equals(h->nan_symbol())) return nan_value();
 
1398
  if (name->Equals(h->infinity_symbol())) return infinity_value();
 
1399
  return Handle<Object>::null();
 
1400
}
 
1401
 
 
1402
 
 
1403
Handle<Object> Factory::ToBoolean(bool value) {
 
1404
  return Handle<Object>(value
 
1405
                        ? isolate()->heap()->true_value()
 
1406
                        : isolate()->heap()->false_value());
 
1407
}
 
1408
 
 
1409
 
 
1410
} }  // namespace v8::internal