deps: update v8 to 4.3.61.21
[platform/upstream/nodejs.git] / deps / v8 / src / runtime / runtime.cc
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "src/v8.h"
6
7 #include "src/runtime/runtime.h"
8 #include "src/runtime/runtime-utils.h"
9
10 namespace v8 {
11 namespace internal {
12
13 // Header of runtime functions.
14 #define F(name, number_of_args, result_size)                    \
15   Object* Runtime_##name(int args_length, Object** args_object, \
16                          Isolate* isolate);
17 FOR_EACH_INTRINSIC_RETURN_OBJECT(F)
18 #undef F
19
20 #define P(name, number_of_args, result_size)                       \
21   ObjectPair Runtime_##name(int args_length, Object** args_object, \
22                             Isolate* isolate);
23 FOR_EACH_INTRINSIC_RETURN_PAIR(P)
24 #undef P
25
26
27 #define F(name, number_of_args, result_size)                                  \
28   {                                                                           \
29     Runtime::k##name, Runtime::RUNTIME, #name, FUNCTION_ADDR(Runtime_##name), \
30         number_of_args, result_size                                           \
31   }                                                                           \
32   ,
33
34
35 #define I(name, number_of_args, result_size)                       \
36   {                                                                \
37     Runtime::kInline##name, Runtime::INLINE, "_" #name,            \
38         FUNCTION_ADDR(Runtime_##name), number_of_args, result_size \
39   }                                                                \
40   ,
41
42
43 static const Runtime::Function kIntrinsicFunctions[] = {
44     FOR_EACH_INTRINSIC(F) FOR_EACH_INTRINSIC(I)};
45
46 #undef I
47 #undef F
48
49
50 void Runtime::InitializeIntrinsicFunctionNames(Isolate* isolate,
51                                                Handle<NameDictionary> dict) {
52   DCHECK(dict->NumberOfElements() == 0);
53   HandleScope scope(isolate);
54   for (int i = 0; i < kNumFunctions; ++i) {
55     const char* name = kIntrinsicFunctions[i].name;
56     if (name == NULL) continue;
57     Handle<NameDictionary> new_dict = NameDictionary::Add(
58         dict, isolate->factory()->InternalizeUtf8String(name),
59         Handle<Smi>(Smi::FromInt(i), isolate), PropertyDetails::Empty());
60     // The dictionary does not need to grow.
61     CHECK(new_dict.is_identical_to(dict));
62   }
63 }
64
65
66 const Runtime::Function* Runtime::FunctionForName(Handle<String> name) {
67   Heap* heap = name->GetHeap();
68   int entry = heap->intrinsic_function_names()->FindEntry(name);
69   if (entry != kNotFound) {
70     Object* smi_index = heap->intrinsic_function_names()->ValueAt(entry);
71     int function_index = Smi::cast(smi_index)->value();
72     return &(kIntrinsicFunctions[function_index]);
73   }
74   return NULL;
75 }
76
77
78 const Runtime::Function* Runtime::FunctionForEntry(Address entry) {
79   for (size_t i = 0; i < arraysize(kIntrinsicFunctions); ++i) {
80     if (entry == kIntrinsicFunctions[i].entry) {
81       return &(kIntrinsicFunctions[i]);
82     }
83   }
84   return NULL;
85 }
86
87
88 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) {
89   return &(kIntrinsicFunctions[static_cast<int>(id)]);
90 }
91
92
93 std::ostream& operator<<(std::ostream& os, Runtime::FunctionId id) {
94   return os << Runtime::FunctionForId(id)->name;
95 }
96
97 }  // namespace internal
98 }  // namespace v8