| 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 "v8.h" | 5 #include "v8.h" |
| 6 #include "accessors.h" | 6 #include "accessors.h" |
| 7 | 7 |
| 8 #include "compiler.h" | 8 #include "compiler.h" |
| 9 #include "contexts.h" | 9 #include "contexts.h" |
| 10 #include "deoptimizer.h" | 10 #include "deoptimizer.h" |
| (...skipping 1106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1117 &FunctionArgumentsSetter, | 1117 &FunctionArgumentsSetter, |
| 1118 attributes); | 1118 attributes); |
| 1119 } | 1119 } |
| 1120 | 1120 |
| 1121 | 1121 |
| 1122 // | 1122 // |
| 1123 // Accessors::FunctionCaller | 1123 // Accessors::FunctionCaller |
| 1124 // | 1124 // |
| 1125 | 1125 |
| 1126 | 1126 |
| 1127 static inline bool AllowAccessToFunction(Context* current_context, |
| 1128 JSFunction* function) { |
| 1129 return current_context->HasSameSecurityTokenAs(function->context()); |
| 1130 } |
| 1131 |
| 1132 |
| 1127 class FrameFunctionIterator { | 1133 class FrameFunctionIterator { |
| 1128 public: | 1134 public: |
| 1129 FrameFunctionIterator(Isolate* isolate, const DisallowHeapAllocation& promise) | 1135 FrameFunctionIterator(Isolate* isolate, const DisallowHeapAllocation& promise) |
| 1130 : frame_iterator_(isolate), | 1136 : isolate_(isolate), |
| 1137 frame_iterator_(isolate), |
| 1131 functions_(2), | 1138 functions_(2), |
| 1132 index_(0) { | 1139 index_(0) { |
| 1133 GetFunctions(); | 1140 GetFunctions(); |
| 1134 } | 1141 } |
| 1135 JSFunction* next() { | 1142 JSFunction* next() { |
| 1136 if (functions_.length() == 0) return NULL; | 1143 if (functions_.length() == 0) return NULL; |
| 1137 JSFunction* next_function = functions_[index_]; | 1144 while (true) { |
| 1138 index_--; | 1145 JSFunction* next_function = functions_[index_]; |
| 1139 if (index_ < 0) { | 1146 index_--; |
| 1140 GetFunctions(); | 1147 if (index_ < 0) { |
| 1148 GetFunctions(); |
| 1149 } |
| 1150 // Skip functions from other origins. |
| 1151 if (!AllowAccessToFunction(isolate_->context(), next_function)) continue; |
| 1152 return next_function; |
| 1141 } | 1153 } |
| 1142 return next_function; | |
| 1143 } | 1154 } |
| 1144 | 1155 |
| 1145 // Iterate through functions until the first occurence of 'function'. | 1156 // Iterate through functions until the first occurence of 'function'. |
| 1146 // Returns true if 'function' is found, and false if the iterator ends | 1157 // Returns true if 'function' is found, and false if the iterator ends |
| 1147 // without finding it. | 1158 // without finding it. |
| 1148 bool Find(JSFunction* function) { | 1159 bool Find(JSFunction* function) { |
| 1149 JSFunction* next_function; | 1160 JSFunction* next_function; |
| 1150 do { | 1161 do { |
| 1151 next_function = next(); | 1162 next_function = next(); |
| 1152 if (next_function == function) return true; | 1163 if (next_function == function) return true; |
| 1153 } while (next_function != NULL); | 1164 } while (next_function != NULL); |
| 1154 return false; | 1165 return false; |
| 1155 } | 1166 } |
| 1156 | 1167 |
| 1157 private: | 1168 private: |
| 1158 void GetFunctions() { | 1169 void GetFunctions() { |
| 1159 functions_.Rewind(0); | 1170 functions_.Rewind(0); |
| 1160 if (frame_iterator_.done()) return; | 1171 if (frame_iterator_.done()) return; |
| 1161 JavaScriptFrame* frame = frame_iterator_.frame(); | 1172 JavaScriptFrame* frame = frame_iterator_.frame(); |
| 1162 frame->GetFunctions(&functions_); | 1173 frame->GetFunctions(&functions_); |
| 1163 ASSERT(functions_.length() > 0); | 1174 ASSERT(functions_.length() > 0); |
| 1164 frame_iterator_.Advance(); | 1175 frame_iterator_.Advance(); |
| 1165 index_ = functions_.length() - 1; | 1176 index_ = functions_.length() - 1; |
| 1166 } | 1177 } |
| 1178 Isolate* isolate_; |
| 1167 JavaScriptFrameIterator frame_iterator_; | 1179 JavaScriptFrameIterator frame_iterator_; |
| 1168 List<JSFunction*> functions_; | 1180 List<JSFunction*> functions_; |
| 1169 int index_; | 1181 int index_; |
| 1170 }; | 1182 }; |
| 1171 | 1183 |
| 1172 | 1184 |
| 1173 MaybeHandle<JSFunction> FindCaller(Isolate* isolate, | 1185 MaybeHandle<JSFunction> FindCaller(Isolate* isolate, |
| 1174 Handle<JSFunction> function) { | 1186 Handle<JSFunction> function) { |
| 1175 DisallowHeapAllocation no_allocation; | 1187 DisallowHeapAllocation no_allocation; |
| 1176 FrameFunctionIterator it(isolate, no_allocation); | 1188 FrameFunctionIterator it(isolate, no_allocation); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1204 // and its associated throwing caller and arguments. | 1216 // and its associated throwing caller and arguments. |
| 1205 if (caller->shared()->bound()) { | 1217 if (caller->shared()->bound()) { |
| 1206 return MaybeHandle<JSFunction>(); | 1218 return MaybeHandle<JSFunction>(); |
| 1207 } | 1219 } |
| 1208 // Censor if the caller is not a sloppy mode function. | 1220 // Censor if the caller is not a sloppy mode function. |
| 1209 // Change from ES5, which used to throw, see: | 1221 // Change from ES5, which used to throw, see: |
| 1210 // https://bugs.ecmascript.org/show_bug.cgi?id=310 | 1222 // https://bugs.ecmascript.org/show_bug.cgi?id=310 |
| 1211 if (caller->shared()->strict_mode() == STRICT) { | 1223 if (caller->shared()->strict_mode() == STRICT) { |
| 1212 return MaybeHandle<JSFunction>(); | 1224 return MaybeHandle<JSFunction>(); |
| 1213 } | 1225 } |
| 1226 // Don't return caller from another security context. |
| 1227 if (!AllowAccessToFunction(isolate->context(), caller)) { |
| 1228 return MaybeHandle<JSFunction>(); |
| 1229 } |
| 1214 return Handle<JSFunction>(caller); | 1230 return Handle<JSFunction>(caller); |
| 1215 } | 1231 } |
| 1216 | 1232 |
| 1217 | 1233 |
| 1218 void Accessors::FunctionCallerGetter( | 1234 void Accessors::FunctionCallerGetter( |
| 1219 v8::Local<v8::String> name, | 1235 v8::Local<v8::String> name, |
| 1220 const v8::PropertyCallbackInfo<v8::Value>& info) { | 1236 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 1221 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); | 1237 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); |
| 1222 HandleScope scope(isolate); | 1238 HandleScope scope(isolate); |
| 1223 Handle<Object> object = GetThisFrom(info); | 1239 Handle<Object> object = GetThisFrom(info); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1322 info->set_data(Smi::FromInt(index)); | 1338 info->set_data(Smi::FromInt(index)); |
| 1323 Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport); | 1339 Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport); |
| 1324 Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport); | 1340 Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport); |
| 1325 info->set_getter(*getter); | 1341 info->set_getter(*getter); |
| 1326 if (!(attributes & ReadOnly)) info->set_setter(*setter); | 1342 if (!(attributes & ReadOnly)) info->set_setter(*setter); |
| 1327 return info; | 1343 return info; |
| 1328 } | 1344 } |
| 1329 | 1345 |
| 1330 | 1346 |
| 1331 } } // namespace v8::internal | 1347 } } // namespace v8::internal |
| OLD | NEW |