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

Side by Side Diff: src/runtime.cc

Issue 19384004: Proxies: Make 'with' work, plus minor other fixes (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 5 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 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 8732 matching lines...) Expand 10 before | Expand all | Expand 10 after
8743 8743
8744 isolate->set_context(result); 8744 isolate->set_context(result);
8745 8745
8746 return result; // non-failure 8746 return result; // non-failure
8747 } 8747 }
8748 8748
8749 8749
8750 RUNTIME_FUNCTION(MaybeObject*, Runtime_PushWithContext) { 8750 RUNTIME_FUNCTION(MaybeObject*, Runtime_PushWithContext) {
8751 SealHandleScope shs(isolate); 8751 SealHandleScope shs(isolate);
8752 ASSERT(args.length() == 2); 8752 ASSERT(args.length() == 2);
8753 JSObject* extension_object; 8753 JSReceiver* extension_object;
8754 if (args[0]->IsJSObject()) { 8754 if (args[0]->IsJSReceiver()) {
8755 extension_object = JSObject::cast(args[0]); 8755 extension_object = JSReceiver::cast(args[0]);
8756 } else { 8756 } else {
8757 // Convert the object to a proper JavaScript object. 8757 // Convert the object to a proper JavaScript object.
8758 MaybeObject* maybe_js_object = args[0]->ToObject(); 8758 MaybeObject* maybe_js_object = args[0]->ToObject();
8759 if (!maybe_js_object->To(&extension_object)) { 8759 if (!maybe_js_object->To(&extension_object)) {
8760 if (Failure::cast(maybe_js_object)->IsInternalError()) { 8760 if (Failure::cast(maybe_js_object)->IsInternalError()) {
8761 HandleScope scope(isolate); 8761 HandleScope scope(isolate);
8762 Handle<Object> handle = args.at<Object>(0); 8762 Handle<Object> handle = args.at<Object>(0);
8763 Handle<Object> result = 8763 Handle<Object> result =
8764 isolate->factory()->NewTypeError("with_expression", 8764 isolate->factory()->NewTypeError("with_expression",
8765 HandleVector(&handle, 1)); 8765 HandleVector(&handle, 1));
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
9046 9046
9047 int index; 9047 int index;
9048 PropertyAttributes attributes; 9048 PropertyAttributes attributes;
9049 ContextLookupFlags flags = FOLLOW_CHAINS; 9049 ContextLookupFlags flags = FOLLOW_CHAINS;
9050 BindingFlags binding_flags; 9050 BindingFlags binding_flags;
9051 Handle<Object> holder = context->Lookup(name, 9051 Handle<Object> holder = context->Lookup(name,
9052 flags, 9052 flags,
9053 &index, 9053 &index,
9054 &attributes, 9054 &attributes,
9055 &binding_flags); 9055 &binding_flags);
9056 if (isolate->has_pending_exception()) {
9057 return MakePair(Failure::Exception(), NULL);
9058 }
9056 9059
9057 // If the index is non-negative, the slot has been found in a context. 9060 // If the index is non-negative, the slot has been found in a context.
9058 if (index >= 0) { 9061 if (index >= 0) {
9059 ASSERT(holder->IsContext()); 9062 ASSERT(holder->IsContext());
9060 // If the "property" we were looking for is a local variable, the 9063 // If the "property" we were looking for is a local variable, the
9061 // receiver is the global object; see ECMA-262, 3rd., 10.1.6 and 10.2.3. 9064 // receiver is the global object; see ECMA-262, 3rd., 10.1.6 and 10.2.3.
9062 // 9065 //
9063 // Use the hole as the receiver to signal that the receiver is implicit 9066 // Use the hole as the receiver to signal that the receiver is implicit
9064 // and that the global receiver should be used (as distinguished from an 9067 // and that the global receiver should be used (as distinguished from an
9065 // explicit receiver that happens to be a global object). 9068 // explicit receiver that happens to be a global object).
(...skipping 20 matching lines...) Expand all
9086 case MISSING_BINDING: 9089 case MISSING_BINDING:
9087 UNREACHABLE(); 9090 UNREACHABLE();
9088 return MakePair(NULL, NULL); 9091 return MakePair(NULL, NULL);
9089 } 9092 }
9090 } 9093 }
9091 9094
9092 // Otherwise, if the slot was found the holder is a context extension 9095 // Otherwise, if the slot was found the holder is a context extension
9093 // object, subject of a with, or a global object. We read the named 9096 // object, subject of a with, or a global object. We read the named
9094 // property from it. 9097 // property from it.
9095 if (!holder.is_null()) { 9098 if (!holder.is_null()) {
9096 Handle<JSObject> object = Handle<JSObject>::cast(holder); 9099 Handle<JSReceiver> object = Handle<JSReceiver>::cast(holder);
9097 ASSERT(object->HasProperty(*name)); 9100 ASSERT(object->IsJSProxy() || object->HasProperty(*name));
9098 // GetProperty below can cause GC. 9101 // GetProperty below can cause GC.
9099 Handle<Object> receiver_handle( 9102 Handle<Object> receiver_handle(
9100 object->IsGlobalObject() 9103 object->IsGlobalObject()
9101 ? GlobalObject::cast(*object)->global_receiver() 9104 ? GlobalObject::cast(*object)->global_receiver()
9102 : ComputeReceiverForNonGlobal(isolate, *object), 9105 : object->IsJSProxy() ? static_cast<Object*>(*object)
9106 : ComputeReceiverForNonGlobal(isolate, JSObject::cast(*object)),
9103 isolate); 9107 isolate);
9104 9108
9105 // No need to unhole the value here. This is taken care of by the 9109 // No need to unhole the value here. This is taken care of by the
9106 // GetProperty function. 9110 // GetProperty function.
9107 MaybeObject* value = object->GetProperty(*name); 9111 MaybeObject* value = object->GetProperty(*name);
9108 return MakePair(value, *receiver_handle); 9112 return MakePair(value, *receiver_handle);
9109 } 9113 }
9110 9114
9111 if (throw_error) { 9115 if (throw_error) {
9112 // The property doesn't exist - throw exception. 9116 // The property doesn't exist - throw exception.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
9145 9149
9146 int index; 9150 int index;
9147 PropertyAttributes attributes; 9151 PropertyAttributes attributes;
9148 ContextLookupFlags flags = FOLLOW_CHAINS; 9152 ContextLookupFlags flags = FOLLOW_CHAINS;
9149 BindingFlags binding_flags; 9153 BindingFlags binding_flags;
9150 Handle<Object> holder = context->Lookup(name, 9154 Handle<Object> holder = context->Lookup(name,
9151 flags, 9155 flags,
9152 &index, 9156 &index,
9153 &attributes, 9157 &attributes,
9154 &binding_flags); 9158 &binding_flags);
9159 if (isolate->has_pending_exception()) return Failure::Exception();
9155 9160
9156 if (index >= 0) { 9161 if (index >= 0) {
9157 // The property was found in a context slot. 9162 // The property was found in a context slot.
9158 Handle<Context> context = Handle<Context>::cast(holder); 9163 Handle<Context> context = Handle<Context>::cast(holder);
9159 if (binding_flags == MUTABLE_CHECK_INITIALIZED && 9164 if (binding_flags == MUTABLE_CHECK_INITIALIZED &&
9160 context->get(index)->IsTheHole()) { 9165 context->get(index)->IsTheHole()) {
9161 Handle<Object> error = 9166 Handle<Object> error =
9162 isolate->factory()->NewReferenceError("not_defined", 9167 isolate->factory()->NewReferenceError("not_defined",
9163 HandleVector(&name, 1)); 9168 HandleVector(&name, 1));
9164 return isolate->Throw(*error); 9169 return isolate->Throw(*error);
9165 } 9170 }
9166 // Ignore if read_only variable. 9171 // Ignore if read_only variable.
9167 if ((attributes & READ_ONLY) == 0) { 9172 if ((attributes & READ_ONLY) == 0) {
9168 // Context is a fixed array and set cannot fail. 9173 // Context is a fixed array and set cannot fail.
9169 context->set(index, *value); 9174 context->set(index, *value);
9170 } else if (strict_mode == kStrictMode) { 9175 } else if (strict_mode == kStrictMode) {
9171 // Setting read only property in strict mode. 9176 // Setting read only property in strict mode.
9172 Handle<Object> error = 9177 Handle<Object> error =
9173 isolate->factory()->NewTypeError("strict_cannot_assign", 9178 isolate->factory()->NewTypeError("strict_cannot_assign",
9174 HandleVector(&name, 1)); 9179 HandleVector(&name, 1));
9175 return isolate->Throw(*error); 9180 return isolate->Throw(*error);
9176 } 9181 }
9177 return *value; 9182 return *value;
9178 } 9183 }
9179 9184
9180 // Slow case: The property is not in a context slot. It is either in a 9185 // Slow case: The property is not in a context slot. It is either in a
9181 // context extension object, a property of the subject of a with, or a 9186 // context extension object, a property of the subject of a with, or a
9182 // property of the global object. 9187 // property of the global object.
9183 Handle<JSObject> object; 9188 Handle<JSReceiver> object;
9184 9189
9185 if (!holder.is_null()) { 9190 if (!holder.is_null()) {
9186 // The property exists on the holder. 9191 // The property exists on the holder.
9187 object = Handle<JSObject>::cast(holder); 9192 object = Handle<JSReceiver>::cast(holder);
9188 } else { 9193 } else {
9189 // The property was not found. 9194 // The property was not found.
9190 ASSERT(attributes == ABSENT); 9195 ASSERT(attributes == ABSENT);
9191 9196
9192 if (strict_mode == kStrictMode) { 9197 if (strict_mode == kStrictMode) {
9193 // Throw in strict mode (assignment to undefined variable). 9198 // Throw in strict mode (assignment to undefined variable).
9194 Handle<Object> error = 9199 Handle<Object> error =
9195 isolate->factory()->NewReferenceError( 9200 isolate->factory()->NewReferenceError(
9196 "not_defined", HandleVector(&name, 1)); 9201 "not_defined", HandleVector(&name, 1));
9197 return isolate->Throw(*error); 9202 return isolate->Throw(*error);
9198 } 9203 }
9199 // In non-strict mode, the property is added to the global object. 9204 // In non-strict mode, the property is added to the global object.
9200 attributes = NONE; 9205 attributes = NONE;
9201 object = Handle<JSObject>(isolate->context()->global_object()); 9206 object = Handle<JSReceiver>(isolate->context()->global_object());
9202 } 9207 }
9203 9208
9204 // Set the property if it's not read only or doesn't yet exist. 9209 // Set the property if it's not read only or doesn't yet exist.
9205 if ((attributes & READ_ONLY) == 0 || 9210 if ((attributes & READ_ONLY) == 0 ||
9206 (object->GetLocalPropertyAttribute(*name) == ABSENT)) { 9211 (object->GetLocalPropertyAttribute(*name) == ABSENT)) {
9207 RETURN_IF_EMPTY_HANDLE( 9212 RETURN_IF_EMPTY_HANDLE(
9208 isolate, 9213 isolate,
9209 JSReceiver::SetProperty(object, name, value, NONE, strict_mode)); 9214 JSReceiver::SetProperty(object, name, value, NONE, strict_mode));
9210 } else if (strict_mode == kStrictMode && (attributes & READ_ONLY) != 0) { 9215 } else if (strict_mode == kStrictMode && (attributes & READ_ONLY) != 0) {
9211 // Setting read only property in strict mode. 9216 // Setting read only property in strict mode.
(...skipping 4866 matching lines...) Expand 10 before | Expand all | Expand 10 after
14078 // Handle last resort GC and make sure to allow future allocations 14083 // Handle last resort GC and make sure to allow future allocations
14079 // to grow the heap without causing GCs (if possible). 14084 // to grow the heap without causing GCs (if possible).
14080 isolate->counters()->gc_last_resort_from_js()->Increment(); 14085 isolate->counters()->gc_last_resort_from_js()->Increment();
14081 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 14086 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
14082 "Runtime::PerformGC"); 14087 "Runtime::PerformGC");
14083 } 14088 }
14084 } 14089 }
14085 14090
14086 14091
14087 } } // namespace v8::internal 14092 } } // namespace v8::internal
OLDNEW
« src/proxy.js ('K') | « src/proxy.js ('k') | test/mjsunit/harmony/proxies-for.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698