| OLD | NEW |
| 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 const char* type = (is_read_only) ? "const" : "var"; | 781 const char* type = (is_read_only) ? "const" : "var"; |
| 782 return ThrowRedeclarationError(type, name); | 782 return ThrowRedeclarationError(type, name); |
| 783 } | 783 } |
| 784 // The property already exists without conflicting: Go to | 784 // The property already exists without conflicting: Go to |
| 785 // the next declaration. | 785 // the next declaration. |
| 786 continue; | 786 continue; |
| 787 } | 787 } |
| 788 } | 788 } |
| 789 } else { | 789 } else { |
| 790 // Copy the function and update its context. Use it as value. | 790 // Copy the function and update its context. Use it as value. |
| 791 Handle<JSFunction> boilerplate = Handle<JSFunction>::cast(value); | 791 Handle<SharedFunctionInfo> shared = |
| 792 Handle<SharedFunctionInfo>::cast(value); |
| 792 Handle<JSFunction> function = | 793 Handle<JSFunction> function = |
| 793 Factory::NewFunctionFromBoilerplate(boilerplate, context, TENURED); | 794 Factory::NewFunctionFromSharedFunctionInfo(shared, context, TENURED); |
| 794 value = function; | 795 value = function; |
| 795 } | 796 } |
| 796 | 797 |
| 797 LookupResult lookup; | 798 LookupResult lookup; |
| 798 global->LocalLookup(*name, &lookup); | 799 global->LocalLookup(*name, &lookup); |
| 799 | 800 |
| 800 PropertyAttributes attributes = is_const_property | 801 PropertyAttributes attributes = is_const_property |
| 801 ? static_cast<PropertyAttributes>(base | READ_ONLY) | 802 ? static_cast<PropertyAttributes>(base | READ_ONLY) |
| 802 : base; | 803 : base; |
| 803 | 804 |
| (...skipping 5001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5805 JSObject::cast(result)->set_elements(FixedArray::cast(obj)); | 5806 JSObject::cast(result)->set_elements(FixedArray::cast(obj)); |
| 5806 } | 5807 } |
| 5807 return result; | 5808 return result; |
| 5808 } | 5809 } |
| 5809 | 5810 |
| 5810 | 5811 |
| 5811 static Object* Runtime_NewClosure(Arguments args) { | 5812 static Object* Runtime_NewClosure(Arguments args) { |
| 5812 HandleScope scope; | 5813 HandleScope scope; |
| 5813 ASSERT(args.length() == 2); | 5814 ASSERT(args.length() == 2); |
| 5814 CONVERT_ARG_CHECKED(Context, context, 0); | 5815 CONVERT_ARG_CHECKED(Context, context, 0); |
| 5815 CONVERT_ARG_CHECKED(JSFunction, boilerplate, 1); | 5816 CONVERT_ARG_CHECKED(SharedFunctionInfo, shared, 1); |
| 5816 | 5817 |
| 5817 PretenureFlag pretenure = (context->global_context() == *context) | 5818 PretenureFlag pretenure = (context->global_context() == *context) |
| 5818 ? TENURED // Allocate global closures in old space. | 5819 ? TENURED // Allocate global closures in old space. |
| 5819 : NOT_TENURED; // Allocate local closures in new space. | 5820 : NOT_TENURED; // Allocate local closures in new space. |
| 5820 Handle<JSFunction> result = | 5821 Handle<JSFunction> result = |
| 5821 Factory::NewFunctionFromBoilerplate(boilerplate, context, pretenure); | 5822 Factory::NewFunctionFromSharedFunctionInfo(shared, context, pretenure); |
| 5822 return *result; | 5823 return *result; |
| 5823 } | 5824 } |
| 5824 | 5825 |
| 5825 | 5826 |
| 5826 static Code* ComputeConstructStub(Handle<JSFunction> function) { | 5827 static Code* ComputeConstructStub(Handle<JSFunction> function) { |
| 5827 Handle<Object> prototype = Factory::null_value(); | 5828 Handle<Object> prototype = Factory::null_value(); |
| 5828 if (function->has_instance_prototype()) { | 5829 if (function->has_instance_prototype()) { |
| 5829 prototype = Handle<Object>(function->instance_prototype()); | 5830 prototype = Handle<Object>(function->instance_prototype()); |
| 5830 } | 5831 } |
| 5831 if (function->shared()->CanGenerateInlineConstructor(*prototype)) { | 5832 if (function->shared()->CanGenerateInlineConstructor(*prototype)) { |
| (...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6496 static Object* Runtime_CompileString(Arguments args) { | 6497 static Object* Runtime_CompileString(Arguments args) { |
| 6497 HandleScope scope; | 6498 HandleScope scope; |
| 6498 ASSERT_EQ(2, args.length()); | 6499 ASSERT_EQ(2, args.length()); |
| 6499 CONVERT_ARG_CHECKED(String, source, 0); | 6500 CONVERT_ARG_CHECKED(String, source, 0); |
| 6500 CONVERT_ARG_CHECKED(Oddball, is_json, 1) | 6501 CONVERT_ARG_CHECKED(Oddball, is_json, 1) |
| 6501 | 6502 |
| 6502 // Compile source string in the global context. | 6503 // Compile source string in the global context. |
| 6503 Handle<Context> context(Top::context()->global_context()); | 6504 Handle<Context> context(Top::context()->global_context()); |
| 6504 Compiler::ValidationState validate = (is_json->IsTrue()) | 6505 Compiler::ValidationState validate = (is_json->IsTrue()) |
| 6505 ? Compiler::VALIDATE_JSON : Compiler::DONT_VALIDATE_JSON; | 6506 ? Compiler::VALIDATE_JSON : Compiler::DONT_VALIDATE_JSON; |
| 6506 Handle<JSFunction> boilerplate = Compiler::CompileEval(source, | 6507 Handle<SharedFunctionInfo> shared = Compiler::CompileEval(source, |
| 6507 context, | 6508 context, |
| 6508 true, | 6509 true, |
| 6509 validate); | 6510 validate); |
| 6510 if (boilerplate.is_null()) return Failure::Exception(); | 6511 if (shared.is_null()) return Failure::Exception(); |
| 6511 Handle<JSFunction> fun = | 6512 Handle<JSFunction> fun = |
| 6512 Factory::NewFunctionFromBoilerplate(boilerplate, context, NOT_TENURED); | 6513 Factory::NewFunctionFromSharedFunctionInfo(shared, context, NOT_TENURED); |
| 6513 return *fun; | 6514 return *fun; |
| 6514 } | 6515 } |
| 6515 | 6516 |
| 6516 | 6517 |
| 6517 static ObjectPair Runtime_ResolvePossiblyDirectEval(Arguments args) { | 6518 static ObjectPair Runtime_ResolvePossiblyDirectEval(Arguments args) { |
| 6518 ASSERT(args.length() == 3); | 6519 ASSERT(args.length() == 3); |
| 6519 if (!args[0]->IsJSFunction()) { | 6520 if (!args[0]->IsJSFunction()) { |
| 6520 return MakePair(Top::ThrowIllegalOperation(), NULL); | 6521 return MakePair(Top::ThrowIllegalOperation(), NULL); |
| 6521 } | 6522 } |
| 6522 | 6523 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6575 // 'eval' is bound in the global context, but it may have been overwritten. | 6576 // 'eval' is bound in the global context, but it may have been overwritten. |
| 6576 // Compare it to the builtin 'GlobalEval' function to make sure. | 6577 // Compare it to the builtin 'GlobalEval' function to make sure. |
| 6577 if (*callee != Top::global_context()->global_eval_fun() || | 6578 if (*callee != Top::global_context()->global_eval_fun() || |
| 6578 !args[1]->IsString()) { | 6579 !args[1]->IsString()) { |
| 6579 return MakePair(*callee, Top::context()->global()->global_receiver()); | 6580 return MakePair(*callee, Top::context()->global()->global_receiver()); |
| 6580 } | 6581 } |
| 6581 | 6582 |
| 6582 // Deal with a normal eval call with a string argument. Compile it | 6583 // Deal with a normal eval call with a string argument. Compile it |
| 6583 // and return the compiled function bound in the local context. | 6584 // and return the compiled function bound in the local context. |
| 6584 Handle<String> source = args.at<String>(1); | 6585 Handle<String> source = args.at<String>(1); |
| 6585 Handle<JSFunction> boilerplate = Compiler::CompileEval( | 6586 Handle<SharedFunctionInfo> shared = Compiler::CompileEval( |
| 6586 source, | 6587 source, |
| 6587 Handle<Context>(Top::context()), | 6588 Handle<Context>(Top::context()), |
| 6588 Top::context()->IsGlobalContext(), | 6589 Top::context()->IsGlobalContext(), |
| 6589 Compiler::DONT_VALIDATE_JSON); | 6590 Compiler::DONT_VALIDATE_JSON); |
| 6590 if (boilerplate.is_null()) return MakePair(Failure::Exception(), NULL); | 6591 if (shared.is_null()) return MakePair(Failure::Exception(), NULL); |
| 6591 callee = Factory::NewFunctionFromBoilerplate( | 6592 callee = Factory::NewFunctionFromSharedFunctionInfo( |
| 6592 boilerplate, | 6593 shared, |
| 6593 Handle<Context>(Top::context()), | 6594 Handle<Context>(Top::context()), |
| 6594 NOT_TENURED); | 6595 NOT_TENURED); |
| 6595 return MakePair(*callee, args[2]); | 6596 return MakePair(*callee, args[2]); |
| 6596 } | 6597 } |
| 6597 | 6598 |
| 6598 | 6599 |
| 6599 static Object* Runtime_SetNewFunctionAttributes(Arguments args) { | 6600 static Object* Runtime_SetNewFunctionAttributes(Arguments args) { |
| 6600 // This utility adjusts the property attributes for newly created Function | 6601 // This utility adjusts the property attributes for newly created Function |
| 6601 // object ("new Function(...)") by changing the map. | 6602 // object ("new Function(...)") by changing the map. |
| 6602 // All it does is changing the prototype property to enumerable | 6603 // All it does is changing the prototype property to enumerable |
| (...skipping 1961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8564 // created context. The function has one parameter which has to be called | 8565 // created context. The function has one parameter which has to be called |
| 8565 // 'arguments'. This it to have access to what would have been 'arguments' in | 8566 // 'arguments'. This it to have access to what would have been 'arguments' in |
| 8566 // the function being debugged. | 8567 // the function being debugged. |
| 8567 // function(arguments,__source__) {return eval(__source__);} | 8568 // function(arguments,__source__) {return eval(__source__);} |
| 8568 static const char* source_str = | 8569 static const char* source_str = |
| 8569 "(function(arguments,__source__){return eval(__source__);})"; | 8570 "(function(arguments,__source__){return eval(__source__);})"; |
| 8570 static const int source_str_length = StrLength(source_str); | 8571 static const int source_str_length = StrLength(source_str); |
| 8571 Handle<String> function_source = | 8572 Handle<String> function_source = |
| 8572 Factory::NewStringFromAscii(Vector<const char>(source_str, | 8573 Factory::NewStringFromAscii(Vector<const char>(source_str, |
| 8573 source_str_length)); | 8574 source_str_length)); |
| 8574 Handle<JSFunction> boilerplate = | 8575 Handle<SharedFunctionInfo> shared = |
| 8575 Compiler::CompileEval(function_source, | 8576 Compiler::CompileEval(function_source, |
| 8576 context, | 8577 context, |
| 8577 context->IsGlobalContext(), | 8578 context->IsGlobalContext(), |
| 8578 Compiler::DONT_VALIDATE_JSON); | 8579 Compiler::DONT_VALIDATE_JSON); |
| 8579 if (boilerplate.is_null()) return Failure::Exception(); | 8580 if (shared.is_null()) return Failure::Exception(); |
| 8580 Handle<JSFunction> compiled_function = | 8581 Handle<JSFunction> compiled_function = |
| 8581 Factory::NewFunctionFromBoilerplate(boilerplate, context); | 8582 Factory::NewFunctionFromSharedFunctionInfo(shared, context); |
| 8582 | 8583 |
| 8583 // Invoke the result of the compilation to get the evaluation function. | 8584 // Invoke the result of the compilation to get the evaluation function. |
| 8584 bool has_pending_exception; | 8585 bool has_pending_exception; |
| 8585 Handle<Object> receiver(frame->receiver()); | 8586 Handle<Object> receiver(frame->receiver()); |
| 8586 Handle<Object> evaluation_function = | 8587 Handle<Object> evaluation_function = |
| 8587 Execution::Call(compiled_function, receiver, 0, NULL, | 8588 Execution::Call(compiled_function, receiver, 0, NULL, |
| 8588 &has_pending_exception); | 8589 &has_pending_exception); |
| 8589 if (has_pending_exception) return Failure::Exception(); | 8590 if (has_pending_exception) return Failure::Exception(); |
| 8590 | 8591 |
| 8591 Handle<Object> arguments = GetArgumentsObject(frame, function, code, &sinfo, | 8592 Handle<Object> arguments = GetArgumentsObject(frame, function, code, &sinfo, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8632 } | 8633 } |
| 8633 if (top != NULL) { | 8634 if (top != NULL) { |
| 8634 Top::set_context(*top->context()); | 8635 Top::set_context(*top->context()); |
| 8635 } | 8636 } |
| 8636 | 8637 |
| 8637 // Get the global context now set to the top context from before the | 8638 // Get the global context now set to the top context from before the |
| 8638 // debugger was invoked. | 8639 // debugger was invoked. |
| 8639 Handle<Context> context = Top::global_context(); | 8640 Handle<Context> context = Top::global_context(); |
| 8640 | 8641 |
| 8641 // Compile the source to be evaluated. | 8642 // Compile the source to be evaluated. |
| 8642 Handle<JSFunction> boilerplate = | 8643 Handle<SharedFunctionInfo> shared = |
| 8643 Handle<JSFunction>(Compiler::CompileEval(source, | 8644 Compiler::CompileEval(source, |
| 8644 context, | 8645 context, |
| 8645 true, | 8646 true, |
| 8646 Compiler::DONT_VALIDATE_JSON)); | 8647 Compiler::DONT_VALIDATE_JSON); |
| 8647 if (boilerplate.is_null()) return Failure::Exception(); | 8648 if (shared.is_null()) return Failure::Exception(); |
| 8648 Handle<JSFunction> compiled_function = | 8649 Handle<JSFunction> compiled_function = |
| 8649 Handle<JSFunction>(Factory::NewFunctionFromBoilerplate(boilerplate, | 8650 Handle<JSFunction>(Factory::NewFunctionFromSharedFunctionInfo(shared, |
| 8650 context)); | 8651 context)); |
| 8651 | 8652 |
| 8652 // Invoke the result of the compilation to get the evaluation function. | 8653 // Invoke the result of the compilation to get the evaluation function. |
| 8653 bool has_pending_exception; | 8654 bool has_pending_exception; |
| 8654 Handle<Object> receiver = Top::global(); | 8655 Handle<Object> receiver = Top::global(); |
| 8655 Handle<Object> result = | 8656 Handle<Object> result = |
| 8656 Execution::Call(compiled_function, receiver, 0, NULL, | 8657 Execution::Call(compiled_function, receiver, 0, NULL, |
| 8657 &has_pending_exception); | 8658 &has_pending_exception); |
| 8658 if (has_pending_exception) return Failure::Exception(); | 8659 if (has_pending_exception) return Failure::Exception(); |
| 8659 return *result; | 8660 return *result; |
| 8660 } | 8661 } |
| (...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9424 } else { | 9425 } else { |
| 9425 // Handle last resort GC and make sure to allow future allocations | 9426 // Handle last resort GC and make sure to allow future allocations |
| 9426 // to grow the heap without causing GCs (if possible). | 9427 // to grow the heap without causing GCs (if possible). |
| 9427 Counters::gc_last_resort_from_js.Increment(); | 9428 Counters::gc_last_resort_from_js.Increment(); |
| 9428 Heap::CollectAllGarbage(false); | 9429 Heap::CollectAllGarbage(false); |
| 9429 } | 9430 } |
| 9430 } | 9431 } |
| 9431 | 9432 |
| 9432 | 9433 |
| 9433 } } // namespace v8::internal | 9434 } } // namespace v8::internal |
| OLD | NEW |