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

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

Issue 2423053002: Install the 'name' property in classes at runtime (Closed)
Patch Set: Use an accessor instead of a data property Created 4 years, 1 month 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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 CONVERT_ARG_HANDLE_CHECKED(Object, super_class, 0); 182 CONVERT_ARG_HANDLE_CHECKED(Object, super_class, 0);
182 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 1); 183 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 1);
183 CONVERT_SMI_ARG_CHECKED(start_position, 2); 184 CONVERT_SMI_ARG_CHECKED(start_position, 2);
184 CONVERT_SMI_ARG_CHECKED(end_position, 3); 185 CONVERT_SMI_ARG_CHECKED(end_position, 3);
185 186
186 RETURN_RESULT_OR_FAILURE( 187 RETURN_RESULT_OR_FAILURE(
187 isolate, DefineClass(isolate, super_class, constructor, start_position, 188 isolate, DefineClass(isolate, super_class, constructor, start_position,
188 end_position)); 189 end_position));
189 } 190 }
190 191
192
193 RUNTIME_FUNCTION(Runtime_DefineClassNameProperty) {
194 HandleScope scope(isolate);
195 DCHECK(args.length() == 2);
196 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0);
197 CONVERT_ARG_HANDLE_CHECKED(String, name, 1);
198
199 // Abort if "name" is undefined.
200 if (name->length() == 0) return *object;
Toon Verwaest 2016/11/24 07:13:38 You can check this at compile-time, which means yo
201
202 // If a property named "name" is already defined, exit.
203 Handle<Name> key = isolate->factory()->name_string();
204 if (JSObject::HasRealNamedProperty(object, key).FromMaybe(false))
205 return *object;
206
207 // Define the "name" property.
208 PropertyAttributes attrs =
209 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY);
210 // Cannot fail since this should only be called when creating an object
211 // literal.
212 DCHECK(!JSObject::SetAccessor(
213 object, Accessors::FunctionNameInfo(object->GetIsolate(), attrs))
214 .is_null());
215 return *object;
216 }
217
191 namespace { 218 namespace {
192 219
193 enum class SuperMode { kLoad, kStore }; 220 enum class SuperMode { kLoad, kStore };
194 221
195 MaybeHandle<JSReceiver> GetSuperHolder( 222 MaybeHandle<JSReceiver> GetSuperHolder(
196 Isolate* isolate, Handle<Object> receiver, Handle<JSObject> home_object, 223 Isolate* isolate, Handle<Object> receiver, Handle<JSObject> home_object,
197 SuperMode mode, MaybeHandle<Name> maybe_name, uint32_t index) { 224 SuperMode mode, MaybeHandle<Name> maybe_name, uint32_t index) {
198 if (home_object->IsAccessCheckNeeded() && 225 if (home_object->IsAccessCheckNeeded() &&
199 !isolate->MayAccess(handle(isolate->context()), home_object)) { 226 !isolate->MayAccess(handle(isolate->context()), home_object)) {
200 isolate->ReportFailedAccessCheck(home_object); 227 isolate->ReportFailedAccessCheck(home_object);
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 428
402 RUNTIME_FUNCTION(Runtime_GetSuperConstructor) { 429 RUNTIME_FUNCTION(Runtime_GetSuperConstructor) {
403 SealHandleScope shs(isolate); 430 SealHandleScope shs(isolate);
404 DCHECK_EQ(1, args.length()); 431 DCHECK_EQ(1, args.length());
405 CONVERT_ARG_CHECKED(JSFunction, active_function, 0); 432 CONVERT_ARG_CHECKED(JSFunction, active_function, 0);
406 return active_function->map()->prototype(); 433 return active_function->map()->prototype();
407 } 434 }
408 435
409 } // namespace internal 436 } // namespace internal
410 } // namespace v8 437 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698