OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
6 | 6 |
7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
8 #include "src/debug/debug.h" | 8 #include "src/debug/debug.h" |
9 #include "src/debug/debug-evaluate.h" | 9 #include "src/debug/debug-evaluate.h" |
10 #include "src/debug/debug-frames.h" | 10 #include "src/debug/debug-frames.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 result->set(4, *iterator_kind); | 143 result->set(4, *iterator_kind); |
144 Handle<String> kind_str = factory->NewStringFromAsciiChecked(kind); | 144 Handle<String> kind_str = factory->NewStringFromAsciiChecked(kind); |
145 result->set(5, *kind_str); | 145 result->set(5, *kind_str); |
146 return factory->NewJSArrayWithElements(result); | 146 return factory->NewJSArrayWithElements(result); |
147 } | 147 } |
148 | 148 |
149 | 149 |
150 MaybeHandle<JSArray> Runtime::GetInternalProperties(Isolate* isolate, | 150 MaybeHandle<JSArray> Runtime::GetInternalProperties(Isolate* isolate, |
151 Handle<Object> object) { | 151 Handle<Object> object) { |
152 Factory* factory = isolate->factory(); | 152 Factory* factory = isolate->factory(); |
153 if (object->IsJSBoundFunction()) { | 153 if (object->IsJSFunction()) { |
154 Handle<JSBoundFunction> function = Handle<JSBoundFunction>::cast(object); | 154 Handle<JSFunction> function = Handle<JSFunction>::cast(object); |
| 155 if (function->shared()->bound()) { |
| 156 RUNTIME_ASSERT_HANDLIFIED(function->function_bindings()->IsFixedArray(), |
| 157 JSArray); |
155 | 158 |
156 Handle<FixedArray> result = factory->NewFixedArray(2 * 3); | 159 Handle<BindingsArray> bindings(function->function_bindings()); |
157 Handle<String> target = | |
158 factory->NewStringFromAsciiChecked("[[TargetFunction]]"); | |
159 result->set(0, *target); | |
160 result->set(1, function->bound_target_function()); | |
161 | 160 |
162 Handle<String> bound_this = | 161 Handle<FixedArray> result = factory->NewFixedArray(2 * 3); |
163 factory->NewStringFromAsciiChecked("[[BoundThis]]"); | 162 Handle<String> target = |
164 result->set(2, *bound_this); | 163 factory->NewStringFromAsciiChecked("[[TargetFunction]]"); |
165 result->set(3, function->bound_this()); | 164 result->set(0, *target); |
| 165 result->set(1, bindings->bound_function()); |
166 | 166 |
167 Handle<String> bound_args = | 167 Handle<String> bound_this = |
168 factory->NewStringFromAsciiChecked("[[BoundArgs]]"); | 168 factory->NewStringFromAsciiChecked("[[BoundThis]]"); |
169 result->set(4, *bound_args); | 169 result->set(2, *bound_this); |
170 Handle<FixedArray> bound_arguments = | 170 result->set(3, bindings->bound_this()); |
171 factory->CopyFixedArray(handle(function->bound_arguments(), isolate)); | 171 |
172 Handle<JSArray> arguments_array = | 172 Handle<String> bound_args = |
173 factory->NewJSArrayWithElements(bound_arguments); | 173 factory->NewStringFromAsciiChecked("[[BoundArgs]]"); |
174 result->set(5, *arguments_array); | 174 result->set(4, *bound_args); |
175 return factory->NewJSArrayWithElements(result); | 175 Handle<JSArray> arguments_array = |
| 176 BindingsArray::CreateBoundArguments(bindings); |
| 177 result->set(5, *arguments_array); |
| 178 return factory->NewJSArrayWithElements(result); |
| 179 } |
176 } else if (object->IsJSMapIterator()) { | 180 } else if (object->IsJSMapIterator()) { |
177 Handle<JSMapIterator> iterator = Handle<JSMapIterator>::cast(object); | 181 Handle<JSMapIterator> iterator = Handle<JSMapIterator>::cast(object); |
178 return GetIteratorInternalProperties(isolate, iterator); | 182 return GetIteratorInternalProperties(isolate, iterator); |
179 } else if (object->IsJSSetIterator()) { | 183 } else if (object->IsJSSetIterator()) { |
180 Handle<JSSetIterator> iterator = Handle<JSSetIterator>::cast(object); | 184 Handle<JSSetIterator> iterator = Handle<JSSetIterator>::cast(object); |
181 return GetIteratorInternalProperties(isolate, iterator); | 185 return GetIteratorInternalProperties(isolate, iterator); |
182 } else if (object->IsJSGeneratorObject()) { | 186 } else if (object->IsJSGeneratorObject()) { |
183 Handle<JSGeneratorObject> generator = | 187 Handle<JSGeneratorObject> generator = |
184 Handle<JSGeneratorObject>::cast(object); | 188 Handle<JSGeneratorObject>::cast(object); |
185 | 189 |
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 Handle<FixedArray> array = isolate->factory()->NewFixedArray(result.length()); | 866 Handle<FixedArray> array = isolate->factory()->NewFixedArray(result.length()); |
863 for (int i = 0; i < result.length(); ++i) { | 867 for (int i = 0; i < result.length(); ++i) { |
864 array->set(i, *result[i]); | 868 array->set(i, *result[i]); |
865 } | 869 } |
866 return *isolate->factory()->NewJSArrayWithElements(array); | 870 return *isolate->factory()->NewJSArrayWithElements(array); |
867 } | 871 } |
868 | 872 |
869 | 873 |
870 RUNTIME_FUNCTION(Runtime_GetFunctionScopeCount) { | 874 RUNTIME_FUNCTION(Runtime_GetFunctionScopeCount) { |
871 HandleScope scope(isolate); | 875 HandleScope scope(isolate); |
872 DCHECK_EQ(1, args.length()); | 876 DCHECK(args.length() == 1); |
873 | 877 |
874 // Check arguments. | 878 // Check arguments. |
875 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, function, 0); | 879 CONVERT_ARG_HANDLE_CHECKED(JSFunction, fun, 0); |
876 | 880 |
877 // Count the visible scopes. | 881 // Count the visible scopes. |
878 int n = 0; | 882 int n = 0; |
879 if (function->IsJSFunction()) { | 883 for (ScopeIterator it(isolate, fun); !it.Done(); it.Next()) { |
880 for (ScopeIterator it(isolate, Handle<JSFunction>::cast(function)); | 884 n++; |
881 !it.Done(); it.Next()) { | |
882 n++; | |
883 } | |
884 } | 885 } |
885 | 886 |
886 return Smi::FromInt(n); | 887 return Smi::FromInt(n); |
887 } | 888 } |
888 | 889 |
889 | 890 |
890 RUNTIME_FUNCTION(Runtime_GetFunctionScopeDetails) { | 891 RUNTIME_FUNCTION(Runtime_GetFunctionScopeDetails) { |
891 HandleScope scope(isolate); | 892 HandleScope scope(isolate); |
892 DCHECK(args.length() == 2); | 893 DCHECK(args.length() == 2); |
893 | 894 |
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1460 int compilation_state = script->compilation_state(); | 1461 int compilation_state = script->compilation_state(); |
1461 RUNTIME_ASSERT(compilation_state == Script::COMPILATION_STATE_INITIAL); | 1462 RUNTIME_ASSERT(compilation_state == Script::COMPILATION_STATE_INITIAL); |
1462 script->set_source(*source); | 1463 script->set_source(*source); |
1463 | 1464 |
1464 return isolate->heap()->undefined_value(); | 1465 return isolate->heap()->undefined_value(); |
1465 } | 1466 } |
1466 | 1467 |
1467 | 1468 |
1468 RUNTIME_FUNCTION(Runtime_FunctionGetInferredName) { | 1469 RUNTIME_FUNCTION(Runtime_FunctionGetInferredName) { |
1469 SealHandleScope shs(isolate); | 1470 SealHandleScope shs(isolate); |
1470 DCHECK_EQ(1, args.length()); | 1471 DCHECK(args.length() == 1); |
1471 | 1472 |
1472 CONVERT_ARG_CHECKED(Object, f, 0); | 1473 CONVERT_ARG_CHECKED(JSFunction, f, 0); |
1473 if (f->IsJSFunction()) { | 1474 return f->shared()->inferred_name(); |
1474 return JSFunction::cast(f)->shared()->inferred_name(); | |
1475 } | |
1476 return isolate->heap()->empty_string(); | |
1477 } | 1475 } |
1478 | 1476 |
1479 | 1477 |
1480 RUNTIME_FUNCTION(Runtime_FunctionGetDebugName) { | 1478 RUNTIME_FUNCTION(Runtime_FunctionGetDebugName) { |
1481 HandleScope scope(isolate); | 1479 HandleScope scope(isolate); |
1482 DCHECK_EQ(1, args.length()); | 1480 DCHECK(args.length() == 1); |
1483 | 1481 |
1484 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, function, 0); | 1482 CONVERT_ARG_HANDLE_CHECKED(JSFunction, f, 0); |
1485 | 1483 Handle<Object> name = JSFunction::GetDebugName(f); |
1486 if (function->IsJSBoundFunction()) { | |
1487 return Handle<JSBoundFunction>::cast(function)->name(); | |
1488 } | |
1489 Handle<Object> name = | |
1490 JSFunction::GetDebugName(Handle<JSFunction>::cast(function)); | |
1491 return *name; | 1484 return *name; |
1492 } | 1485 } |
1493 | 1486 |
1494 | 1487 |
1495 // A testing entry. Returns statement position which is the closest to | 1488 // A testing entry. Returns statement position which is the closest to |
1496 // source_position. | 1489 // source_position. |
1497 RUNTIME_FUNCTION(Runtime_GetFunctionCodePositionFromSource) { | 1490 RUNTIME_FUNCTION(Runtime_GetFunctionCodePositionFromSource) { |
1498 HandleScope scope(isolate); | 1491 HandleScope scope(isolate); |
1499 CHECK(isolate->debug()->live_edit_enabled()); | 1492 CHECK(isolate->debug()->live_edit_enabled()); |
1500 DCHECK(args.length() == 2); | 1493 DCHECK(args.length() == 2); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1687 return Smi::FromInt(isolate->debug()->is_active()); | 1680 return Smi::FromInt(isolate->debug()->is_active()); |
1688 } | 1681 } |
1689 | 1682 |
1690 | 1683 |
1691 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) { | 1684 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) { |
1692 UNIMPLEMENTED(); | 1685 UNIMPLEMENTED(); |
1693 return NULL; | 1686 return NULL; |
1694 } | 1687 } |
1695 } // namespace internal | 1688 } // namespace internal |
1696 } // namespace v8 | 1689 } // namespace v8 |
OLD | NEW |