| 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/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
| 8 #include "src/bootstrapper.h" | 8 #include "src/bootstrapper.h" |
| 9 #include "src/debug.h" | 9 #include "src/debug.h" |
| 10 #include "src/messages.h" | 10 #include "src/messages.h" |
| (...skipping 1128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1139 | 1139 |
| 1140 RUNTIME_FUNCTION(Runtime_ToBool) { | 1140 RUNTIME_FUNCTION(Runtime_ToBool) { |
| 1141 SealHandleScope shs(isolate); | 1141 SealHandleScope shs(isolate); |
| 1142 DCHECK(args.length() == 1); | 1142 DCHECK(args.length() == 1); |
| 1143 CONVERT_ARG_CHECKED(Object, object, 0); | 1143 CONVERT_ARG_CHECKED(Object, object, 0); |
| 1144 | 1144 |
| 1145 return isolate->heap()->ToBoolean(object->BooleanValue()); | 1145 return isolate->heap()->ToBoolean(object->BooleanValue()); |
| 1146 } | 1146 } |
| 1147 | 1147 |
| 1148 | 1148 |
| 1149 // Returns the type string of a value; see ECMA-262, 11.4.3 (p 47). | |
| 1150 // Possible optimizations: put the type string into the oddballs. | |
| 1151 RUNTIME_FUNCTION(Runtime_Typeof) { | |
| 1152 SealHandleScope shs(isolate); | |
| 1153 DCHECK(args.length() == 1); | |
| 1154 CONVERT_ARG_CHECKED(Object, obj, 0); | |
| 1155 if (obj->IsNumber()) return isolate->heap()->number_string(); | |
| 1156 HeapObject* heap_obj = HeapObject::cast(obj); | |
| 1157 | |
| 1158 // typeof an undetectable object is 'undefined' | |
| 1159 if (heap_obj->map()->is_undetectable()) { | |
| 1160 return isolate->heap()->undefined_string(); | |
| 1161 } | |
| 1162 | |
| 1163 InstanceType instance_type = heap_obj->map()->instance_type(); | |
| 1164 if (instance_type < FIRST_NONSTRING_TYPE) { | |
| 1165 return isolate->heap()->string_string(); | |
| 1166 } | |
| 1167 | |
| 1168 switch (instance_type) { | |
| 1169 case ODDBALL_TYPE: | |
| 1170 if (heap_obj->IsTrue() || heap_obj->IsFalse()) { | |
| 1171 return isolate->heap()->boolean_string(); | |
| 1172 } | |
| 1173 if (heap_obj->IsNull()) { | |
| 1174 return isolate->heap()->object_string(); | |
| 1175 } | |
| 1176 DCHECK(heap_obj->IsUndefined()); | |
| 1177 return isolate->heap()->undefined_string(); | |
| 1178 case SYMBOL_TYPE: | |
| 1179 return isolate->heap()->symbol_string(); | |
| 1180 case JS_FUNCTION_TYPE: | |
| 1181 case JS_FUNCTION_PROXY_TYPE: | |
| 1182 return isolate->heap()->function_string(); | |
| 1183 default: | |
| 1184 // For any kind of object not handled above, the spec rule for | |
| 1185 // host objects gives that it is okay to return "object" | |
| 1186 return isolate->heap()->object_string(); | |
| 1187 } | |
| 1188 } | |
| 1189 | |
| 1190 | |
| 1191 RUNTIME_FUNCTION(Runtime_NewStringWrapper) { | 1149 RUNTIME_FUNCTION(Runtime_NewStringWrapper) { |
| 1192 HandleScope scope(isolate); | 1150 HandleScope scope(isolate); |
| 1193 DCHECK(args.length() == 1); | 1151 DCHECK(args.length() == 1); |
| 1194 CONVERT_ARG_HANDLE_CHECKED(String, value, 0); | 1152 CONVERT_ARG_HANDLE_CHECKED(String, value, 0); |
| 1195 return *Object::ToObject(isolate, value).ToHandleChecked(); | 1153 return *Object::ToObject(isolate, value).ToHandleChecked(); |
| 1196 } | 1154 } |
| 1197 | 1155 |
| 1198 | 1156 |
| 1199 RUNTIME_FUNCTION(Runtime_AllocateHeapNumber) { | 1157 RUNTIME_FUNCTION(Runtime_AllocateHeapNumber) { |
| 1200 HandleScope scope(isolate); | 1158 HandleScope scope(isolate); |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1595 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3); | 1553 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3); |
| 1596 | 1554 |
| 1597 RETURN_FAILURE_ON_EXCEPTION( | 1555 RETURN_FAILURE_ON_EXCEPTION( |
| 1598 isolate, | 1556 isolate, |
| 1599 JSObject::DefineAccessor(object, name, isolate->factory()->null_value(), | 1557 JSObject::DefineAccessor(object, name, isolate->factory()->null_value(), |
| 1600 setter, attrs)); | 1558 setter, attrs)); |
| 1601 return isolate->heap()->undefined_value(); | 1559 return isolate->heap()->undefined_value(); |
| 1602 } | 1560 } |
| 1603 } | 1561 } |
| 1604 } // namespace v8::internal | 1562 } // namespace v8::internal |
| OLD | NEW |