| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 949 if (!result) return false; | 949 if (!result) return false; |
| 950 | 950 |
| 951 } else { | 951 } else { |
| 952 // Empty natives file name - do not install any natives. | 952 // Empty natives file name - do not install any natives. |
| 953 PrintF("Warning: Running without installed natives!\n"); | 953 PrintF("Warning: Running without installed natives!\n"); |
| 954 return true; | 954 return true; |
| 955 } | 955 } |
| 956 | 956 |
| 957 InstallNativeFunctions(); | 957 InstallNativeFunctions(); |
| 958 | 958 |
| 959 // TODO(1240778): Get rid of the JS implementation of | 959 // Install Function.prototype.call and apply. |
| 960 // Function.prototype.call and simply create a function with the | 960 { Handle<String> key = Factory::function_class_symbol(); |
| 961 // faked formal parameter count (-1) and use the illegal builtin as | 961 Handle<JSFunction> function = |
| 962 // the code for it. | 962 Handle<JSFunction>::cast(GetProperty(Top::global(), key)); |
| 963 | |
| 964 // Find Function.prototype.call and set it's number of formal | |
| 965 // parameters to -1 to let the arguments adaptor handle it | |
| 966 // specially. | |
| 967 { Handle<JSFunction> function = | |
| 968 Handle<JSFunction>::cast(GetProperty(Top::global(), | |
| 969 Factory::function_class_symbol())); | |
| 970 Handle<JSObject> proto = | 963 Handle<JSObject> proto = |
| 971 Handle<JSObject>(JSObject::cast(function->instance_prototype())); | 964 Handle<JSObject>(JSObject::cast(function->instance_prototype())); |
| 965 |
| 966 // Install the call and the apply functions. |
| 972 Handle<JSFunction> call = | 967 Handle<JSFunction> call = |
| 973 Handle<JSFunction>::cast(GetProperty(proto, Factory::call_symbol())); | 968 InstallFunction(proto, "call", JS_OBJECT_TYPE, JSObject::kHeaderSize, |
| 974 call->shared()->set_formal_parameter_count(-1); | 969 Factory::NewJSObject(Top::object_function(), TENURED), |
| 970 Builtins::FunctionCall, |
| 971 false); |
| 972 Handle<JSFunction> apply = |
| 973 InstallFunction(proto, "apply", JS_OBJECT_TYPE, JSObject::kHeaderSize, |
| 974 Factory::NewJSObject(Top::object_function(), TENURED), |
| 975 Builtins::FunctionApply, |
| 976 false); |
| 975 | 977 |
| 976 // Make sure that Function.prototype.call appears to be compiled. | 978 // Make sure that Function.prototype.call appears to be compiled. |
| 977 // The code will never be called, but inline caching for call will | 979 // The code will never be called, but inline caching for call will |
| 978 // only work if it appears to be compiled. | 980 // only work if it appears to be compiled. |
| 979 call->shared()->set_code(Builtins::builtin(Builtins::Illegal)); | 981 call->shared()->DontAdaptArguments(); |
| 980 ASSERT(call->is_compiled()); | 982 ASSERT(call->is_compiled()); |
| 981 | 983 |
| 982 // Use the specialized builtin for Function.prototype.apply. | 984 // Set the expected paramters for apply to 2; required by builtin. |
| 983 Handle<JSFunction> apply = | 985 apply->shared()->set_formal_parameter_count(2); |
| 984 Handle<JSFunction>::cast(GetProperty(proto, Factory::apply_symbol())); | 986 |
| 985 apply->shared()->set_code(Builtins::builtin(Builtins::FunctionApply)); | 987 // Set the lengths for the functions to satisfy ECMA-262. |
| 988 call->shared()->set_length(1); |
| 989 apply->shared()->set_length(2); |
| 986 } | 990 } |
| 987 | 991 |
| 988 // Make sure that the builtins object has fast properties. | 992 // Make sure that the builtins object has fast properties. |
| 989 // If the ASSERT below fails, please increase the expected number of | 993 // If the ASSERT below fails, please increase the expected number of |
| 990 // properties for the builtins object. | 994 // properties for the builtins object. |
| 991 ASSERT(builtins->HasFastProperties()); | 995 ASSERT(builtins->HasFastProperties()); |
| 992 #ifdef DEBUG | 996 #ifdef DEBUG |
| 993 builtins->Verify(); | 997 builtins->Verify(); |
| 994 #endif | 998 #endif |
| 995 return true; | 999 return true; |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1331 if (!ConfigureGlobalObject(global_template)) return; | 1335 if (!ConfigureGlobalObject(global_template)) return; |
| 1332 | 1336 |
| 1333 if (!InstallExtensions(extensions)) return; | 1337 if (!InstallExtensions(extensions)) return; |
| 1334 | 1338 |
| 1335 if (!InstallSpecialObjects()) return; | 1339 if (!InstallSpecialObjects()) return; |
| 1336 | 1340 |
| 1337 result_ = global_context_; | 1341 result_ = global_context_; |
| 1338 } | 1342 } |
| 1339 | 1343 |
| 1340 } } // namespace v8::internal | 1344 } } // namespace v8::internal |
| OLD | NEW |