~yolanda.robla/ubuntu/trusty/nodejs/add_distribution

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Jérémy Lal
  • Date: 2013-08-14 00:16:46 UTC
  • mfrom: (7.1.40 sid)
  • Revision ID: package-import@ubuntu.com-20130814001646-bzlysfh8sd6mukbo
Tags: 0.10.15~dfsg1-4
* Update 2005 patch, adding a handful of tests that can fail on
  slow platforms.
* Add 1004 patch to fix test failures when writing NaN to buffer
  on mipsel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright 2011 the V8 project authors. All rights reserved.
 
1
// Copyright 2012 the V8 project authors. All rights reserved.
2
2
// Redistribution and use in source and binary forms, with or without
3
3
// modification, are permitted provided that the following conditions are
4
4
// met:
34
34
#include "macro-assembler.h"
35
35
#include "objects.h"
36
36
#include "objects-visiting.h"
 
37
#include "platform.h"
37
38
#include "scopeinfo.h"
38
39
 
39
40
namespace v8 {
59
60
}
60
61
 
61
62
 
62
 
Handle<FixedArray> Factory::NewFixedDoubleArray(int size,
63
 
                                                PretenureFlag pretenure) {
 
63
Handle<FixedDoubleArray> Factory::NewFixedDoubleArray(int size,
 
64
                                                      PretenureFlag pretenure) {
64
65
  ASSERT(0 <= size);
65
66
  CALL_HEAP_FUNCTION(
66
67
      isolate(),
67
68
      isolate()->heap()->AllocateUninitializedFixedDoubleArray(size, pretenure),
68
 
      FixedArray);
 
69
      FixedDoubleArray);
69
70
}
70
71
 
71
72
 
95
96
}
96
97
 
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
 
98
107
Handle<ObjectHashTable> Factory::NewObjectHashTable(int at_least_space_for) {
99
108
  ASSERT(0 <= at_least_space_for);
100
109
  CALL_HEAP_FUNCTION(isolate(),
103
112
}
104
113
 
105
114
 
106
 
Handle<DescriptorArray> Factory::NewDescriptorArray(int number_of_descriptors) {
 
115
Handle<DescriptorArray> Factory::NewDescriptorArray(int number_of_descriptors,
 
116
                                                    int slack) {
107
117
  ASSERT(0 <= number_of_descriptors);
108
118
  CALL_HEAP_FUNCTION(isolate(),
109
 
                     DescriptorArray::Allocate(number_of_descriptors),
 
119
                     DescriptorArray::Allocate(number_of_descriptors, slack),
110
120
                     DescriptorArray);
111
121
}
112
122
 
133
143
}
134
144
 
135
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
 
136
160
// Symbols are created in the old generation (data space).
137
161
Handle<String> Factory::LookupSymbol(Vector<const char> string) {
138
162
  CALL_HEAP_FUNCTION(isolate(),
244
268
 
245
269
 
246
270
Handle<String> Factory::NewExternalStringFromAscii(
247
 
    ExternalAsciiString::Resource* resource) {
 
271
    const ExternalAsciiString::Resource* resource) {
248
272
  CALL_HEAP_FUNCTION(
249
273
      isolate(),
250
274
      isolate()->heap()->AllocateExternalStringFromAscii(resource),
253
277
 
254
278
 
255
279
Handle<String> Factory::NewExternalStringFromTwoByte(
256
 
    ExternalTwoByteString::Resource* resource) {
 
280
    const ExternalTwoByteString::Resource* resource) {
257
281
  CALL_HEAP_FUNCTION(
258
282
      isolate(),
259
283
      isolate()->heap()->AllocateExternalStringFromTwoByte(resource),
261
285
}
262
286
 
263
287
 
264
 
Handle<Context> Factory::NewGlobalContext() {
265
 
  CALL_HEAP_FUNCTION(
266
 
      isolate(),
267
 
      isolate()->heap()->AllocateGlobalContext(),
 
288
Handle<Context> Factory::NewNativeContext() {
 
289
  CALL_HEAP_FUNCTION(
 
290
      isolate(),
 
291
      isolate()->heap()->AllocateNativeContext(),
 
292
      Context);
 
293
}
 
294
 
 
295
 
 
296
Handle<Context> Factory::NewGlobalContext(Handle<JSFunction> function,
 
297
                                          Handle<ScopeInfo> scope_info) {
 
298
  CALL_HEAP_FUNCTION(
 
299
      isolate(),
 
300
      isolate()->heap()->AllocateGlobalContext(*function, *scope_info),
 
301
      Context);
 
302
}
 
303
 
 
304
 
 
305
Handle<Context> Factory::NewModuleContext(Handle<ScopeInfo> scope_info) {
 
306
  CALL_HEAP_FUNCTION(
 
307
      isolate(),
 
308
      isolate()->heap()->AllocateModuleContext(*scope_info),
268
309
      Context);
269
310
}
270
311
 
302
343
}
303
344
 
304
345
 
305
 
Handle<Context> Factory::NewBlockContext(
306
 
    Handle<JSFunction> function,
307
 
    Handle<Context> previous,
308
 
    Handle<SerializedScopeInfo> scope_info) {
 
346
Handle<Context> Factory::NewBlockContext(Handle<JSFunction> function,
 
347
                                         Handle<Context> previous,
 
348
                                         Handle<ScopeInfo> scope_info) {
309
349
  CALL_HEAP_FUNCTION(
310
350
      isolate(),
311
351
      isolate()->heap()->AllocateBlockContext(*function,
360
400
  script->set_context_data(heap->undefined_value());
361
401
  script->set_type(Smi::FromInt(Script::TYPE_NORMAL));
362
402
  script->set_compilation_type(Smi::FromInt(Script::COMPILATION_TYPE_HOST));
 
403
  script->set_compilation_state(
 
404
      Smi::FromInt(Script::COMPILATION_STATE_INITIAL));
363
405
  script->set_wrapper(*wrapper);
364
406
  script->set_line_ends(heap->undefined_value());
365
407
  script->set_eval_from_shared(heap->undefined_value());
414
456
}
415
457
 
416
458
 
417
 
Handle<Map> Factory::NewMap(InstanceType type, int instance_size) {
 
459
Handle<Map> Factory::NewMap(InstanceType type,
 
460
                            int instance_size,
 
461
                            ElementsKind elements_kind) {
418
462
  CALL_HEAP_FUNCTION(
419
463
      isolate(),
420
 
      isolate()->heap()->AllocateMap(type, instance_size),
 
464
      isolate()->heap()->AllocateMap(type, instance_size, elements_kind),
421
465
      Map);
422
466
}
423
467
 
430
474
}
431
475
 
432
476
 
433
 
Handle<Map> Factory::CopyMapDropDescriptors(Handle<Map> src) {
434
 
  CALL_HEAP_FUNCTION(isolate(), src->CopyDropDescriptors(), Map);
 
477
Handle<Map> Factory::CopyWithPreallocatedFieldDescriptors(Handle<Map> src) {
 
478
  CALL_HEAP_FUNCTION(
 
479
      isolate(), src->CopyWithPreallocatedFieldDescriptors(), Map);
435
480
}
436
481
 
437
482
 
438
483
Handle<Map> Factory::CopyMap(Handle<Map> src,
439
484
                             int extra_inobject_properties) {
440
 
  Handle<Map> copy = CopyMapDropDescriptors(src);
 
485
  Handle<Map> copy = CopyWithPreallocatedFieldDescriptors(src);
441
486
  // Check that we do not overflow the instance size when adding the
442
487
  // extra inobject properties.
443
488
  int instance_size_delta = extra_inobject_properties * kPointerSize;
460
505
}
461
506
 
462
507
 
463
 
Handle<Map> Factory::CopyMapDropTransitions(Handle<Map> src) {
464
 
  CALL_HEAP_FUNCTION(isolate(), src->CopyDropTransitions(), Map);
465
 
}
466
 
 
467
 
 
468
 
Handle<Map> Factory::GetFastElementsMap(Handle<Map> src) {
469
 
  CALL_HEAP_FUNCTION(isolate(), src->GetFastElementsMap(), Map);
470
 
}
471
 
 
472
 
 
473
 
Handle<Map> Factory::GetSlowElementsMap(Handle<Map> src) {
474
 
  CALL_HEAP_FUNCTION(isolate(), src->GetSlowElementsMap(), Map);
 
508
Handle<Map> Factory::CopyMap(Handle<Map> src) {
 
509
  CALL_HEAP_FUNCTION(isolate(), src->Copy(), Map);
475
510
}
476
511
 
477
512
 
478
513
Handle<Map> Factory::GetElementsTransitionMap(
479
 
    Handle<Map> src,
480
 
    ElementsKind elements_kind,
481
 
    bool safe_to_add_transition) {
482
 
  CALL_HEAP_FUNCTION(isolate(),
483
 
                     src->GetElementsTransitionMap(elements_kind,
484
 
                                                   safe_to_add_transition),
 
514
    Handle<JSObject> src,
 
515
    ElementsKind elements_kind) {
 
516
  Isolate* i = isolate();
 
517
  CALL_HEAP_FUNCTION(i,
 
518
                     src->GetElementsTransitionMap(i, elements_kind),
485
519
                     Map);
486
520
}
487
521
 
491
525
}
492
526
 
493
527
 
 
528
Handle<FixedDoubleArray> Factory::CopyFixedDoubleArray(
 
529
    Handle<FixedDoubleArray> array) {
 
530
  CALL_HEAP_FUNCTION(isolate(), array->Copy(), FixedDoubleArray);
 
531
}
 
532
 
 
533
 
494
534
Handle<JSFunction> Factory::BaseNewFunctionFromSharedFunctionInfo(
495
535
    Handle<SharedFunctionInfo> function_info,
496
536
    Handle<Map> function_map,
511
551
    PretenureFlag pretenure) {
512
552
  Handle<JSFunction> result = BaseNewFunctionFromSharedFunctionInfo(
513
553
      function_info,
514
 
      function_info->strict_mode()
515
 
          ? isolate()->strict_mode_function_map()
516
 
          : isolate()->function_map(),
 
554
      function_info->is_classic_mode()
 
555
          ? isolate()->function_map()
 
556
          : isolate()->strict_mode_function_map(),
517
557
      pretenure);
518
558
 
 
559
  if (function_info->ic_age() != isolate()->heap()->global_ic_age()) {
 
560
    function_info->ResetForNewContext(isolate()->heap()->global_ic_age());
 
561
  }
 
562
 
519
563
  result->set_context(*context);
520
 
  int number_of_literals = function_info->num_literals();
521
 
  Handle<FixedArray> literals = NewFixedArray(number_of_literals, pretenure);
522
 
  if (number_of_literals > 0) {
523
 
    // Store the object, regexp and array functions in the literals
524
 
    // array prefix.  These functions will be used when creating
525
 
    // object, regexp and array literals in this function.
526
 
    literals->set(JSFunction::kLiteralGlobalContextIndex,
527
 
                  context->global_context());
528
 
  }
529
 
  result->set_literals(*literals);
530
 
  result->set_next_function_link(isolate()->heap()->undefined_value());
 
564
 
 
565
  int index = function_info->SearchOptimizedCodeMap(context->native_context());
 
566
  if (!function_info->bound() && index < 0) {
 
567
    int number_of_literals = function_info->num_literals();
 
568
    Handle<FixedArray> literals = NewFixedArray(number_of_literals, pretenure);
 
569
    if (number_of_literals > 0) {
 
570
      // Store the native context in the literals array prefix. This
 
571
      // context will be used when creating object, regexp and array
 
572
      // literals in this function.
 
573
      literals->set(JSFunction::kLiteralNativeContextIndex,
 
574
                    context->native_context());
 
575
    }
 
576
    result->set_literals(*literals);
 
577
  }
 
578
 
 
579
  if (index > 0) {
 
580
    // Caching of optimized code enabled and optimized code found.
 
581
    function_info->InstallFromOptimizedCodeMap(*result, index);
 
582
    return result;
 
583
  }
531
584
 
532
585
  if (V8::UseCrankshaft() &&
533
586
      FLAG_always_opt &&
534
587
      result->is_compiled() &&
535
588
      !function_info->is_toplevel() &&
536
 
      function_info->allows_lazy_compilation()) {
 
589
      function_info->allows_lazy_compilation() &&
 
590
      !function_info->optimization_disabled()) {
537
591
    result->MarkForLazyRecompilation();
538
592
  }
539
593
  return result;
548
602
}
549
603
 
550
604
 
551
 
Handle<Object> Factory::NewNumberFromInt(int value) {
 
605
Handle<Object> Factory::NewNumberFromInt(int32_t value,
 
606
                                         PretenureFlag pretenure) {
552
607
  CALL_HEAP_FUNCTION(
553
608
      isolate(),
554
 
      isolate()->heap()->NumberFromInt32(value), Object);
 
609
      isolate()->heap()->NumberFromInt32(value, pretenure), Object);
555
610
}
556
611
 
557
612
 
558
 
Handle<Object> Factory::NewNumberFromUint(uint32_t value) {
 
613
Handle<Object> Factory::NewNumberFromUint(uint32_t value,
 
614
                                         PretenureFlag pretenure) {
559
615
  CALL_HEAP_FUNCTION(
560
616
      isolate(),
561
 
      isolate()->heap()->NumberFromUint32(value), Object);
 
617
      isolate()->heap()->NumberFromUint32(value, pretenure), Object);
562
618
}
563
619
 
564
620
 
639
695
}
640
696
 
641
697
 
 
698
Handle<String> Factory::EmergencyNewError(const char* type,
 
699
                                          Handle<JSArray> args) {
 
700
  const int kBufferSize = 1000;
 
701
  char buffer[kBufferSize];
 
702
  size_t space = kBufferSize;
 
703
  char* p = &buffer[0];
 
704
 
 
705
  Vector<char> v(buffer, kBufferSize);
 
706
  OS::StrNCpy(v, type, space);
 
707
  space -= Min(space, strlen(type));
 
708
  p = &buffer[kBufferSize] - space;
 
709
 
 
710
  for (unsigned i = 0; i < ARRAY_SIZE(args); i++) {
 
711
    if (space > 0) {
 
712
      *p++ = ' ';
 
713
      space--;
 
714
      if (space > 0) {
 
715
        MaybeObject* maybe_arg = args->GetElement(i);
 
716
        Handle<String> arg_str(reinterpret_cast<String*>(maybe_arg));
 
717
        const char* arg = *arg_str->ToCString();
 
718
        Vector<char> v2(p, static_cast<int>(space));
 
719
        OS::StrNCpy(v2, arg, space);
 
720
        space -= Min(space, strlen(arg));
 
721
        p = &buffer[kBufferSize] - space;
 
722
      }
 
723
    }
 
724
  }
 
725
  if (space > 0) {
 
726
    *p = '\0';
 
727
  } else {
 
728
    buffer[kBufferSize - 1] = '\0';
 
729
  }
 
730
  Handle<String> error_string = NewStringFromUtf8(CStrVector(buffer), TENURED);
 
731
  return error_string;
 
732
}
 
733
 
 
734
 
642
735
Handle<Object> Factory::NewError(const char* maker,
643
736
                                 const char* type,
644
737
                                 Handle<JSArray> args) {
647
740
      isolate()->js_builtins_object()->GetPropertyNoExceptionThrown(*make_str));
648
741
  // If the builtins haven't been properly configured yet this error
649
742
  // constructor may not have been defined.  Bail out.
650
 
  if (!fun_obj->IsJSFunction())
651
 
    return undefined_value();
 
743
  if (!fun_obj->IsJSFunction()) {
 
744
    return EmergencyNewError(type, args);
 
745
  }
652
746
  Handle<JSFunction> fun = Handle<JSFunction>::cast(fun_obj);
653
747
  Handle<Object> type_obj = LookupAsciiSymbol(type);
654
 
  Object** argv[2] = { type_obj.location(),
655
 
                       Handle<Object>::cast(args).location() };
 
748
  Handle<Object> argv[] = { type_obj, args };
656
749
 
657
750
  // Invoke the JavaScript factory method. If an exception is thrown while
658
751
  // running the factory method, use the exception as the result.
659
752
  bool caught_exception;
660
753
  Handle<Object> result = Execution::TryCall(fun,
661
 
      isolate()->js_builtins_object(), 2, argv, &caught_exception);
 
754
                                             isolate()->js_builtins_object(),
 
755
                                             ARRAY_SIZE(argv),
 
756
                                             argv,
 
757
                                             &caught_exception);
662
758
  return result;
663
759
}
664
760
 
674
770
  Handle<JSFunction> fun = Handle<JSFunction>(
675
771
      JSFunction::cast(isolate()->js_builtins_object()->
676
772
                       GetPropertyNoExceptionThrown(*constr)));
677
 
  Object** argv[1] = { Handle<Object>::cast(message).location() };
 
773
  Handle<Object> argv[] = { message };
678
774
 
679
775
  // Invoke the JavaScript factory method. If an exception is thrown while
680
776
  // running the factory method, use the exception as the result.
681
777
  bool caught_exception;
682
778
  Handle<Object> result = Execution::TryCall(fun,
683
 
      isolate()->js_builtins_object(), 1, argv, &caught_exception);
 
779
                                             isolate()->js_builtins_object(),
 
780
                                             ARRAY_SIZE(argv),
 
781
                                             argv,
 
782
                                             &caught_exception);
684
783
  return result;
685
784
}
686
785
 
693
792
  // Allocate the function
694
793
  Handle<JSFunction> function = NewFunction(name, the_hole_value());
695
794
 
696
 
  // Setup the code pointer in both the shared function info and in
 
795
  // Set up the code pointer in both the shared function info and in
697
796
  // the function itself.
698
797
  function->shared()->set_code(*code);
699
798
  function->set_code(*code);
724
823
  // Allocate the function.
725
824
  Handle<JSFunction> function = NewFunction(name, prototype);
726
825
 
727
 
  // Setup the code pointer in both the shared function info and in
 
826
  // Set up the code pointer in both the shared function info and in
728
827
  // the function itself.
729
828
  function->shared()->set_code(*code);
730
829
  function->set_code(*code);
732
831
  if (force_initial_map ||
733
832
      type != JS_OBJECT_TYPE ||
734
833
      instance_size != JSObject::kHeaderSize) {
735
 
    Handle<Map> initial_map = NewMap(type, instance_size);
 
834
    Handle<Map> initial_map = NewMap(type,
 
835
                                     instance_size,
 
836
                                     GetInitialFastElementsKind());
736
837
    function->set_initial_map(*initial_map);
737
838
    initial_map->set_constructor(*function);
738
839
  }
741
842
  // property that refers to the function.
742
843
  SetPrototypeProperty(function, prototype);
743
844
  // Currently safe because it is only invoked from Genesis.
744
 
  SetLocalPropertyNoThrow(prototype, constructor_symbol(), function, DONT_ENUM);
 
845
  CHECK_NOT_EMPTY_HANDLE(isolate(),
 
846
                         JSObject::SetLocalPropertyIgnoreAttributes(
 
847
                             prototype, constructor_symbol(),
 
848
                             function, DONT_ENUM));
745
849
  return function;
746
850
}
747
851
 
749
853
Handle<JSFunction> Factory::NewFunctionWithoutPrototype(Handle<String> name,
750
854
                                                        Handle<Code> code) {
751
855
  Handle<JSFunction> function = NewFunctionWithoutPrototype(name,
752
 
                                                            kNonStrictMode);
 
856
                                                            CLASSIC_MODE);
753
857
  function->shared()->set_code(*code);
754
858
  function->set_code(*code);
755
859
  ASSERT(!function->has_initial_map());
758
862
}
759
863
 
760
864
 
761
 
Handle<SerializedScopeInfo> Factory::NewSerializedScopeInfo(int length) {
 
865
Handle<ScopeInfo> Factory::NewScopeInfo(int length) {
762
866
  CALL_HEAP_FUNCTION(
763
867
      isolate(),
764
 
      isolate()->heap()->AllocateSerializedScopeInfo(length),
765
 
      SerializedScopeInfo);
 
868
      isolate()->heap()->AllocateScopeInfo(length),
 
869
      ScopeInfo);
766
870
}
767
871
 
768
872
 
791
895
}
792
896
 
793
897
 
794
 
MUST_USE_RESULT static inline MaybeObject* DoCopyInsert(
795
 
    DescriptorArray* array,
796
 
    String* key,
797
 
    Object* value,
798
 
    PropertyAttributes attributes) {
799
 
  CallbacksDescriptor desc(key, value, attributes);
800
 
  MaybeObject* obj = array->CopyInsert(&desc, REMOVE_TRANSITIONS);
801
 
  return obj;
802
 
}
803
 
 
804
 
 
805
 
// Allocate the new array.
806
 
Handle<DescriptorArray> Factory::CopyAppendForeignDescriptor(
807
 
    Handle<DescriptorArray> array,
808
 
    Handle<String> key,
809
 
    Handle<Object> value,
810
 
    PropertyAttributes attributes) {
811
 
  CALL_HEAP_FUNCTION(isolate(),
812
 
                     DoCopyInsert(*array, *key, *value, attributes),
813
 
                     DescriptorArray);
814
 
}
815
 
 
816
 
 
817
898
Handle<String> Factory::SymbolFromString(Handle<String> value) {
818
899
  CALL_HEAP_FUNCTION(isolate(),
819
900
                     isolate()->heap()->LookupSymbol(*value), String);
820
901
}
821
902
 
822
903
 
823
 
Handle<DescriptorArray> Factory::CopyAppendCallbackDescriptors(
824
 
    Handle<DescriptorArray> array,
825
 
    Handle<Object> descriptors) {
826
 
  v8::NeanderArray callbacks(descriptors);
827
 
  int nof_callbacks = callbacks.length();
828
 
  Handle<DescriptorArray> result =
829
 
      NewDescriptorArray(array->number_of_descriptors() + nof_callbacks);
830
 
 
831
 
  // Number of descriptors added to the result so far.
832
 
  int descriptor_count = 0;
833
 
 
834
 
  // Copy the descriptors from the array.
835
 
  for (int i = 0; i < array->number_of_descriptors(); i++) {
836
 
    if (array->GetType(i) != NULL_DESCRIPTOR) {
837
 
      result->CopyFrom(descriptor_count++, *array, i);
838
 
    }
839
 
  }
840
 
 
841
 
  // Number of duplicates detected.
842
 
  int duplicates = 0;
843
 
 
844
 
  // Fill in new callback descriptors.  Process the callbacks from
845
 
  // back to front so that the last callback with a given name takes
846
 
  // precedence over previously added callbacks with that name.
847
 
  for (int i = nof_callbacks - 1; i >= 0; i--) {
848
 
    Handle<AccessorInfo> entry =
849
 
        Handle<AccessorInfo>(AccessorInfo::cast(callbacks.get(i)));
850
 
    // Ensure the key is a symbol before writing into the instance descriptor.
851
 
    Handle<String> key =
852
 
        SymbolFromString(Handle<String>(String::cast(entry->name())));
853
 
    // Check if a descriptor with this name already exists before writing.
854
 
    if (result->LinearSearch(*key, descriptor_count) ==
855
 
        DescriptorArray::kNotFound) {
856
 
      CallbacksDescriptor desc(*key, *entry, entry->property_attributes());
857
 
      result->Set(descriptor_count, &desc);
858
 
      descriptor_count++;
859
 
    } else {
860
 
      duplicates++;
861
 
    }
862
 
  }
863
 
 
864
 
  // If duplicates were detected, allocate a result of the right size
865
 
  // and transfer the elements.
866
 
  if (duplicates > 0) {
867
 
    int number_of_descriptors = result->number_of_descriptors() - duplicates;
868
 
    Handle<DescriptorArray> new_result =
869
 
        NewDescriptorArray(number_of_descriptors);
870
 
    for (int i = 0; i < number_of_descriptors; i++) {
871
 
      new_result->CopyFrom(i, *result, i);
872
 
    }
873
 
    result = new_result;
874
 
  }
875
 
 
876
 
  // Sort the result before returning.
877
 
  result->Sort();
878
 
  return result;
879
 
}
880
 
 
881
 
 
882
904
Handle<JSObject> Factory::NewJSObject(Handle<JSFunction> constructor,
883
905
                                      PretenureFlag pretenure) {
884
906
  CALL_HEAP_FUNCTION(
887
909
}
888
910
 
889
911
 
 
912
Handle<JSModule> Factory::NewJSModule(Handle<Context> context,
 
913
                                      Handle<ScopeInfo> scope_info) {
 
914
  CALL_HEAP_FUNCTION(
 
915
      isolate(),
 
916
      isolate()->heap()->AllocateJSModule(*context, *scope_info), JSModule);
 
917
}
 
918
 
 
919
 
890
920
Handle<GlobalObject> Factory::NewGlobalObject(
891
921
    Handle<JSFunction> constructor) {
892
922
  CALL_HEAP_FUNCTION(isolate(),
905
935
 
906
936
 
907
937
Handle<JSArray> Factory::NewJSArray(int capacity,
 
938
                                    ElementsKind elements_kind,
908
939
                                    PretenureFlag pretenure) {
909
 
  Handle<JSObject> obj = NewJSObject(isolate()->array_function(), pretenure);
910
940
  CALL_HEAP_FUNCTION(isolate(),
911
 
                     Handle<JSArray>::cast(obj)->Initialize(capacity),
 
941
                     isolate()->heap()->AllocateJSArrayAndStorage(
 
942
                         elements_kind,
 
943
                         0,
 
944
                         capacity,
 
945
                         INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE,
 
946
                         pretenure),
912
947
                     JSArray);
913
948
}
914
949
 
915
950
 
916
 
Handle<JSArray> Factory::NewJSArrayWithElements(Handle<FixedArray> elements,
 
951
Handle<JSArray> Factory::NewJSArrayWithElements(Handle<FixedArrayBase> elements,
 
952
                                                ElementsKind elements_kind,
917
953
                                                PretenureFlag pretenure) {
918
 
  Handle<JSArray> result =
919
 
      Handle<JSArray>::cast(NewJSObject(isolate()->array_function(),
920
 
                                        pretenure));
921
 
  result->SetContent(*elements);
922
 
  return result;
 
954
  CALL_HEAP_FUNCTION(
 
955
      isolate(),
 
956
      isolate()->heap()->AllocateJSArrayWithElements(*elements,
 
957
                                                     elements_kind,
 
958
                                                     pretenure),
 
959
      JSArray);
 
960
}
 
961
 
 
962
 
 
963
void Factory::SetElementsCapacityAndLength(Handle<JSArray> array,
 
964
                                           int capacity,
 
965
                                           int length) {
 
966
  ElementsAccessor* accessor = array->GetElementsAccessor();
 
967
  CALL_HEAP_FUNCTION_VOID(
 
968
      isolate(),
 
969
      accessor->SetCapacityAndLength(*array, capacity, length));
 
970
}
 
971
 
 
972
 
 
973
void Factory::SetContent(Handle<JSArray> array,
 
974
                         Handle<FixedArrayBase> elements) {
 
975
  CALL_HEAP_FUNCTION_VOID(
 
976
      isolate(),
 
977
      array->SetContent(*elements));
 
978
}
 
979
 
 
980
 
 
981
void Factory::EnsureCanContainHeapObjectElements(Handle<JSArray> array) {
 
982
  CALL_HEAP_FUNCTION_VOID(
 
983
      isolate(),
 
984
      array->EnsureCanContainHeapObjectElements());
 
985
}
 
986
 
 
987
 
 
988
void Factory::EnsureCanContainElements(Handle<JSArray> array,
 
989
                                       Handle<FixedArrayBase> elements,
 
990
                                       uint32_t length,
 
991
                                       EnsureElementsMode mode) {
 
992
  CALL_HEAP_FUNCTION_VOID(
 
993
      isolate(),
 
994
      array->EnsureCanContainElements(*elements, length, mode));
923
995
}
924
996
 
925
997
 
948
1020
}
949
1021
 
950
1022
 
 
1023
void Factory::SetIdentityHash(Handle<JSObject> object, Smi* hash) {
 
1024
  CALL_HEAP_FUNCTION_VOID(
 
1025
      isolate(),
 
1026
      object->SetIdentityHash(hash, ALLOW_CREATION));
 
1027
}
 
1028
 
 
1029
 
951
1030
Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo(
952
1031
    Handle<String> name,
953
1032
    int number_of_literals,
954
1033
    Handle<Code> code,
955
 
    Handle<SerializedScopeInfo> scope_info) {
 
1034
    Handle<ScopeInfo> scope_info) {
956
1035
  Handle<SharedFunctionInfo> shared = NewSharedFunctionInfo(name);
957
1036
  shared->set_code(*code);
958
1037
  shared->set_scope_info(*scope_info);
1000
1079
}
1001
1080
 
1002
1081
 
 
1082
Handle<String> Factory::Uint32ToString(uint32_t value) {
 
1083
  CALL_HEAP_FUNCTION(isolate(),
 
1084
                     isolate()->heap()->Uint32ToString(value), String);
 
1085
}
 
1086
 
 
1087
 
1003
1088
Handle<SeededNumberDictionary> Factory::DictionaryAtNumberPut(
1004
1089
    Handle<SeededNumberDictionary> dictionary,
1005
1090
    uint32_t key,
1035
1120
Handle<JSFunction> Factory::NewFunction(Handle<String> name,
1036
1121
                                        Handle<Object> prototype) {
1037
1122
  Handle<JSFunction> fun = NewFunctionHelper(name, prototype);
1038
 
  fun->set_context(isolate()->context()->global_context());
 
1123
  fun->set_context(isolate()->context()->native_context());
1039
1124
  return fun;
1040
1125
}
1041
1126
 
1042
1127
 
1043
1128
Handle<JSFunction> Factory::NewFunctionWithoutPrototypeHelper(
1044
1129
    Handle<String> name,
1045
 
    StrictModeFlag strict_mode) {
 
1130
    LanguageMode language_mode) {
1046
1131
  Handle<SharedFunctionInfo> function_share = NewSharedFunctionInfo(name);
1047
 
  Handle<Map> map = strict_mode == kStrictMode
1048
 
      ? isolate()->strict_mode_function_without_prototype_map()
1049
 
      : isolate()->function_without_prototype_map();
 
1132
  Handle<Map> map = (language_mode == CLASSIC_MODE)
 
1133
      ? isolate()->function_without_prototype_map()
 
1134
      : isolate()->strict_mode_function_without_prototype_map();
1050
1135
  CALL_HEAP_FUNCTION(isolate(),
1051
1136
                     isolate()->heap()->AllocateFunction(
1052
1137
                         *map,
1058
1143
 
1059
1144
Handle<JSFunction> Factory::NewFunctionWithoutPrototype(
1060
1145
    Handle<String> name,
1061
 
    StrictModeFlag strict_mode) {
1062
 
  Handle<JSFunction> fun = NewFunctionWithoutPrototypeHelper(name, strict_mode);
1063
 
  fun->set_context(isolate()->context()->global_context());
 
1146
    LanguageMode language_mode) {
 
1147
  Handle<JSFunction> fun =
 
1148
      NewFunctionWithoutPrototypeHelper(name, language_mode);
 
1149
  fun->set_context(isolate()->context()->native_context());
1064
1150
  return fun;
1065
1151
}
1066
1152
 
1071
1157
 
1072
1158
 
1073
1159
Handle<Object> Factory::ToObject(Handle<Object> object,
1074
 
                                 Handle<Context> global_context) {
1075
 
  CALL_HEAP_FUNCTION(isolate(), object->ToObject(*global_context), Object);
 
1160
                                 Handle<Context> native_context) {
 
1161
  CALL_HEAP_FUNCTION(isolate(), object->ToObject(*native_context), Object);
1076
1162
}
1077
1163
 
1078
1164
 
1199
1285
  result->shared()->DontAdaptArguments();
1200
1286
 
1201
1287
  // Recursively copy parent templates' accessors, 'data' may be modified.
1202
 
  Handle<DescriptorArray> array =
1203
 
      Handle<DescriptorArray>(map->instance_descriptors());
 
1288
  int max_number_of_additional_properties = 0;
 
1289
  FunctionTemplateInfo* info = *obj;
 
1290
  while (true) {
 
1291
    Object* props = info->property_accessors();
 
1292
    if (!props->IsUndefined()) {
 
1293
      Handle<Object> props_handle(props);
 
1294
      NeanderArray props_array(props_handle);
 
1295
      max_number_of_additional_properties += props_array.length();
 
1296
    }
 
1297
    Object* parent = info->parent_template();
 
1298
    if (parent->IsUndefined()) break;
 
1299
    info = FunctionTemplateInfo::cast(parent);
 
1300
  }
 
1301
 
 
1302
  Map::EnsureDescriptorSlack(map, max_number_of_additional_properties);
 
1303
 
1204
1304
  while (true) {
1205
1305
    Handle<Object> props = Handle<Object>(obj->property_accessors());
1206
1306
    if (!props->IsUndefined()) {
1207
 
      array = CopyAppendCallbackDescriptors(array, props);
 
1307
      Map::AppendCallbackDescriptors(map, props);
1208
1308
    }
1209
1309
    Handle<Object> parent = Handle<Object>(obj->parent_template());
1210
1310
    if (parent->IsUndefined()) break;
1211
1311
    obj = Handle<FunctionTemplateInfo>::cast(parent);
1212
1312
  }
1213
 
  if (!array->IsEmpty()) {
1214
 
    map->set_instance_descriptors(*array);
1215
 
  }
1216
1313
 
1217
1314
  ASSERT(result->shared()->IsApiFunction());
1218
1315
  return result;
1249
1346
Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> context,
1250
1347
                                               Handle<FixedArray> keys) {
1251
1348
  if (context->map_cache()->IsUndefined()) {
1252
 
    // Allocate the new map cache for the global context.
 
1349
    // Allocate the new map cache for the native context.
1253
1350
    Handle<MapCache> new_cache = NewMapCache(24);
1254
1351
    context->set_map_cache(*new_cache);
1255
1352
  }
1319
1416
}
1320
1417
 
1321
1418
 
 
1419
Handle<Object> Factory::GlobalConstantFor(Handle<String> name) {
 
1420
  Heap* h = isolate()->heap();
 
1421
  if (name->Equals(h->undefined_symbol())) return undefined_value();
 
1422
  if (name->Equals(h->nan_symbol())) return nan_value();
 
1423
  if (name->Equals(h->infinity_symbol())) return infinity_value();
 
1424
  return Handle<Object>::null();
 
1425
}
 
1426
 
 
1427
 
 
1428
Handle<Object> Factory::ToBoolean(bool value) {
 
1429
  return Handle<Object>(value
 
1430
                        ? isolate()->heap()->true_value()
 
1431
                        : isolate()->heap()->false_value());
 
1432
}
 
1433
 
 
1434
 
1322
1435
} }  // namespace v8::internal