Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: src/parser.cc

Issue 6614010: [Isolates] Merge 6700:7030 from bleeding_edge to isolates. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/isolates/
Patch Set: '' Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/oprofile-agent.cc ('k') | src/platform.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 1095 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 InitializationBlockFinder block_finder; 1106 InitializationBlockFinder block_finder;
1107 ThisNamedPropertyAssigmentFinder this_property_assignment_finder; 1107 ThisNamedPropertyAssigmentFinder this_property_assignment_finder;
1108 bool directive_prologue = true; // Parsing directive prologue. 1108 bool directive_prologue = true; // Parsing directive prologue.
1109 1109
1110 while (peek() != end_token) { 1110 while (peek() != end_token) {
1111 if (directive_prologue && peek() != Token::STRING) { 1111 if (directive_prologue && peek() != Token::STRING) {
1112 directive_prologue = false; 1112 directive_prologue = false;
1113 } 1113 }
1114 1114
1115 Scanner::Location token_loc = scanner().peek_location(); 1115 Scanner::Location token_loc = scanner().peek_location();
1116 Statement* stat = ParseStatement(NULL, CHECK_OK); 1116
1117 Statement* stat;
1118 if (peek() == Token::FUNCTION) {
1119 // FunctionDeclaration is only allowed in the context of SourceElements
1120 // (Ecma 262 5th Edition, clause 14):
1121 // SourceElement:
1122 // Statement
1123 // FunctionDeclaration
1124 // Common language extension is to allow function declaration in place
1125 // of any statement. This language extension is disabled in strict mode.
1126 stat = ParseFunctionDeclaration(CHECK_OK);
1127 } else {
1128 stat = ParseStatement(NULL, CHECK_OK);
1129 }
1117 1130
1118 if (stat == NULL || stat->IsEmpty()) { 1131 if (stat == NULL || stat->IsEmpty()) {
1119 directive_prologue = false; // End of directive prologue. 1132 directive_prologue = false; // End of directive prologue.
1120 continue; 1133 continue;
1121 } 1134 }
1122 1135
1123 if (directive_prologue) { 1136 if (directive_prologue) {
1124 // A shot at a directive. 1137 // A shot at a directive.
1125 ExpressionStatement *e_stat; 1138 ExpressionStatement *e_stat;
1126 Literal *literal; 1139 Literal *literal;
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1263 Block* result = new Block(labels, 1, false); 1276 Block* result = new Block(labels, 1, false);
1264 Target target(&this->target_stack_, result); 1277 Target target(&this->target_stack_, result);
1265 TryStatement* statement = ParseTryStatement(CHECK_OK); 1278 TryStatement* statement = ParseTryStatement(CHECK_OK);
1266 if (statement) { 1279 if (statement) {
1267 statement->set_statement_pos(statement_pos); 1280 statement->set_statement_pos(statement_pos);
1268 } 1281 }
1269 if (result) result->AddStatement(statement); 1282 if (result) result->AddStatement(statement);
1270 return result; 1283 return result;
1271 } 1284 }
1272 1285
1273 case Token::FUNCTION: 1286 case Token::FUNCTION: {
1287 // In strict mode, FunctionDeclaration is only allowed in the context
1288 // of SourceElements.
1289 if (temp_scope_->StrictMode()) {
1290 ReportMessageAt(scanner().peek_location(), "strict_function",
1291 Vector<const char*>::empty());
1292 *ok = false;
1293 return NULL;
1294 }
1274 return ParseFunctionDeclaration(ok); 1295 return ParseFunctionDeclaration(ok);
1296 }
1275 1297
1276 case Token::NATIVE: 1298 case Token::NATIVE:
1277 return ParseNativeDeclaration(ok); 1299 return ParseNativeDeclaration(ok);
1278 1300
1279 case Token::DEBUGGER: 1301 case Token::DEBUGGER:
1280 stmt = ParseDebuggerStatement(ok); 1302 stmt = ParseDebuggerStatement(ok);
1281 break; 1303 break;
1282 1304
1283 default: 1305 default:
1284 stmt = ParseExpressionOrLabelledStatement(labels, ok); 1306 stmt = ParseExpressionOrLabelledStatement(labels, ok);
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
1515 bool* ok) { 1537 bool* ok) {
1516 // VariableDeclarations :: 1538 // VariableDeclarations ::
1517 // ('var' | 'const') (Identifier ('=' AssignmentExpression)?)+[','] 1539 // ('var' | 'const') (Identifier ('=' AssignmentExpression)?)+[',']
1518 1540
1519 Variable::Mode mode = Variable::VAR; 1541 Variable::Mode mode = Variable::VAR;
1520 bool is_const = false; 1542 bool is_const = false;
1521 if (peek() == Token::VAR) { 1543 if (peek() == Token::VAR) {
1522 Consume(Token::VAR); 1544 Consume(Token::VAR);
1523 } else if (peek() == Token::CONST) { 1545 } else if (peek() == Token::CONST) {
1524 Consume(Token::CONST); 1546 Consume(Token::CONST);
1547 if (temp_scope_->StrictMode()) {
1548 ReportMessage("strict_const", Vector<const char*>::empty());
1549 *ok = false;
1550 return NULL;
1551 }
1525 mode = Variable::CONST; 1552 mode = Variable::CONST;
1526 is_const = true; 1553 is_const = true;
1527 } else { 1554 } else {
1528 UNREACHABLE(); // by current callers 1555 UNREACHABLE(); // by current callers
1529 } 1556 }
1530 1557
1531 // The scope of a variable/const declared anywhere inside a function 1558 // The scope of a variable/const declared anywhere inside a function
1532 // is the entire function (ECMA-262, 3rd, 10.1.3, and 12.2). Thus we can 1559 // is the entire function (ECMA-262, 3rd, 10.1.3, and 12.2). Thus we can
1533 // transform a source-level variable/const declaration into a (Function) 1560 // transform a source-level variable/const declaration into a (Function)
1534 // Scope declaration, and rewrite the source-level initialization into an 1561 // Scope declaration, and rewrite the source-level initialization into an
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1634 // guarantee to give the global object a "local" variable; a 1661 // guarantee to give the global object a "local" variable; a
1635 // variable defined in the global object and not in any 1662 // variable defined in the global object and not in any
1636 // prototype. This way, global variable declarations can shadow 1663 // prototype. This way, global variable declarations can shadow
1637 // properties in the prototype chain, but only after the variable 1664 // properties in the prototype chain, but only after the variable
1638 // declaration statement has been executed. This is important in 1665 // declaration statement has been executed. This is important in
1639 // browsers where the global object (window) has lots of 1666 // browsers where the global object (window) has lots of
1640 // properties defined in prototype objects. 1667 // properties defined in prototype objects.
1641 1668
1642 if (top_scope_->is_global_scope()) { 1669 if (top_scope_->is_global_scope()) {
1643 // Compute the arguments for the runtime call. 1670 // Compute the arguments for the runtime call.
1644 ZoneList<Expression*>* arguments = new ZoneList<Expression*>(2); 1671 ZoneList<Expression*>* arguments = new ZoneList<Expression*>(3);
1645 // Be careful not to assign a value to the global variable if
1646 // we're in a with. The initialization value should not
1647 // necessarily be stored in the global object in that case,
1648 // which is why we need to generate a separate assignment node.
1649 arguments->Add(new Literal(name)); // we have at least 1 parameter 1672 arguments->Add(new Literal(name)); // we have at least 1 parameter
1650 if (is_const || (value != NULL && !inside_with())) { 1673 CallRuntime* initialize;
1674
1675 if (is_const) {
1651 arguments->Add(value); 1676 arguments->Add(value);
1652 value = NULL; // zap the value to avoid the unnecessary assignment 1677 value = NULL; // zap the value to avoid the unnecessary assignment
1678
1679 // Construct the call to Runtime_InitializeConstGlobal
1680 // and add it to the initialization statement block.
1681 // Note that the function does different things depending on
1682 // the number of arguments (1 or 2).
1683 initialize =
1684 new CallRuntime(
1685 isolate()->factory()->InitializeConstGlobal_symbol(),
1686 Runtime::FunctionForId(Runtime::kInitializeConstGlobal),
1687 arguments);
1688 } else {
1689 // Add strict mode.
1690 // We may want to pass singleton to avoid Literal allocations.
1691 arguments->Add(NewNumberLiteral(
1692 temp_scope_->StrictMode() ? kStrictMode : kNonStrictMode));
1693
1694 // Be careful not to assign a value to the global variable if
1695 // we're in a with. The initialization value should not
1696 // necessarily be stored in the global object in that case,
1697 // which is why we need to generate a separate assignment node.
1698 if (value != NULL && !inside_with()) {
1699 arguments->Add(value);
1700 value = NULL; // zap the value to avoid the unnecessary assignment
1701 }
1702
1703 // Construct the call to Runtime_InitializeVarGlobal
1704 // and add it to the initialization statement block.
1705 // Note that the function does different things depending on
1706 // the number of arguments (2 or 3).
1707 initialize =
1708 new CallRuntime(
1709 isolate()->factory()->InitializeVarGlobal_symbol(),
1710 Runtime::FunctionForId(Runtime::kInitializeVarGlobal),
1711 arguments);
1653 } 1712 }
1654 // Construct the call to Runtime::DeclareGlobal{Variable,Const}Locally 1713
1655 // and add it to the initialization statement block. Note that
1656 // this function does different things depending on if we have
1657 // 1 or 2 parameters.
1658 CallRuntime* initialize;
1659 if (is_const) {
1660 initialize =
1661 new CallRuntime(
1662 isolate()->factory()->InitializeConstGlobal_symbol(),
1663 Runtime::FunctionForId(Runtime::kInitializeConstGlobal),
1664 arguments);
1665 } else {
1666 initialize =
1667 new CallRuntime(
1668 isolate()->factory()->InitializeVarGlobal_symbol(),
1669 Runtime::FunctionForId(Runtime::kInitializeVarGlobal),
1670 arguments);
1671 }
1672 block->AddStatement(new ExpressionStatement(initialize)); 1714 block->AddStatement(new ExpressionStatement(initialize));
1673 } 1715 }
1674 1716
1675 // Add an assignment node to the initialization statement block if 1717 // Add an assignment node to the initialization statement block if
1676 // we still have a pending initialization value. We must distinguish 1718 // we still have a pending initialization value. We must distinguish
1677 // between variables and constants: Variable initializations are simply 1719 // between variables and constants: Variable initializations are simply
1678 // assignments (with all the consequences if they are inside a 'with' 1720 // assignments (with all the consequences if they are inside a 'with'
1679 // statement - they may change a 'with' object property). Constant 1721 // statement - they may change a 'with' object property). Constant
1680 // initializations always assign to the declared constant which is 1722 // initializations always assign to the declared constant which is
1681 // always at the function scope level. This is only relevant for 1723 // always at the function scope level. This is only relevant for
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after
2524 case Token::ADD: 2566 case Token::ADD:
2525 return expression; 2567 return expression;
2526 case Token::SUB: 2568 case Token::SUB:
2527 return NewNumberLiteral(-value); 2569 return NewNumberLiteral(-value);
2528 case Token::BIT_NOT: 2570 case Token::BIT_NOT:
2529 return NewNumberLiteral(~DoubleToInt32(value)); 2571 return NewNumberLiteral(~DoubleToInt32(value));
2530 default: break; 2572 default: break;
2531 } 2573 }
2532 } 2574 }
2533 2575
2576 // "delete identifier" is a syntax error in strict mode.
2577 if (op == Token::DELETE && temp_scope_->StrictMode()) {
2578 VariableProxy* operand = expression->AsVariableProxy();
2579 if (operand != NULL && !operand->is_this()) {
2580 ReportMessage("strict_delete", Vector<const char*>::empty());
2581 *ok = false;
2582 return NULL;
2583 }
2584 }
2585
2534 return new UnaryOperation(op, expression); 2586 return new UnaryOperation(op, expression);
2535 2587
2536 } else if (Token::IsCountOp(op)) { 2588 } else if (Token::IsCountOp(op)) {
2537 op = Next(); 2589 op = Next();
2538 Expression* expression = ParseUnaryExpression(CHECK_OK); 2590 Expression* expression = ParseUnaryExpression(CHECK_OK);
2539 // Signal a reference error if the expression is an invalid 2591 // Signal a reference error if the expression is an invalid
2540 // left-hand side expression. We could report this as a syntax 2592 // left-hand side expression. We could report this as a syntax
2541 // error here but for compatibility with JSC we choose to report the 2593 // error here but for compatibility with JSC we choose to report the
2542 // error at runtime. 2594 // error at runtime.
2543 if (expression == NULL || !expression->IsValidLeftHandSide()) { 2595 if (expression == NULL || !expression->IsValidLeftHandSide()) {
(...skipping 1389 matching lines...) Expand 10 before | Expand all | Expand 10 after
3933 HandleVector<Object>(elements, ARRAY_SIZE(elements)); 3985 HandleVector<Object>(elements, ARRAY_SIZE(elements));
3934 return NewThrowError( 3986 return NewThrowError(
3935 isolate()->factory()->MakeTypeError_symbol(), type, arguments); 3987 isolate()->factory()->MakeTypeError_symbol(), type, arguments);
3936 } 3988 }
3937 3989
3938 3990
3939 Expression* Parser::NewThrowError(Handle<String> constructor, 3991 Expression* Parser::NewThrowError(Handle<String> constructor,
3940 Handle<String> type, 3992 Handle<String> type,
3941 Vector< Handle<Object> > arguments) { 3993 Vector< Handle<Object> > arguments) {
3942 int argc = arguments.length(); 3994 int argc = arguments.length();
3943 Handle<JSArray> array = isolate()->factory()->NewJSArray(argc, TENURED); 3995 Handle<FixedArray> elements = isolate()->factory()->NewFixedArray(argc,
3944 ASSERT(array->IsJSArray() && array->HasFastElements()); 3996 TENURED);
3945 for (int i = 0; i < argc; i++) { 3997 for (int i = 0; i < argc; i++) {
3946 Handle<Object> element = arguments[i]; 3998 Handle<Object> element = arguments[i];
3947 if (!element.is_null()) { 3999 if (!element.is_null()) {
3948 // We know this doesn't cause a GC here because we allocated the JSArray 4000 elements->set(i, *element);
3949 // large enough.
3950 array->SetFastElement(i, *element)->ToObjectUnchecked();
3951 } 4001 }
3952 } 4002 }
4003 Handle<JSArray> array = isolate()->factory()->NewJSArrayWithElements(elements,
4004 TENURED);
4005
3953 ZoneList<Expression*>* args = new ZoneList<Expression*>(2); 4006 ZoneList<Expression*>* args = new ZoneList<Expression*>(2);
3954 args->Add(new Literal(type)); 4007 args->Add(new Literal(type));
3955 args->Add(new Literal(array)); 4008 args->Add(new Literal(array));
3956 return new Throw(new CallRuntime(constructor, NULL, args), 4009 return new Throw(new CallRuntime(constructor, NULL, args),
3957 scanner().location().beg_pos); 4010 scanner().location().beg_pos);
3958 } 4011 }
3959 4012
3960 // ---------------------------------------------------------------------------- 4013 // ----------------------------------------------------------------------------
3961 // JSON 4014 // JSON
3962 4015
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
4280 body = capture; 4333 body = capture;
4281 } else if (type != GROUPING) { 4334 } else if (type != GROUPING) {
4282 ASSERT(type == POSITIVE_LOOKAHEAD || type == NEGATIVE_LOOKAHEAD); 4335 ASSERT(type == POSITIVE_LOOKAHEAD || type == NEGATIVE_LOOKAHEAD);
4283 bool is_positive = (type == POSITIVE_LOOKAHEAD); 4336 bool is_positive = (type == POSITIVE_LOOKAHEAD);
4284 body = new RegExpLookahead(body, 4337 body = new RegExpLookahead(body,
4285 is_positive, 4338 is_positive,
4286 end_capture_index - capture_index, 4339 end_capture_index - capture_index,
4287 capture_index); 4340 capture_index);
4288 } 4341 }
4289 builder->AddAtom(body); 4342 builder->AddAtom(body);
4343 // For compatability with JSC and ES3, we allow quantifiers after
4344 // lookaheads, and break in all cases.
4290 break; 4345 break;
4291 } 4346 }
4292 case '|': { 4347 case '|': {
4293 Advance(); 4348 Advance();
4294 builder->NewAlternative(); 4349 builder->NewAlternative();
4295 continue; 4350 continue;
4296 } 4351 }
4297 case '*': 4352 case '*':
4298 case '+': 4353 case '+':
4299 case '?': 4354 case '?':
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
4353 if (captures_started() >= kMaxCaptures) { 4408 if (captures_started() >= kMaxCaptures) {
4354 ReportError(CStrVector("Too many captures") CHECK_FAILED); 4409 ReportError(CStrVector("Too many captures") CHECK_FAILED);
4355 } 4410 }
4356 captures_->Add(NULL); 4411 captures_->Add(NULL);
4357 } 4412 }
4358 // Store current state and begin new disjunction parsing. 4413 // Store current state and begin new disjunction parsing.
4359 stored_state = new RegExpParserState(stored_state, 4414 stored_state = new RegExpParserState(stored_state,
4360 type, 4415 type,
4361 captures_started()); 4416 captures_started());
4362 builder = stored_state->builder(); 4417 builder = stored_state->builder();
4363 break; 4418 continue;
4364 } 4419 }
4365 case '[': { 4420 case '[': {
4366 RegExpTree* atom = ParseCharacterClass(CHECK_FAILED); 4421 RegExpTree* atom = ParseCharacterClass(CHECK_FAILED);
4367 builder->AddAtom(atom); 4422 builder->AddAtom(atom);
4368 break; 4423 break;
4369 } 4424 }
4370 // Atom :: 4425 // Atom ::
4371 // \ AtomEscape 4426 // \ AtomEscape
4372 case '\\': 4427 case '\\':
4373 switch (Next()) { 4428 switch (Next()) {
4374 case kEndMarker: 4429 case kEndMarker:
4375 return ReportError(CStrVector("\\ at end of pattern")); 4430 return ReportError(CStrVector("\\ at end of pattern"));
4376 case 'b': 4431 case 'b':
4377 Advance(2); 4432 Advance(2);
4378 builder->AddAssertion( 4433 builder->AddAssertion(
4379 new RegExpAssertion(RegExpAssertion::BOUNDARY)); 4434 new RegExpAssertion(RegExpAssertion::BOUNDARY));
4380 continue; 4435 continue;
4381 case 'B': 4436 case 'B':
4382 Advance(2); 4437 Advance(2);
4383 builder->AddAssertion( 4438 builder->AddAssertion(
4384 new RegExpAssertion(RegExpAssertion::NON_BOUNDARY)); 4439 new RegExpAssertion(RegExpAssertion::NON_BOUNDARY));
4385 continue; 4440 continue;
4386 // AtomEscape :: 4441 // AtomEscape ::
4387 // CharacterClassEscape 4442 // CharacterClassEscape
4388 // 4443 //
4389 // CharacterClassEscape :: one of 4444 // CharacterClassEscape :: one of
4390 // d D s S w W 4445 // d D s S w W
4391 case 'd': case 'D': case 's': case 'S': case 'w': case 'W': { 4446 case 'd': case 'D': case 's': case 'S': case 'w': case 'W': {
4392 uc32 c = Next(); 4447 uc32 c = Next();
4393 Advance(2); 4448 Advance(2);
4394 ZoneList<CharacterRange>* ranges = new ZoneList<CharacterRange>(2); 4449 ZoneList<CharacterRange>* ranges = new ZoneList<CharacterRange>(2);
4395 CharacterRange::AddClassEscape(c, ranges); 4450 CharacterRange::AddClassEscape(c, ranges);
4396 RegExpTree* atom = new RegExpCharacterClass(ranges, false); 4451 RegExpTree* atom = new RegExpCharacterClass(ranges, false);
4397 builder->AddAtom(atom); 4452 builder->AddAtom(atom);
4398 break; 4453 break;
4399 } 4454 }
4400 case '1': case '2': case '3': case '4': case '5': case '6': 4455 case '1': case '2': case '3': case '4': case '5': case '6':
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after
5104 info->is_global(), 5159 info->is_global(),
5105 info->StrictMode()); 5160 info->StrictMode());
5106 } 5161 }
5107 } 5162 }
5108 5163
5109 info->SetFunction(result); 5164 info->SetFunction(result);
5110 return (result != NULL); 5165 return (result != NULL);
5111 } 5166 }
5112 5167
5113 } } // namespace v8::internal 5168 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/oprofile-agent.cc ('k') | src/platform.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698