OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1256 BUILTIN(StrictModePoisonPill) { | 1256 BUILTIN(StrictModePoisonPill) { |
1257 HandleScope scope; | 1257 HandleScope scope; |
1258 return isolate->Throw(*isolate->factory()->NewTypeError( | 1258 return isolate->Throw(*isolate->factory()->NewTypeError( |
1259 "strict_poison_pill", HandleVector<Object>(NULL, 0))); | 1259 "strict_poison_pill", HandleVector<Object>(NULL, 0))); |
1260 } | 1260 } |
1261 | 1261 |
1262 // ----------------------------------------------------------------------------- | 1262 // ----------------------------------------------------------------------------- |
1263 // | 1263 // |
1264 | 1264 |
1265 | 1265 |
| 1266 // Searches the hidden prototype chain of the given object for the first |
| 1267 // object that is an instance of the given type. If no such object can |
| 1268 // be found then Heap::null_value() is returned. |
| 1269 static inline Object* FindHidden(Heap* heap, |
| 1270 Object* object, |
| 1271 FunctionTemplateInfo* type) { |
| 1272 if (object->IsInstanceOf(type)) return object; |
| 1273 Object* proto = object->GetPrototype(); |
| 1274 if (proto->IsJSObject() && |
| 1275 JSObject::cast(proto)->map()->is_hidden_prototype()) { |
| 1276 return FindHidden(heap, proto, type); |
| 1277 } |
| 1278 return heap->null_value(); |
| 1279 } |
| 1280 |
| 1281 |
1266 // Returns the holder JSObject if the function can legally be called | 1282 // Returns the holder JSObject if the function can legally be called |
1267 // with this receiver. Returns Heap::null_value() if the call is | 1283 // with this receiver. Returns Heap::null_value() if the call is |
1268 // illegal. Any arguments that don't fit the expected type is | 1284 // illegal. Any arguments that don't fit the expected type is |
1269 // overwritten with undefined. Arguments that do fit the expected | 1285 // overwritten with undefined. Note that holder and the arguments are |
1270 // type is overwritten with the object in the prototype chain that | 1286 // implicitly rewritten with the first object in the hidden prototype |
1271 // actually has that type. | 1287 // chain that actually has the expected type. |
1272 static inline Object* TypeCheck(Heap* heap, | 1288 static inline Object* TypeCheck(Heap* heap, |
1273 int argc, | 1289 int argc, |
1274 Object** argv, | 1290 Object** argv, |
1275 FunctionTemplateInfo* info) { | 1291 FunctionTemplateInfo* info) { |
1276 Object* recv = argv[0]; | 1292 Object* recv = argv[0]; |
1277 // API calls are only supported with JSObject receivers. | 1293 // API calls are only supported with JSObject receivers. |
1278 if (!recv->IsJSObject()) return heap->null_value(); | 1294 if (!recv->IsJSObject()) return heap->null_value(); |
1279 Object* sig_obj = info->signature(); | 1295 Object* sig_obj = info->signature(); |
1280 if (sig_obj->IsUndefined()) return recv; | 1296 if (sig_obj->IsUndefined()) return recv; |
1281 SignatureInfo* sig = SignatureInfo::cast(sig_obj); | 1297 SignatureInfo* sig = SignatureInfo::cast(sig_obj); |
1282 // If necessary, check the receiver | 1298 // If necessary, check the receiver |
1283 Object* recv_type = sig->receiver(); | 1299 Object* recv_type = sig->receiver(); |
1284 | |
1285 Object* holder = recv; | 1300 Object* holder = recv; |
1286 if (!recv_type->IsUndefined()) { | 1301 if (!recv_type->IsUndefined()) { |
1287 for (; holder != heap->null_value(); holder = holder->GetPrototype()) { | 1302 holder = FindHidden(heap, holder, FunctionTemplateInfo::cast(recv_type)); |
1288 if (holder->IsInstanceOf(FunctionTemplateInfo::cast(recv_type))) { | 1303 if (holder == heap->null_value()) return heap->null_value(); |
1289 break; | |
1290 } | |
1291 } | |
1292 if (holder == heap->null_value()) return holder; | |
1293 } | 1304 } |
1294 Object* args_obj = sig->args(); | 1305 Object* args_obj = sig->args(); |
1295 // If there is no argument signature we're done | 1306 // If there is no argument signature we're done |
1296 if (args_obj->IsUndefined()) return holder; | 1307 if (args_obj->IsUndefined()) return holder; |
1297 FixedArray* args = FixedArray::cast(args_obj); | 1308 FixedArray* args = FixedArray::cast(args_obj); |
1298 int length = args->length(); | 1309 int length = args->length(); |
1299 if (argc <= length) length = argc - 1; | 1310 if (argc <= length) length = argc - 1; |
1300 for (int i = 0; i < length; i++) { | 1311 for (int i = 0; i < length; i++) { |
1301 Object* argtype = args->get(i); | 1312 Object* argtype = args->get(i); |
1302 if (argtype->IsUndefined()) continue; | 1313 if (argtype->IsUndefined()) continue; |
1303 Object** arg = &argv[-1 - i]; | 1314 Object** arg = &argv[-1 - i]; |
1304 Object* current = *arg; | 1315 Object* current = *arg; |
1305 for (; current != heap->null_value(); current = current->GetPrototype()) { | 1316 current = FindHidden(heap, current, FunctionTemplateInfo::cast(argtype)); |
1306 if (current->IsInstanceOf(FunctionTemplateInfo::cast(argtype))) { | 1317 if (current == heap->null_value()) current = heap->undefined_value(); |
1307 *arg = current; | 1318 *arg = current; |
1308 break; | |
1309 } | |
1310 } | |
1311 if (current == heap->null_value()) *arg = heap->undefined_value(); | |
1312 } | 1319 } |
1313 return holder; | 1320 return holder; |
1314 } | 1321 } |
1315 | 1322 |
1316 | 1323 |
1317 template <bool is_construct> | 1324 template <bool is_construct> |
1318 MUST_USE_RESULT static MaybeObject* HandleApiCallHelper( | 1325 MUST_USE_RESULT static MaybeObject* HandleApiCallHelper( |
1319 BuiltinArguments<NEEDS_CALLED_FUNCTION> args, Isolate* isolate) { | 1326 BuiltinArguments<NEEDS_CALLED_FUNCTION> args, Isolate* isolate) { |
1320 ASSERT(is_construct == CalledAsConstructor(isolate)); | 1327 ASSERT(is_construct == CalledAsConstructor(isolate)); |
1321 Heap* heap = isolate->heap(); | 1328 Heap* heap = isolate->heap(); |
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1946 return Handle<Code>(code_address); \ | 1953 return Handle<Code>(code_address); \ |
1947 } | 1954 } |
1948 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 1955 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
1949 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 1956 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
1950 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 1957 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
1951 #undef DEFINE_BUILTIN_ACCESSOR_C | 1958 #undef DEFINE_BUILTIN_ACCESSOR_C |
1952 #undef DEFINE_BUILTIN_ACCESSOR_A | 1959 #undef DEFINE_BUILTIN_ACCESSOR_A |
1953 | 1960 |
1954 | 1961 |
1955 } } // namespace v8::internal | 1962 } } // namespace v8::internal |
OLD | NEW |