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

Side by Side Diff: src/runtime/runtime-classes.cc

Issue 2423053002: Install the 'name' property in classes at runtime (Closed)
Patch Set: Rebase Created 4 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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <limits> 8 #include <limits>
9 9
10 #include "src/accessors.h"
10 #include "src/arguments.h" 11 #include "src/arguments.h"
11 #include "src/debug/debug.h" 12 #include "src/debug/debug.h"
12 #include "src/frames-inl.h" 13 #include "src/frames-inl.h"
13 #include "src/isolate-inl.h" 14 #include "src/isolate-inl.h"
14 #include "src/messages.h" 15 #include "src/messages.h"
15 #include "src/runtime/runtime.h" 16 #include "src/runtime/runtime.h"
16 17
17 namespace v8 { 18 namespace v8 {
18 namespace internal { 19 namespace internal {
19 20
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 1); 165 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 1);
165 CONVERT_SMI_ARG_CHECKED(start_position, 2); 166 CONVERT_SMI_ARG_CHECKED(start_position, 2);
166 CONVERT_SMI_ARG_CHECKED(end_position, 3); 167 CONVERT_SMI_ARG_CHECKED(end_position, 3);
167 168
168 RETURN_RESULT_OR_FAILURE( 169 RETURN_RESULT_OR_FAILURE(
169 isolate, DefineClass(isolate, super_class, constructor, start_position, 170 isolate, DefineClass(isolate, super_class, constructor, start_position,
170 end_position)); 171 end_position));
171 } 172 }
172 173
173 namespace { 174 namespace {
175 void InstallClassNameAccessor(Isolate* isolate, Handle<JSObject> object) {
176 PropertyAttributes attrs =
177 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY);
178 // Cannot fail since this should only be called when creating an object
179 // literal.
180 CHECK(!JSObject::SetAccessor(
181 object, Accessors::FunctionNameInfo(object->GetIsolate(), attrs))
182 .is_null());
183 }
184 } // anonymous namespace
185
186 RUNTIME_FUNCTION(Runtime_InstallClassNameAccessor) {
187 HandleScope scope(isolate);
188 DCHECK(args.length() == 2);
189 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0);
190 InstallClassNameAccessor(isolate, object);
191 return *object;
192 }
193
194 RUNTIME_FUNCTION(Runtime_InstallClassNameAccessorWithCheck) {
195 HandleScope scope(isolate);
196 DCHECK(args.length() == 2);
197 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0);
198
199 // If a property named "name" is already defined, exit.
200 Handle<Name> key = isolate->factory()->name_string();
201 if (JSObject::HasRealNamedProperty(object, key).FromMaybe(false)) {
202 return *object;
203 }
204
205 // Define the "name" accessor.
206 InstallClassNameAccessor(isolate, object);
207 return *object;
208 }
209
210 namespace {
174 211
175 enum class SuperMode { kLoad, kStore }; 212 enum class SuperMode { kLoad, kStore };
176 213
177 MaybeHandle<JSReceiver> GetSuperHolder( 214 MaybeHandle<JSReceiver> GetSuperHolder(
178 Isolate* isolate, Handle<Object> receiver, Handle<JSObject> home_object, 215 Isolate* isolate, Handle<Object> receiver, Handle<JSObject> home_object,
179 SuperMode mode, MaybeHandle<Name> maybe_name, uint32_t index) { 216 SuperMode mode, MaybeHandle<Name> maybe_name, uint32_t index) {
180 if (home_object->IsAccessCheckNeeded() && 217 if (home_object->IsAccessCheckNeeded() &&
181 !isolate->MayAccess(handle(isolate->context()), home_object)) { 218 !isolate->MayAccess(handle(isolate->context()), home_object)) {
182 isolate->ReportFailedAccessCheck(home_object); 219 isolate->ReportFailedAccessCheck(home_object);
183 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, JSReceiver); 220 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, JSReceiver);
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 420
384 RUNTIME_FUNCTION(Runtime_GetSuperConstructor) { 421 RUNTIME_FUNCTION(Runtime_GetSuperConstructor) {
385 SealHandleScope shs(isolate); 422 SealHandleScope shs(isolate);
386 DCHECK_EQ(1, args.length()); 423 DCHECK_EQ(1, args.length());
387 CONVERT_ARG_CHECKED(JSFunction, active_function, 0); 424 CONVERT_ARG_CHECKED(JSFunction, active_function, 0);
388 return active_function->map()->prototype(); 425 return active_function->map()->prototype();
389 } 426 }
390 427
391 } // namespace internal 428 } // namespace internal
392 } // namespace v8 429 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698