OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/api.h" | 8 #include "src/api.h" |
9 #include "src/contexts.h" | 9 #include "src/contexts.h" |
10 #include "src/deoptimizer.h" | 10 #include "src/deoptimizer.h" |
(...skipping 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 const v8::PropertyCallbackInfo<v8::Value>& info) { | 1124 const v8::PropertyCallbackInfo<v8::Value>& info) { |
1125 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); | 1125 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); |
1126 HandleScope scope(isolate); | 1126 HandleScope scope(isolate); |
1127 Handle<JSFunction> function = | 1127 Handle<JSFunction> function = |
1128 Handle<JSFunction>::cast(Utils::OpenHandle(*info.Holder())); | 1128 Handle<JSFunction>::cast(Utils::OpenHandle(*info.Holder())); |
1129 Handle<Object> result(function->shared()->name(), isolate); | 1129 Handle<Object> result(function->shared()->name(), isolate); |
1130 info.GetReturnValue().Set(Utils::ToLocal(result)); | 1130 info.GetReturnValue().Set(Utils::ToLocal(result)); |
1131 } | 1131 } |
1132 | 1132 |
1133 | 1133 |
| 1134 MUST_USE_RESULT static MaybeHandle<Object> SetFunctionName( |
| 1135 Isolate* isolate, Handle<JSFunction> function, Handle<Object> value) { |
| 1136 Handle<Object> old_value; |
| 1137 bool is_observed = function->map()->is_observed(); |
| 1138 if (is_observed) { |
| 1139 old_value = handle(function->shared()->name(), isolate); |
| 1140 } |
| 1141 |
| 1142 Handle<Name> name = isolate->factory()->name_string(); |
| 1143 LookupIterator it(function, name); |
| 1144 CHECK_EQ(LookupIterator::ACCESSOR, it.state()); |
| 1145 DCHECK(it.HolderIsReceiverOrHiddenPrototype()); |
| 1146 it.ReconfigureDataProperty(value, it.property_details().attributes()); |
| 1147 value = it.WriteDataValue(value); |
| 1148 |
| 1149 if (is_observed && !old_value->SameValue(*value)) { |
| 1150 return JSObject::EnqueueChangeRecord(function, "update", name, old_value); |
| 1151 } |
| 1152 |
| 1153 return value; |
| 1154 } |
| 1155 |
| 1156 |
1134 void Accessors::FunctionNameSetter( | 1157 void Accessors::FunctionNameSetter( |
1135 v8::Local<v8::Name> name, | 1158 v8::Local<v8::Name> name, |
1136 v8::Local<v8::Value> val, | 1159 v8::Local<v8::Value> val, |
1137 const v8::PropertyCallbackInfo<void>& info) { | 1160 const v8::PropertyCallbackInfo<void>& info) { |
1138 // Function name is non writable, non configurable. | 1161 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); |
1139 UNREACHABLE(); | 1162 HandleScope scope(isolate); |
| 1163 Handle<Object> value = Utils::OpenHandle(*val); |
| 1164 |
| 1165 if (SetPropertyOnInstanceIfInherited(isolate, info, name, value)) return; |
| 1166 |
| 1167 Handle<JSFunction> object = |
| 1168 Handle<JSFunction>::cast(Utils::OpenHandle(*info.Holder())); |
| 1169 if (SetFunctionName(isolate, object, value).is_null()) { |
| 1170 isolate->OptionalRescheduleException(false); |
| 1171 } |
1140 } | 1172 } |
1141 | 1173 |
1142 | 1174 |
1143 Handle<AccessorInfo> Accessors::FunctionNameInfo( | 1175 Handle<AccessorInfo> Accessors::FunctionNameInfo( |
1144 Isolate* isolate, PropertyAttributes attributes) { | 1176 Isolate* isolate, PropertyAttributes attributes) { |
1145 return MakeAccessor(isolate, | 1177 return MakeAccessor(isolate, |
1146 isolate->factory()->name_string(), | 1178 isolate->factory()->name_string(), |
1147 &FunctionNameGetter, | 1179 &FunctionNameGetter, |
1148 &FunctionNameSetter, | 1180 &FunctionNameSetter, |
1149 attributes); | 1181 attributes); |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1497 info->set_data(Smi::FromInt(index)); | 1529 info->set_data(Smi::FromInt(index)); |
1498 Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport); | 1530 Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport); |
1499 Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport); | 1531 Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport); |
1500 info->set_getter(*getter); | 1532 info->set_getter(*getter); |
1501 if (!(attributes & ReadOnly)) info->set_setter(*setter); | 1533 if (!(attributes & ReadOnly)) info->set_setter(*setter); |
1502 return info; | 1534 return info; |
1503 } | 1535 } |
1504 | 1536 |
1505 | 1537 |
1506 } } // namespace v8::internal | 1538 } } // namespace v8::internal |
OLD | NEW |