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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/V8DOMConfiguration.cpp

Issue 2815453005: [Bindings] Use SetNativeDataProperty to install features on instances (Closed)
Patch Set: Add DCHECK Created 3 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } 88 }
89 89
90 void InstallAttributeInternal( 90 void InstallAttributeInternal(
91 v8::Isolate* isolate, 91 v8::Isolate* isolate,
92 v8::Local<v8::Object> instance, 92 v8::Local<v8::Object> instance,
93 v8::Local<v8::Object> prototype, 93 v8::Local<v8::Object> prototype,
94 const V8DOMConfiguration::AttributeConfiguration& attribute, 94 const V8DOMConfiguration::AttributeConfiguration& attribute,
95 const DOMWrapperWorld& world) { 95 const DOMWrapperWorld& world) {
96 if (!WorldConfigurationApplies(attribute, world)) 96 if (!WorldConfigurationApplies(attribute, world))
97 return; 97 return;
98
98 v8::Local<v8::Name> name = V8AtomicString(isolate, attribute.name); 99 v8::Local<v8::Name> name = V8AtomicString(isolate, attribute.name);
100 v8::AccessorNameGetterCallback getter = attribute.getter;
101 v8::AccessorNameSetterCallback setter = attribute.setter;
102 v8::Local<v8::Value> data =
103 v8::External::New(isolate, const_cast<WrapperTypeInfo*>(attribute.data));
99 104
100 // This method is only being used for installing interfaces which are 105 v8::Local<v8::Context> context = isolate->GetCurrentContext();
101 // enabled through origin trials. Assert here that it is being called with
102 // an attribute configuration for a constructor.
103 // TODO(iclelland): Relax this constraint and allow arbitrary data-type
104 // properties to be added here.
105 DCHECK_EQ(&V8ConstructorAttributeGetter, attribute.getter);
haraken 2017/04/13 08:06:09 Can we keep this assert? This assert is important
peria 2017/04/13 09:51:21 done
106
107 V8PerContextData* per_context_data =
108 V8PerContextData::From(isolate->GetCurrentContext());
109 v8::Local<v8::Function> data =
110 per_context_data->ConstructorForType(attribute.data);
111
112 DCHECK(attribute.property_location_configuration); 106 DCHECK(attribute.property_location_configuration);
113 if (attribute.property_location_configuration & 107 if (attribute.property_location_configuration &
114 V8DOMConfiguration::kOnInstance) 108 V8DOMConfiguration::kOnInstance) {
115 instance 109 DCHECK(instance
bashi 2017/04/13 08:08:36 Why do we need DCHECK()? ToChecked() should crash
peria 2017/04/13 09:51:21 Hmm, I thought returning false can be independent
116 ->DefineOwnProperty( 110 ->SetAccessor(
117 isolate->GetCurrentContext(), name, data, 111 context, name, getter, setter, data, v8::DEFAULT,
118 static_cast<v8::PropertyAttribute>(attribute.attribute)) 112 static_cast<v8::PropertyAttribute>(attribute.attribute))
119 .ToChecked(); 113 .ToChecked());
114 }
120 if (attribute.property_location_configuration & 115 if (attribute.property_location_configuration &
121 V8DOMConfiguration::kOnPrototype) 116 V8DOMConfiguration::kOnPrototype) {
122 prototype 117 DCHECK(prototype
123 ->DefineOwnProperty( 118 ->SetAccessor(
124 isolate->GetCurrentContext(), name, data, 119 context, name, getter, setter, data, v8::DEFAULT,
125 static_cast<v8::PropertyAttribute>(attribute.attribute)) 120 static_cast<v8::PropertyAttribute>(attribute.attribute))
126 .ToChecked(); 121 .ToChecked());
122 }
127 if (attribute.property_location_configuration & 123 if (attribute.property_location_configuration &
128 V8DOMConfiguration::kOnInterface) 124 V8DOMConfiguration::kOnInterface)
129 NOTREACHED(); 125 NOTREACHED();
130 } 126 }
131 127
132 void InstallLazyDataAttributeInternal( 128 void InstallLazyDataAttributeInternal(
133 v8::Isolate* isolate, 129 v8::Isolate* isolate,
134 v8::Local<v8::ObjectTemplate> instance_template, 130 v8::Local<v8::ObjectTemplate> instance_template,
135 v8::Local<v8::ObjectTemplate> prototype_template, 131 v8::Local<v8::ObjectTemplate> prototype_template,
136 const V8DOMConfiguration::AttributeConfiguration& attribute, 132 const V8DOMConfiguration::AttributeConfiguration& attribute,
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 v8::Isolate* isolate, 698 v8::Isolate* isolate,
703 v8::Local<v8::ObjectTemplate> object_template, 699 v8::Local<v8::ObjectTemplate> object_template,
704 const char* class_string) { 700 const char* class_string) {
705 object_template->Set( 701 object_template->Set(
706 v8::Symbol::GetToStringTag(isolate), 702 v8::Symbol::GetToStringTag(isolate),
707 V8AtomicString(isolate, class_string), 703 V8AtomicString(isolate, class_string),
708 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); 704 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum));
709 } 705 }
710 706
711 } // namespace blink 707 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698