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

Side by Side Diff: src/runtime.cc

Issue 7671042: Temporal dead zone behaviour for let bindings. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Bailout in hydrogen and X64 and ARM code. Created 9 years, 3 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
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 1278 matching lines...) Expand 10 before | Expand all | Expand 10 after
1289 PropertyAttributes mode = static_cast<PropertyAttributes>(args.smi_at(2)); 1289 PropertyAttributes mode = static_cast<PropertyAttributes>(args.smi_at(2));
1290 RUNTIME_ASSERT(mode == READ_ONLY || mode == NONE); 1290 RUNTIME_ASSERT(mode == READ_ONLY || mode == NONE);
1291 Handle<Object> initial_value(args[3], isolate); 1291 Handle<Object> initial_value(args[3], isolate);
1292 1292
1293 // Declarations are always done in a function or global context. 1293 // Declarations are always done in a function or global context.
1294 context = Handle<Context>(context->declaration_context()); 1294 context = Handle<Context>(context->declaration_context());
1295 1295
1296 int index; 1296 int index;
1297 PropertyAttributes attributes; 1297 PropertyAttributes attributes;
1298 ContextLookupFlags flags = DONT_FOLLOW_CHAINS; 1298 ContextLookupFlags flags = DONT_FOLLOW_CHAINS;
1299 BindingFlags binding_flags;
1299 Handle<Object> holder = 1300 Handle<Object> holder =
1300 context->Lookup(name, flags, &index, &attributes); 1301 context->Lookup(name, flags, &index, &attributes, &binding_flags);
1301 1302
1302 if (attributes != ABSENT) { 1303 if (attributes != ABSENT) {
1303 // The name was declared before; check for conflicting 1304 // The name was declared before; check for conflicting
1304 // re-declarations: This is similar to the code in parser.cc in 1305 // re-declarations: This is similar to the code in parser.cc in
1305 // the AstBuildingParser::Declare function. 1306 // the AstBuildingParser::Declare function.
1306 if (((attributes & READ_ONLY) != 0) || (mode == READ_ONLY)) { 1307 if (((attributes & READ_ONLY) != 0) || (mode == READ_ONLY)) {
1307 // Functions are not read-only. 1308 // Functions are not read-only.
1308 ASSERT(mode != READ_ONLY || initial_value->IsTheHole()); 1309 ASSERT(mode != READ_ONLY || initial_value->IsTheHole());
1309 const char* type = ((attributes & READ_ONLY) != 0) ? "const" : "var"; 1310 const char* type = ((attributes & READ_ONLY) != 0) ? "const" : "var";
1310 return ThrowRedeclarationError(isolate, type, name); 1311 return ThrowRedeclarationError(isolate, type, name);
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1577 ASSERT(!value->IsTheHole()); 1578 ASSERT(!value->IsTheHole());
1578 CONVERT_ARG_CHECKED(Context, context, 1); 1579 CONVERT_ARG_CHECKED(Context, context, 1);
1579 Handle<String> name(String::cast(args[2])); 1580 Handle<String> name(String::cast(args[2]));
1580 1581
1581 // Initializations are always done in a function or global context. 1582 // Initializations are always done in a function or global context.
1582 context = Handle<Context>(context->declaration_context()); 1583 context = Handle<Context>(context->declaration_context());
1583 1584
1584 int index; 1585 int index;
1585 PropertyAttributes attributes; 1586 PropertyAttributes attributes;
1586 ContextLookupFlags flags = FOLLOW_CHAINS; 1587 ContextLookupFlags flags = FOLLOW_CHAINS;
1588 BindingFlags binding_flags;
1587 Handle<Object> holder = 1589 Handle<Object> holder =
1588 context->Lookup(name, flags, &index, &attributes); 1590 context->Lookup(name, flags, &index, &attributes, &binding_flags);
1589 1591
1590 // In most situations, the property introduced by the const 1592 // In most situations, the property introduced by the const
1591 // declaration should be present in the context extension object. 1593 // declaration should be present in the context extension object.
1592 // However, because declaration and initialization are separate, the 1594 // However, because declaration and initialization are separate, the
1593 // property might have been deleted (if it was introduced by eval) 1595 // property might have been deleted (if it was introduced by eval)
1594 // before we reach the initialization point. 1596 // before we reach the initialization point.
1595 // 1597 //
1596 // Example: 1598 // Example:
1597 // 1599 //
1598 // function f() { eval("delete x; const x;"); } 1600 // function f() { eval("delete x; const x;"); }
(...skipping 6744 matching lines...) Expand 10 before | Expand all | Expand 10 after
8343 RUNTIME_FUNCTION(MaybeObject*, Runtime_DeleteContextSlot) { 8345 RUNTIME_FUNCTION(MaybeObject*, Runtime_DeleteContextSlot) {
8344 HandleScope scope(isolate); 8346 HandleScope scope(isolate);
8345 ASSERT(args.length() == 2); 8347 ASSERT(args.length() == 2);
8346 8348
8347 CONVERT_ARG_CHECKED(Context, context, 0); 8349 CONVERT_ARG_CHECKED(Context, context, 0);
8348 CONVERT_ARG_CHECKED(String, name, 1); 8350 CONVERT_ARG_CHECKED(String, name, 1);
8349 8351
8350 int index; 8352 int index;
8351 PropertyAttributes attributes; 8353 PropertyAttributes attributes;
8352 ContextLookupFlags flags = FOLLOW_CHAINS; 8354 ContextLookupFlags flags = FOLLOW_CHAINS;
8353 Handle<Object> holder = context->Lookup(name, flags, &index, &attributes); 8355 BindingFlags binding_flags;
8356 Handle<Object> holder = context->Lookup(name,
8357 flags,
8358 &index,
8359 &attributes,
8360 &binding_flags);
8354 8361
8355 // If the slot was not found the result is true. 8362 // If the slot was not found the result is true.
8356 if (holder.is_null()) { 8363 if (holder.is_null()) {
8357 return isolate->heap()->true_value(); 8364 return isolate->heap()->true_value();
8358 } 8365 }
8359 8366
8360 // If the slot was found in a context, it should be DONT_DELETE. 8367 // If the slot was found in a context, it should be DONT_DELETE.
8361 if (holder->IsContext()) { 8368 if (holder->IsContext()) {
8362 return isolate->heap()->false_value(); 8369 return isolate->heap()->false_value();
8363 } 8370 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
8445 8452
8446 if (!args[0]->IsContext() || !args[1]->IsString()) { 8453 if (!args[0]->IsContext() || !args[1]->IsString()) {
8447 return MakePair(isolate->ThrowIllegalOperation(), NULL); 8454 return MakePair(isolate->ThrowIllegalOperation(), NULL);
8448 } 8455 }
8449 Handle<Context> context = args.at<Context>(0); 8456 Handle<Context> context = args.at<Context>(0);
8450 Handle<String> name = args.at<String>(1); 8457 Handle<String> name = args.at<String>(1);
8451 8458
8452 int index; 8459 int index;
8453 PropertyAttributes attributes; 8460 PropertyAttributes attributes;
8454 ContextLookupFlags flags = FOLLOW_CHAINS; 8461 ContextLookupFlags flags = FOLLOW_CHAINS;
8455 Handle<Object> holder = context->Lookup(name, flags, &index, &attributes); 8462 BindingFlags binding_flags;
8463 Handle<Object> holder = context->Lookup(name,
8464 flags,
8465 &index,
8466 &attributes,
8467 &binding_flags);
8456 8468
8457 // If the index is non-negative, the slot has been found in a local 8469 // If the index is non-negative, the slot has been found in a local
8458 // variable or a parameter. Read it from the context object or the 8470 // variable or a parameter. Read it from the context object or the
8459 // arguments object. 8471 // arguments object.
8460 if (index >= 0) { 8472 if (index >= 0) {
8461 // If the "property" we were looking for is a local variable or an 8473 // If the "property" we were looking for is a local variable or an
8462 // argument in a context, the receiver is the global object; see 8474 // argument in a context, the receiver is the global object; see
8463 // ECMA-262, 3rd., 10.1.6 and 10.2.3. 8475 // ECMA-262, 3rd., 10.1.6 and 10.2.3.
8464 // 8476 //
8465 // Use the hole as the receiver to signal that the receiver is 8477 // Use the hole as the receiver to signal that the receiver is
8466 // implicit and that the global receiver should be used. 8478 // implicit and that the global receiver should be used.
8467 Handle<Object> receiver = isolate->factory()->the_hole_value(); 8479 Handle<Object> receiver = isolate->factory()->the_hole_value();
8468 MaybeObject* value = (holder->IsContext()) 8480 MaybeObject* value = (holder->IsContext())
8469 ? Context::cast(*holder)->get(index) 8481 ? Context::cast(*holder)->get(index)
8470 : JSObject::cast(*holder)->GetElement(index); 8482 : JSObject::cast(*holder)->GetElement(index);
8471 return MakePair(Unhole(isolate->heap(), value, attributes), *receiver); 8483 // Check for uninitialized bindings.
8484 if (holder->IsContext() &&
8485 binding_flags == MUTABLE_CHECK_INITIALIZED &&
8486 value->IsTheHole()) {
8487 Handle<Object> reference_error =
8488 isolate->factory()->NewReferenceError("not_defined",
8489 HandleVector(&name, 1));
8490 return MakePair(isolate->Throw(*reference_error), NULL);
8491 } else {
8492 return MakePair(Unhole(isolate->heap(), value, attributes), *receiver);
8493 }
8472 } 8494 }
8473 8495
8474 // If the holder is found, we read the property from it. 8496 // If the holder is found, we read the property from it.
8475 if (!holder.is_null() && holder->IsJSObject()) { 8497 if (!holder.is_null() && holder->IsJSObject()) {
8476 ASSERT(Handle<JSObject>::cast(holder)->HasProperty(*name)); 8498 ASSERT(Handle<JSObject>::cast(holder)->HasProperty(*name));
8477 JSObject* object = JSObject::cast(*holder); 8499 JSObject* object = JSObject::cast(*holder);
8478 Object* receiver; 8500 Object* receiver;
8479 if (object->IsGlobalObject()) { 8501 if (object->IsGlobalObject()) {
8480 receiver = GlobalObject::cast(object)->global_receiver(); 8502 receiver = GlobalObject::cast(object)->global_receiver();
8481 } else if (context->is_exception_holder(*holder)) { 8503 } else if (context->is_exception_holder(*holder)) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
8527 CONVERT_ARG_CHECKED(Context, context, 1); 8549 CONVERT_ARG_CHECKED(Context, context, 1);
8528 CONVERT_ARG_CHECKED(String, name, 2); 8550 CONVERT_ARG_CHECKED(String, name, 2);
8529 CONVERT_SMI_ARG_CHECKED(strict_unchecked, 3); 8551 CONVERT_SMI_ARG_CHECKED(strict_unchecked, 3);
8530 RUNTIME_ASSERT(strict_unchecked == kStrictMode || 8552 RUNTIME_ASSERT(strict_unchecked == kStrictMode ||
8531 strict_unchecked == kNonStrictMode); 8553 strict_unchecked == kNonStrictMode);
8532 StrictModeFlag strict_mode = static_cast<StrictModeFlag>(strict_unchecked); 8554 StrictModeFlag strict_mode = static_cast<StrictModeFlag>(strict_unchecked);
8533 8555
8534 int index; 8556 int index;
8535 PropertyAttributes attributes; 8557 PropertyAttributes attributes;
8536 ContextLookupFlags flags = FOLLOW_CHAINS; 8558 ContextLookupFlags flags = FOLLOW_CHAINS;
8537 Handle<Object> holder = context->Lookup(name, flags, &index, &attributes); 8559 BindingFlags binding_flags;
8560 Handle<Object> holder = context->Lookup(name,
8561 flags,
8562 &index,
8563 &attributes,
8564 &binding_flags);
8538 8565
8539 if (index >= 0) { 8566 if (index >= 0) {
8540 if (holder->IsContext()) { 8567 if (holder->IsContext()) {
8568 Handle<Context> context = Handle<Context>::cast(holder);
8569 if (binding_flags == MUTABLE_CHECK_INITIALIZED &&
8570 context->get(index)->IsTheHole()) {
8571 Handle<Object> error =
8572 isolate->factory()->NewReferenceError("not_defined",
8573 HandleVector(&name, 1));
8574 return isolate->Throw(*error);
8575 }
8541 // Ignore if read_only variable. 8576 // Ignore if read_only variable.
8542 if ((attributes & READ_ONLY) == 0) { 8577 if ((attributes & READ_ONLY) == 0) {
8543 // Context is a fixed array and set cannot fail. 8578 // Context is a fixed array and set cannot fail.
8544 Context::cast(*holder)->set(index, *value); 8579 context->set(index, *value);
8545 } else if (strict_mode == kStrictMode) { 8580 } else if (strict_mode == kStrictMode) {
8546 // Setting read only property in strict mode. 8581 // Setting read only property in strict mode.
8547 Handle<Object> error = 8582 Handle<Object> error =
8548 isolate->factory()->NewTypeError("strict_cannot_assign", 8583 isolate->factory()->NewTypeError("strict_cannot_assign",
8549 HandleVector(&name, 1)); 8584 HandleVector(&name, 1));
8550 return isolate->Throw(*error); 8585 return isolate->Throw(*error);
8551 } 8586 }
8552 } else { 8587 } else {
8553 ASSERT((attributes & READ_ONLY) == 0); 8588 ASSERT((attributes & READ_ONLY) == 0);
8554 Handle<Object> result = 8589 Handle<Object> result =
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
8985 // the stack frames to compute the context. 9020 // the stack frames to compute the context.
8986 StackFrameLocator locator; 9021 StackFrameLocator locator;
8987 JavaScriptFrame* frame = locator.FindJavaScriptFrame(0); 9022 JavaScriptFrame* frame = locator.FindJavaScriptFrame(0);
8988 ASSERT(Context::cast(frame->context()) == *context); 9023 ASSERT(Context::cast(frame->context()) == *context);
8989 #endif 9024 #endif
8990 9025
8991 // Find where the 'eval' symbol is bound. It is unaliased only if 9026 // Find where the 'eval' symbol is bound. It is unaliased only if
8992 // it is bound in the global context. 9027 // it is bound in the global context.
8993 int index = -1; 9028 int index = -1;
8994 PropertyAttributes attributes = ABSENT; 9029 PropertyAttributes attributes = ABSENT;
9030 BindingFlags binding_flags;
8995 while (true) { 9031 while (true) {
8996 receiver = context->Lookup(isolate->factory()->eval_symbol(), 9032 receiver = context->Lookup(isolate->factory()->eval_symbol(),
8997 FOLLOW_PROTOTYPE_CHAIN, 9033 FOLLOW_PROTOTYPE_CHAIN,
8998 &index, &attributes); 9034 &index,
9035 &attributes,
9036 &binding_flags);
8999 // Stop search when eval is found or when the global context is 9037 // Stop search when eval is found or when the global context is
9000 // reached. 9038 // reached.
9001 if (attributes != ABSENT || context->IsGlobalContext()) break; 9039 if (attributes != ABSENT || context->IsGlobalContext()) break;
9002 context = Handle<Context>(context->previous(), isolate); 9040 context = Handle<Context>(context->previous(), isolate);
9003 } 9041 }
9004 9042
9005 // If eval could not be resolved, it has been deleted and we need to 9043 // If eval could not be resolved, it has been deleted and we need to
9006 // throw a reference error. 9044 // throw a reference error.
9007 if (attributes == ABSENT) { 9045 if (attributes == ABSENT) {
9008 Handle<Object> name = isolate->factory()->eval_symbol(); 9046 Handle<Object> name = isolate->factory()->eval_symbol();
(...skipping 3901 matching lines...) Expand 10 before | Expand all | Expand 10 after
12910 } else { 12948 } else {
12911 // Handle last resort GC and make sure to allow future allocations 12949 // Handle last resort GC and make sure to allow future allocations
12912 // to grow the heap without causing GCs (if possible). 12950 // to grow the heap without causing GCs (if possible).
12913 isolate->counters()->gc_last_resort_from_js()->Increment(); 12951 isolate->counters()->gc_last_resort_from_js()->Increment();
12914 isolate->heap()->CollectAllGarbage(false); 12952 isolate->heap()->CollectAllGarbage(false);
12915 } 12953 }
12916 } 12954 }
12917 12955
12918 12956
12919 } } // namespace v8::internal 12957 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | src/token.h » ('j') | test/mjsunit/harmony/block-let-crankshaft.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698