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 1649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1660 } | 1660 } |
1661 Expect(Token::RPAREN, CHECK_OK); | 1661 Expect(Token::RPAREN, CHECK_OK); |
1662 Expect(Token::SEMICOLON, CHECK_OK); | 1662 Expect(Token::SEMICOLON, CHECK_OK); |
1663 | 1663 |
1664 // Make sure that the function containing the native declaration | 1664 // Make sure that the function containing the native declaration |
1665 // isn't lazily compiled. The extension structures are only | 1665 // isn't lazily compiled. The extension structures are only |
1666 // accessible while parsing the first time not when reparsing | 1666 // accessible while parsing the first time not when reparsing |
1667 // because of lazy compilation. | 1667 // because of lazy compilation. |
1668 DeclarationScope(VAR)->ForceEagerCompilation(); | 1668 DeclarationScope(VAR)->ForceEagerCompilation(); |
1669 | 1669 |
1670 // Compute the function template for the native function. | |
1671 v8::Handle<v8::FunctionTemplate> fun_template = | |
1672 extension_->GetNativeFunction(v8::Utils::ToLocal(name)); | |
1673 ASSERT(!fun_template.IsEmpty()); | |
1674 | |
1675 // Instantiate the function and create a shared function info from it. | |
1676 Handle<JSFunction> fun = Utils::OpenHandle(*fun_template->GetFunction()); | |
1677 const int literals = fun->NumberOfLiterals(); | |
1678 Handle<Code> code = Handle<Code>(fun->shared()->code()); | |
1679 Handle<Code> construct_stub = Handle<Code>(fun->shared()->construct_stub()); | |
1680 bool is_generator = false; | |
1681 Handle<SharedFunctionInfo> shared = | |
1682 isolate()->factory()->NewSharedFunctionInfo(name, literals, is_generator, | |
1683 code, Handle<ScopeInfo>(fun->shared()->scope_info())); | |
1684 shared->set_construct_stub(*construct_stub); | |
1685 | |
1686 // Copy the function data to the shared function info. | |
1687 shared->set_function_data(fun->shared()->function_data()); | |
1688 int parameters = fun->shared()->formal_parameter_count(); | |
1689 shared->set_formal_parameter_count(parameters); | |
1690 | |
1691 // TODO(1240846): It's weird that native function declarations are | 1670 // TODO(1240846): It's weird that native function declarations are |
1692 // introduced dynamically when we meet their declarations, whereas | 1671 // introduced dynamically when we meet their declarations, whereas |
1693 // other functions are set up when entering the surrounding scope. | 1672 // other functions are set up when entering the surrounding scope. |
1694 VariableProxy* proxy = NewUnresolved(name, VAR, Interface::NewValue()); | 1673 VariableProxy* proxy = NewUnresolved(name, VAR, Interface::NewValue()); |
1695 Declaration* declaration = | 1674 Declaration* declaration = |
1696 factory()->NewVariableDeclaration(proxy, VAR, top_scope_); | 1675 factory()->NewVariableDeclaration(proxy, VAR, top_scope_); |
1697 Declare(declaration, true, CHECK_OK); | 1676 Declare(declaration, true, CHECK_OK); |
1698 SharedFunctionInfoLiteral* lit = | 1677 NativeFunctionLiteral* lit = factory()->NewNativeFunctionLiteral(name); |
1699 factory()->NewSharedFunctionInfoLiteral(shared); | |
1700 return factory()->NewExpressionStatement( | 1678 return factory()->NewExpressionStatement( |
1701 factory()->NewAssignment( | 1679 factory()->NewAssignment( |
1702 Token::INIT_VAR, proxy, lit, RelocInfo::kNoPosition)); | 1680 Token::INIT_VAR, proxy, lit, RelocInfo::kNoPosition)); |
1703 } | 1681 } |
1704 | 1682 |
1705 | 1683 |
1706 Statement* Parser::ParseFunctionDeclaration(ZoneStringList* names, bool* ok) { | 1684 Statement* Parser::ParseFunctionDeclaration(ZoneStringList* names, bool* ok) { |
1707 // FunctionDeclaration :: | 1685 // FunctionDeclaration :: |
1708 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' | 1686 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' |
1709 // GeneratorDeclaration :: | 1687 // GeneratorDeclaration :: |
(...skipping 4266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5976 ASSERT(info()->isolate()->has_pending_exception()); | 5954 ASSERT(info()->isolate()->has_pending_exception()); |
5977 } else { | 5955 } else { |
5978 result = ParseProgram(); | 5956 result = ParseProgram(); |
5979 } | 5957 } |
5980 } | 5958 } |
5981 info()->SetFunction(result); | 5959 info()->SetFunction(result); |
5982 return (result != NULL); | 5960 return (result != NULL); |
5983 } | 5961 } |
5984 | 5962 |
5985 } } // namespace v8::internal | 5963 } } // namespace v8::internal |
OLD | NEW |