| OLD | NEW |
| 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 Loading... |
| 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() == 1); |
| 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() == 1); |
| 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 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 } | 463 } |
| 427 | 464 |
| 428 // Call the constructor. | 465 // Call the constructor. |
| 429 RETURN_RESULT_OR_FAILURE( | 466 RETURN_RESULT_OR_FAILURE( |
| 430 isolate, Execution::New(isolate, constructor, new_target, result_length, | 467 isolate, Execution::New(isolate, constructor, new_target, result_length, |
| 431 construct_args.start())); | 468 construct_args.start())); |
| 432 } | 469 } |
| 433 | 470 |
| 434 } // namespace internal | 471 } // namespace internal |
| 435 } // namespace v8 | 472 } // namespace v8 |
| OLD | NEW |