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 "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/arguments.h" | 8 #include "src/arguments.h" |
9 #include "src/frames-inl.h" | 9 #include "src/frames-inl.h" |
10 #include "src/isolate-inl.h" | 10 #include "src/isolate-inl.h" |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 | 216 |
217 // TODO(verwaest): Unify the encoding indicating "var" with DeclareGlobals. | 217 // TODO(verwaest): Unify the encoding indicating "var" with DeclareGlobals. |
218 bool is_var = *initial_value == NULL; | 218 bool is_var = *initial_value == NULL; |
219 bool is_const = initial_value->IsTheHole(); | 219 bool is_const = initial_value->IsTheHole(); |
220 bool is_function = initial_value->IsJSFunction(); | 220 bool is_function = initial_value->IsJSFunction(); |
221 DCHECK_EQ(1, | 221 DCHECK_EQ(1, |
222 BoolToInt(is_var) + BoolToInt(is_const) + BoolToInt(is_function)); | 222 BoolToInt(is_var) + BoolToInt(is_const) + BoolToInt(is_function)); |
223 | 223 |
224 int index; | 224 int index; |
225 PropertyAttributes attributes; | 225 PropertyAttributes attributes; |
226 ContextLookupFlags flags = DONT_FOLLOW_CHAINS; | |
227 BindingFlags binding_flags; | 226 BindingFlags binding_flags; |
228 Handle<Object> holder = | 227 |
229 context->Lookup(name, flags, &index, &attributes, &binding_flags); | 228 if ((attr & EVAL_DECLARED) != 0) { |
| 229 // Check for a conflict with a lexically scoped variable |
| 230 context_arg->Lookup(name, LEXICAL_TEST, &index, &attributes, |
| 231 &binding_flags); |
| 232 if (attributes != ABSENT && |
| 233 (binding_flags == MUTABLE_CHECK_INITIALIZED || |
| 234 binding_flags == IMMUTABLE_CHECK_INITIALIZED)) { |
| 235 return ThrowRedeclarationError(isolate, name); |
| 236 } |
| 237 attr = static_cast<PropertyAttributes>(attr & ~EVAL_DECLARED); |
| 238 } |
| 239 |
| 240 Handle<Object> holder = context->Lookup(name, DONT_FOLLOW_CHAINS, &index, |
| 241 &attributes, &binding_flags); |
230 if (holder.is_null()) { | 242 if (holder.is_null()) { |
231 // In case of JSProxy, an exception might have been thrown. | 243 // In case of JSProxy, an exception might have been thrown. |
232 if (isolate->has_pending_exception()) return isolate->heap()->exception(); | 244 if (isolate->has_pending_exception()) return isolate->heap()->exception(); |
233 } | 245 } |
234 | 246 |
235 Handle<JSObject> object; | 247 Handle<JSObject> object; |
236 Handle<Object> value = | 248 Handle<Object> value = |
237 is_function ? initial_value | 249 is_function ? initial_value |
238 : Handle<Object>::cast(isolate->factory()->undefined_value()); | 250 : Handle<Object>::cast(isolate->factory()->undefined_value()); |
239 | 251 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 object, name, value, attr)); | 312 object, name, value, attr)); |
301 | 313 |
302 return isolate->heap()->undefined_value(); | 314 return isolate->heap()->undefined_value(); |
303 } | 315 } |
304 | 316 |
305 } // namespace | 317 } // namespace |
306 | 318 |
307 | 319 |
308 RUNTIME_FUNCTION(Runtime_DeclareLookupSlot) { | 320 RUNTIME_FUNCTION(Runtime_DeclareLookupSlot) { |
309 HandleScope scope(isolate); | 321 HandleScope scope(isolate); |
310 DCHECK_EQ(2, args.length()); | 322 DCHECK_EQ(3, args.length()); |
311 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); | 323 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); |
312 CONVERT_ARG_HANDLE_CHECKED(Object, initial_value, 1); | 324 CONVERT_ARG_HANDLE_CHECKED(Object, initial_value, 1); |
| 325 CONVERT_ARG_HANDLE_CHECKED(Smi, property_attributes, 2); |
313 | 326 |
314 return DeclareLookupSlot(isolate, name, initial_value, NONE); | 327 PropertyAttributes attributes = |
| 328 static_cast<PropertyAttributes>(property_attributes->value()); |
| 329 return DeclareLookupSlot(isolate, name, initial_value, attributes); |
315 } | 330 } |
316 | 331 |
317 | 332 |
318 RUNTIME_FUNCTION(Runtime_DeclareReadOnlyLookupSlot) { | |
319 HandleScope scope(isolate); | |
320 DCHECK_EQ(2, args.length()); | |
321 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); | |
322 CONVERT_ARG_HANDLE_CHECKED(Object, initial_value, 1); | |
323 | |
324 return DeclareLookupSlot(isolate, name, initial_value, READ_ONLY); | |
325 } | |
326 | |
327 | |
328 RUNTIME_FUNCTION(Runtime_InitializeLegacyConstLookupSlot) { | 333 RUNTIME_FUNCTION(Runtime_InitializeLegacyConstLookupSlot) { |
329 HandleScope scope(isolate); | 334 HandleScope scope(isolate); |
330 DCHECK(args.length() == 3); | 335 DCHECK(args.length() == 3); |
331 | 336 |
332 CONVERT_ARG_HANDLE_CHECKED(Object, value, 0); | 337 CONVERT_ARG_HANDLE_CHECKED(Object, value, 0); |
333 DCHECK(!value->IsTheHole()); | 338 DCHECK(!value->IsTheHole()); |
334 // Initializations are always done in a function or native context. | 339 // Initializations are always done in a function or native context. |
335 CONVERT_ARG_HANDLE_CHECKED(Context, context_arg, 1); | 340 CONVERT_ARG_HANDLE_CHECKED(Context, context_arg, 1); |
336 Handle<Context> context(context_arg->declaration_context()); | 341 Handle<Context> context(context_arg->declaration_context()); |
337 CONVERT_ARG_HANDLE_CHECKED(String, name, 2); | 342 CONVERT_ARG_HANDLE_CHECKED(String, name, 2); |
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1161 | 1166 |
1162 // Lookup in the initial Object.prototype object. | 1167 // Lookup in the initial Object.prototype object. |
1163 Handle<Object> result; | 1168 Handle<Object> result; |
1164 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1169 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
1165 isolate, result, | 1170 isolate, result, |
1166 Object::GetProperty(isolate->initial_object_prototype(), key)); | 1171 Object::GetProperty(isolate->initial_object_prototype(), key)); |
1167 return *result; | 1172 return *result; |
1168 } | 1173 } |
1169 } // namespace internal | 1174 } // namespace internal |
1170 } // namespace v8 | 1175 } // namespace v8 |
OLD | NEW |