| 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 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1088 } | 1088 } |
| 1089 if (isolate->has_pending_exception()) { | 1089 if (isolate->has_pending_exception()) { |
| 1090 isolate->OptionalRescheduleException(false); | 1090 isolate->OptionalRescheduleException(false); |
| 1091 } | 1091 } |
| 1092 } | 1092 } |
| 1093 Handle<Object> result(Smi::FromInt(length), isolate); | 1093 Handle<Object> result(Smi::FromInt(length), isolate); |
| 1094 info.GetReturnValue().Set(Utils::ToLocal(result)); | 1094 info.GetReturnValue().Set(Utils::ToLocal(result)); |
| 1095 } | 1095 } |
| 1096 | 1096 |
| 1097 | 1097 |
| 1098 MUST_USE_RESULT static MaybeHandle<Object> ReplaceAccessorWithDataProperty( |
| 1099 Isolate* isolate, Handle<JSObject> object, Handle<Name> name, |
| 1100 Handle<Object> value, bool is_observed, Handle<Object> old_value) { |
| 1101 LookupIterator it(object, name); |
| 1102 CHECK_EQ(LookupIterator::ACCESSOR, it.state()); |
| 1103 DCHECK(it.HolderIsReceiverOrHiddenPrototype()); |
| 1104 it.ReconfigureDataProperty(value, it.property_details().attributes()); |
| 1105 value = it.WriteDataValue(value); |
| 1106 |
| 1107 if (is_observed && !old_value->SameValue(*value)) { |
| 1108 return JSObject::EnqueueChangeRecord(object, "update", name, old_value); |
| 1109 } |
| 1110 |
| 1111 return value; |
| 1112 } |
| 1113 |
| 1114 |
| 1115 MUST_USE_RESULT static MaybeHandle<Object> SetFunctionLength( |
| 1116 Isolate* isolate, Handle<JSFunction> function, Handle<Object> value) { |
| 1117 Handle<Object> old_value; |
| 1118 bool is_observed = function->map()->is_observed(); |
| 1119 if (is_observed) { |
| 1120 old_value = handle(Smi::FromInt(function->shared()->length()), isolate); |
| 1121 } |
| 1122 |
| 1123 return ReplaceAccessorWithDataProperty(isolate, function, |
| 1124 isolate->factory()->length_string(), |
| 1125 value, is_observed, old_value); |
| 1126 } |
| 1127 |
| 1128 |
| 1098 void Accessors::FunctionLengthSetter( | 1129 void Accessors::FunctionLengthSetter( |
| 1099 v8::Local<v8::Name> name, | 1130 v8::Local<v8::Name> name, |
| 1100 v8::Local<v8::Value> val, | 1131 v8::Local<v8::Value> val, |
| 1101 const v8::PropertyCallbackInfo<void>& info) { | 1132 const v8::PropertyCallbackInfo<void>& info) { |
| 1102 // Function length is non writable, non configurable. | 1133 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); |
| 1103 UNREACHABLE(); | 1134 HandleScope scope(isolate); |
| 1135 Handle<Object> value = Utils::OpenHandle(*val); |
| 1136 |
| 1137 if (SetPropertyOnInstanceIfInherited(isolate, info, name, value)) return; |
| 1138 |
| 1139 Handle<JSFunction> object = |
| 1140 Handle<JSFunction>::cast(Utils::OpenHandle(*info.Holder())); |
| 1141 if (SetFunctionLength(isolate, object, value).is_null()) { |
| 1142 isolate->OptionalRescheduleException(false); |
| 1143 } |
| 1104 } | 1144 } |
| 1105 | 1145 |
| 1106 | 1146 |
| 1107 Handle<AccessorInfo> Accessors::FunctionLengthInfo( | 1147 Handle<AccessorInfo> Accessors::FunctionLengthInfo( |
| 1108 Isolate* isolate, PropertyAttributes attributes) { | 1148 Isolate* isolate, PropertyAttributes attributes) { |
| 1109 return MakeAccessor(isolate, | 1149 return MakeAccessor(isolate, |
| 1110 isolate->factory()->length_string(), | 1150 isolate->factory()->length_string(), |
| 1111 &FunctionLengthGetter, | 1151 &FunctionLengthGetter, |
| 1112 &FunctionLengthSetter, | 1152 &FunctionLengthSetter, |
| 1113 attributes); | 1153 attributes); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1132 | 1172 |
| 1133 | 1173 |
| 1134 MUST_USE_RESULT static MaybeHandle<Object> SetFunctionName( | 1174 MUST_USE_RESULT static MaybeHandle<Object> SetFunctionName( |
| 1135 Isolate* isolate, Handle<JSFunction> function, Handle<Object> value) { | 1175 Isolate* isolate, Handle<JSFunction> function, Handle<Object> value) { |
| 1136 Handle<Object> old_value; | 1176 Handle<Object> old_value; |
| 1137 bool is_observed = function->map()->is_observed(); | 1177 bool is_observed = function->map()->is_observed(); |
| 1138 if (is_observed) { | 1178 if (is_observed) { |
| 1139 old_value = handle(function->shared()->name(), isolate); | 1179 old_value = handle(function->shared()->name(), isolate); |
| 1140 } | 1180 } |
| 1141 | 1181 |
| 1142 Handle<Name> name = isolate->factory()->name_string(); | 1182 return ReplaceAccessorWithDataProperty(isolate, function, |
| 1143 LookupIterator it(function, name); | 1183 isolate->factory()->name_string(), |
| 1144 CHECK_EQ(LookupIterator::ACCESSOR, it.state()); | 1184 value, is_observed, old_value); |
| 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 } | 1185 } |
| 1155 | 1186 |
| 1156 | 1187 |
| 1157 void Accessors::FunctionNameSetter( | 1188 void Accessors::FunctionNameSetter( |
| 1158 v8::Local<v8::Name> name, | 1189 v8::Local<v8::Name> name, |
| 1159 v8::Local<v8::Value> val, | 1190 v8::Local<v8::Value> val, |
| 1160 const v8::PropertyCallbackInfo<void>& info) { | 1191 const v8::PropertyCallbackInfo<void>& info) { |
| 1161 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); | 1192 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); |
| 1162 HandleScope scope(isolate); | 1193 HandleScope scope(isolate); |
| 1163 Handle<Object> value = Utils::OpenHandle(*val); | 1194 Handle<Object> value = Utils::OpenHandle(*val); |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1529 info->set_data(Smi::FromInt(index)); | 1560 info->set_data(Smi::FromInt(index)); |
| 1530 Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport); | 1561 Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport); |
| 1531 Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport); | 1562 Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport); |
| 1532 info->set_getter(*getter); | 1563 info->set_getter(*getter); |
| 1533 if (!(attributes & ReadOnly)) info->set_setter(*setter); | 1564 if (!(attributes & ReadOnly)) info->set_setter(*setter); |
| 1534 return info; | 1565 return info; |
| 1535 } | 1566 } |
| 1536 | 1567 |
| 1537 | 1568 |
| 1538 } } // namespace v8::internal | 1569 } } // namespace v8::internal |
| OLD | NEW |