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

Side by Side Diff: src/objects.cc

Issue 1481773003: [Proxies] Support constructable proxy as new.target (reland) (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Diff with previous version Created 5 years 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
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/objects.h" 5 #include "src/objects.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <iomanip> 8 #include <iomanip>
9 #include <sstream> 9 #include <sstream>
10 10
(...skipping 4676 matching lines...) Expand 10 before | Expand all | Expand 10 after
4687 if (isolate->has_pending_exception()) return Nothing<bool>(); 4687 if (isolate->has_pending_exception()) return Nothing<bool>();
4688 if (owned && !target_desc.configurable()) { 4688 if (owned && !target_desc.configurable()) {
4689 isolate->Throw(*factory->NewTypeError( 4689 isolate->Throw(*factory->NewTypeError(
4690 MessageTemplate::kProxyDeletePropertyViolatesInvariant, name)); 4690 MessageTemplate::kProxyDeletePropertyViolatesInvariant, name));
4691 return Nothing<bool>(); 4691 return Nothing<bool>();
4692 } 4692 }
4693 return Just(true); 4693 return Just(true);
4694 } 4694 }
4695 4695
4696 4696
4697 // static
4698 MaybeHandle<Context> JSProxy::GetFunctionRealm(Handle<JSProxy> proxy) {
4699 DCHECK(proxy->map()->is_constructor());
4700 if (JSProxy::IsRevoked(proxy)) {
4701 THROW_NEW_ERROR(proxy->GetIsolate(),
4702 NewTypeError(MessageTemplate::kProxyRevoked), Context);
4703 }
4704
4705 // TODO(verwaest): Get rid of JSFunctionProxies.
4706 Object* target = proxy->IsJSFunctionProxy()
4707 ? JSFunctionProxy::cast(*proxy)->construct_trap()
4708 : proxy->target();
4709 return JSReceiver::GetFunctionRealm(handle(JSReceiver::cast(target)));
4710 }
4711
4712
4713 // static
4714 MaybeHandle<Context> JSFunction::GetFunctionRealm(Handle<JSFunction> function) {
4715 DCHECK(function->map()->is_constructor());
4716 return handle(function->context()->native_context());
4717 }
4718
4719
4720 // static
4721 MaybeHandle<Context> JSObject::GetFunctionRealm(Handle<JSObject> object) {
4722 DCHECK(object->map()->is_constructor());
4723 DCHECK(!object->IsJSFunction());
4724 return handle(object->GetCreationContext());
4725 }
4726
4727
4728 // static
4729 MaybeHandle<Context> JSReceiver::GetFunctionRealm(Handle<JSReceiver> receiver) {
4730 if (receiver->IsJSProxy()) {
4731 return JSProxy::GetFunctionRealm(Handle<JSProxy>::cast(receiver));
4732 }
4733
4734 if (receiver->IsJSFunction()) {
4735 return JSFunction::GetFunctionRealm(Handle<JSFunction>::cast(receiver));
4736 }
4737
4738 return JSObject::GetFunctionRealm(Handle<JSObject>::cast(receiver));
4739 }
4740
4741
4697 Maybe<PropertyAttributes> JSProxy::GetPropertyAttributes(LookupIterator* it) { 4742 Maybe<PropertyAttributes> JSProxy::GetPropertyAttributes(LookupIterator* it) {
4698 Isolate* isolate = it->isolate(); 4743 Isolate* isolate = it->isolate();
4699 HandleScope scope(isolate); 4744 HandleScope scope(isolate);
4700 PropertyDescriptor desc; 4745 PropertyDescriptor desc;
4701 bool found = JSProxy::GetOwnPropertyDescriptor(it, &desc); 4746 bool found = JSProxy::GetOwnPropertyDescriptor(it, &desc);
4702 if (isolate->has_pending_exception()) return Nothing<PropertyAttributes>(); 4747 if (isolate->has_pending_exception()) return Nothing<PropertyAttributes>();
4703 if (!found) return Just(ABSENT); 4748 if (!found) return Just(ABSENT);
4704 return Just(desc.ToAttributes()); 4749 return Just(desc.ToAttributes());
4705 } 4750 }
4706 4751
(...skipping 7508 matching lines...) Expand 10 before | Expand all | Expand 10 after
12215 return handle(new_target->initial_map(), isolate); 12260 return handle(new_target->initial_map(), isolate);
12216 } 12261 }
12217 } 12262 }
12218 12263
12219 // First create a new map with the size and number of in-object properties 12264 // First create a new map with the size and number of in-object properties
12220 // suggested by the function. 12265 // suggested by the function.
12221 DCHECK(!new_target->shared()->is_generator()); 12266 DCHECK(!new_target->shared()->is_generator());
12222 DCHECK(!constructor->shared()->is_generator()); 12267 DCHECK(!constructor->shared()->is_generator());
12223 12268
12224 // Fetch or allocate prototype. 12269 // Fetch or allocate prototype.
12270 // TODO(verwaest): In case of non-instance prototype, use the
12271 // intrinsicDefaultProto instead.
12225 Handle<Object> prototype; 12272 Handle<Object> prototype;
12226 if (new_target->has_instance_prototype()) { 12273 if (new_target->has_instance_prototype()) {
12227 prototype = handle(new_target->instance_prototype(), isolate); 12274 prototype = handle(new_target->instance_prototype(), isolate);
12228 } else { 12275 } else {
12229 prototype = isolate->factory()->NewFunctionPrototype(new_target); 12276 prototype = isolate->factory()->NewFunctionPrototype(new_target);
12230 } 12277 }
12231 12278
12232 // Finally link initial map and constructor function if the original 12279 // Finally link initial map and constructor function if the original
12233 // constructor is actually a subclass constructor. 12280 // constructor is actually a subclass constructor.
12234 if (IsSubclassConstructor(new_target->shared()->kind())) { 12281 if (IsSubclassConstructor(new_target->shared()->kind())) {
(...skipping 6366 matching lines...) Expand 10 before | Expand all | Expand 10 after
18601 if (cell->value() != *new_value) { 18648 if (cell->value() != *new_value) {
18602 cell->set_value(*new_value); 18649 cell->set_value(*new_value);
18603 Isolate* isolate = cell->GetIsolate(); 18650 Isolate* isolate = cell->GetIsolate();
18604 cell->dependent_code()->DeoptimizeDependentCodeGroup( 18651 cell->dependent_code()->DeoptimizeDependentCodeGroup(
18605 isolate, DependentCode::kPropertyCellChangedGroup); 18652 isolate, DependentCode::kPropertyCellChangedGroup);
18606 } 18653 }
18607 } 18654 }
18608 18655
18609 } // namespace internal 18656 } // namespace internal
18610 } // namespace v8 18657 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/runtime/runtime-object.cc » ('j') | src/runtime/runtime-object.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698