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...) 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.PrepareForDataProperty(value); | |
1147 value = it.WriteDataValue(value); | |
arv (Not doing code reviews)
2015/02/27 15:44:32
Turns out that I could not use SetDataProperty sin
| |
1148 | |
1149 if (is_observed && !old_value->SameValue(*value)) { | |
1150 MaybeHandle<Object> result = | |
1151 JSObject::EnqueueChangeRecord(function, "update", name, old_value); | |
1152 if (result.is_null()) return MaybeHandle<Object>(); | |
1153 } | |
1154 | |
1155 return value; | |
1156 } | |
1157 | |
1158 | |
1134 void Accessors::FunctionNameSetter( | 1159 void Accessors::FunctionNameSetter( |
1135 v8::Local<v8::Name> name, | 1160 v8::Local<v8::Name> name, |
1136 v8::Local<v8::Value> val, | 1161 v8::Local<v8::Value> val, |
1137 const v8::PropertyCallbackInfo<void>& info) { | 1162 const v8::PropertyCallbackInfo<void>& info) { |
1138 // Function name is non writable, non configurable. | 1163 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); |
1139 UNREACHABLE(); | 1164 HandleScope scope(isolate); |
1165 Handle<Object> value = Utils::OpenHandle(*val); | |
1166 | |
1167 if (SetPropertyOnInstanceIfInherited(isolate, info, name, value)) return; | |
1168 | |
1169 Handle<JSFunction> object = | |
1170 Handle<JSFunction>::cast(Utils::OpenHandle(*info.Holder())); | |
1171 if (SetFunctionName(isolate, object, value).is_null()) { | |
1172 isolate->OptionalRescheduleException(false); | |
1173 } | |
1140 } | 1174 } |
1141 | 1175 |
1142 | 1176 |
1143 Handle<AccessorInfo> Accessors::FunctionNameInfo( | 1177 Handle<AccessorInfo> Accessors::FunctionNameInfo( |
1144 Isolate* isolate, PropertyAttributes attributes) { | 1178 Isolate* isolate, PropertyAttributes attributes) { |
1145 return MakeAccessor(isolate, | 1179 return MakeAccessor(isolate, |
1146 isolate->factory()->name_string(), | 1180 isolate->factory()->name_string(), |
1147 &FunctionNameGetter, | 1181 &FunctionNameGetter, |
1148 &FunctionNameSetter, | 1182 &FunctionNameSetter, |
1149 attributes); | 1183 attributes); |
(...skipping 347 matching lines...) Loading... | |
1497 info->set_data(Smi::FromInt(index)); | 1531 info->set_data(Smi::FromInt(index)); |
1498 Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport); | 1532 Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport); |
1499 Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport); | 1533 Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport); |
1500 info->set_getter(*getter); | 1534 info->set_getter(*getter); |
1501 if (!(attributes & ReadOnly)) info->set_setter(*setter); | 1535 if (!(attributes & ReadOnly)) info->set_setter(*setter); |
1502 return info; | 1536 return info; |
1503 } | 1537 } |
1504 | 1538 |
1505 | 1539 |
1506 } } // namespace v8::internal | 1540 } } // namespace v8::internal |
OLD | NEW |