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/v8.h" | 5 #include "src/v8.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/messages.h" | 10 #include "src/messages.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 // Define or redefine own property. | 79 // Define or redefine own property. |
80 RETURN_FAILURE_ON_EXCEPTION(isolate, JSObject::SetOwnPropertyIgnoreAttributes( | 80 RETURN_FAILURE_ON_EXCEPTION(isolate, JSObject::SetOwnPropertyIgnoreAttributes( |
81 global, name, value, attr)); | 81 global, name, value, attr)); |
82 | 82 |
83 return isolate->heap()->undefined_value(); | 83 return isolate->heap()->undefined_value(); |
84 } | 84 } |
85 | 85 |
86 | 86 |
87 RUNTIME_FUNCTION(Runtime_DeclareGlobals) { | 87 RUNTIME_FUNCTION(Runtime_DeclareGlobals) { |
88 HandleScope scope(isolate); | 88 HandleScope scope(isolate); |
89 DCHECK(args.length() == 3); | 89 DCHECK_EQ(2, args.length()); |
90 Handle<GlobalObject> global(isolate->global_object()); | 90 Handle<GlobalObject> global(isolate->global_object()); |
| 91 Handle<Context> context(isolate->context()); |
91 | 92 |
92 CONVERT_ARG_HANDLE_CHECKED(Context, context, 0); | 93 CONVERT_ARG_HANDLE_CHECKED(FixedArray, pairs, 0); |
93 CONVERT_ARG_HANDLE_CHECKED(FixedArray, pairs, 1); | 94 CONVERT_SMI_ARG_CHECKED(flags, 1); |
94 CONVERT_SMI_ARG_CHECKED(flags, 2); | |
95 | 95 |
96 // Traverse the name/value pairs and set the properties. | 96 // Traverse the name/value pairs and set the properties. |
97 int length = pairs->length(); | 97 int length = pairs->length(); |
98 for (int i = 0; i < length; i += 2) { | 98 for (int i = 0; i < length; i += 2) { |
99 HandleScope scope(isolate); | 99 HandleScope scope(isolate); |
100 Handle<String> name(String::cast(pairs->get(i))); | 100 Handle<String> name(String::cast(pairs->get(i))); |
101 Handle<Object> initial_value(pairs->get(i + 1), isolate); | 101 Handle<Object> initial_value(pairs->get(i + 1), isolate); |
102 | 102 |
103 // We have to declare a global const property. To capture we only | 103 // We have to declare a global const property. To capture we only |
104 // assign to it when evaluating the assignment for "const x = | 104 // assign to it when evaluating the assignment for "const x = |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 } | 195 } |
196 } | 196 } |
197 | 197 |
198 RETURN_FAILURE_ON_EXCEPTION(isolate, JSObject::SetOwnPropertyIgnoreAttributes( | 198 RETURN_FAILURE_ON_EXCEPTION(isolate, JSObject::SetOwnPropertyIgnoreAttributes( |
199 global, name, value, attr)); | 199 global, name, value, attr)); |
200 | 200 |
201 return *value; | 201 return *value; |
202 } | 202 } |
203 | 203 |
204 | 204 |
205 RUNTIME_FUNCTION(Runtime_DeclareLookupSlot) { | 205 namespace { |
206 HandleScope scope(isolate); | |
207 DCHECK(args.length() == 4); | |
208 | 206 |
| 207 Object* DeclareLookupSlot(Isolate* isolate, Handle<String> name, |
| 208 Handle<Object> initial_value, |
| 209 PropertyAttributes attr) { |
209 // Declarations are always made in a function, eval or script context. In | 210 // Declarations are always made in a function, eval or script context. In |
210 // the case of eval code, the context passed is the context of the caller, | 211 // the case of eval code, the context passed is the context of the caller, |
211 // which may be some nested context and not the declaration context. | 212 // which may be some nested context and not the declaration context. |
212 CONVERT_ARG_HANDLE_CHECKED(Context, context_arg, 0); | 213 Handle<Context> context_arg(isolate->context(), isolate); |
213 Handle<Context> context(context_arg->declaration_context()); | 214 Handle<Context> context(context_arg->declaration_context(), isolate); |
214 CONVERT_ARG_HANDLE_CHECKED(String, name, 1); | |
215 CONVERT_SMI_ARG_CHECKED(attr_arg, 2); | |
216 PropertyAttributes attr = static_cast<PropertyAttributes>(attr_arg); | |
217 RUNTIME_ASSERT(attr == READ_ONLY || attr == NONE); | |
218 CONVERT_ARG_HANDLE_CHECKED(Object, initial_value, 3); | |
219 | 215 |
220 // TODO(verwaest): Unify the encoding indicating "var" with DeclareGlobals. | 216 // TODO(verwaest): Unify the encoding indicating "var" with DeclareGlobals. |
221 bool is_var = *initial_value == NULL; | 217 bool is_var = *initial_value == NULL; |
222 bool is_const = initial_value->IsTheHole(); | 218 bool is_const = initial_value->IsTheHole(); |
223 bool is_function = initial_value->IsJSFunction(); | 219 bool is_function = initial_value->IsJSFunction(); |
224 DCHECK_EQ(1, | 220 DCHECK_EQ(1, |
225 BoolToInt(is_var) + BoolToInt(is_const) + BoolToInt(is_function)); | 221 BoolToInt(is_var) + BoolToInt(is_const) + BoolToInt(is_function)); |
226 | 222 |
227 int index; | 223 int index; |
228 PropertyAttributes attributes; | 224 PropertyAttributes attributes; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 isolate->factory()->NewJSObject(isolate->context_extension_function()); | 283 isolate->factory()->NewJSObject(isolate->context_extension_function()); |
288 context->set_extension(*object); | 284 context->set_extension(*object); |
289 } | 285 } |
290 | 286 |
291 RETURN_FAILURE_ON_EXCEPTION(isolate, JSObject::SetOwnPropertyIgnoreAttributes( | 287 RETURN_FAILURE_ON_EXCEPTION(isolate, JSObject::SetOwnPropertyIgnoreAttributes( |
292 object, name, value, attr)); | 288 object, name, value, attr)); |
293 | 289 |
294 return isolate->heap()->undefined_value(); | 290 return isolate->heap()->undefined_value(); |
295 } | 291 } |
296 | 292 |
| 293 } // namespace |
| 294 |
| 295 |
| 296 RUNTIME_FUNCTION(Runtime_DeclareLookupSlot) { |
| 297 HandleScope scope(isolate); |
| 298 DCHECK_EQ(2, args.length()); |
| 299 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); |
| 300 CONVERT_ARG_HANDLE_CHECKED(Object, initial_value, 1); |
| 301 |
| 302 return DeclareLookupSlot(isolate, name, initial_value, NONE); |
| 303 } |
| 304 |
| 305 |
| 306 RUNTIME_FUNCTION(Runtime_DeclareReadOnlyLookupSlot) { |
| 307 HandleScope scope(isolate); |
| 308 DCHECK_EQ(2, args.length()); |
| 309 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); |
| 310 CONVERT_ARG_HANDLE_CHECKED(Object, initial_value, 1); |
| 311 |
| 312 return DeclareLookupSlot(isolate, name, initial_value, READ_ONLY); |
| 313 } |
| 314 |
297 | 315 |
298 RUNTIME_FUNCTION(Runtime_InitializeLegacyConstLookupSlot) { | 316 RUNTIME_FUNCTION(Runtime_InitializeLegacyConstLookupSlot) { |
299 HandleScope scope(isolate); | 317 HandleScope scope(isolate); |
300 DCHECK(args.length() == 3); | 318 DCHECK(args.length() == 3); |
301 | 319 |
302 CONVERT_ARG_HANDLE_CHECKED(Object, value, 0); | 320 CONVERT_ARG_HANDLE_CHECKED(Object, value, 0); |
303 DCHECK(!value->IsTheHole()); | 321 DCHECK(!value->IsTheHole()); |
304 // Initializations are always done in a function or native context. | 322 // Initializations are always done in a function or native context. |
305 CONVERT_ARG_HANDLE_CHECKED(Context, context_arg, 1); | 323 CONVERT_ARG_HANDLE_CHECKED(Context, context_arg, 1); |
306 Handle<Context> context(context_arg->declaration_context()); | 324 Handle<Context> context(context_arg->declaration_context()); |
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1149 return Smi::FromInt(frame->GetArgumentsLength()); | 1167 return Smi::FromInt(frame->GetArgumentsLength()); |
1150 } | 1168 } |
1151 | 1169 |
1152 | 1170 |
1153 RUNTIME_FUNCTION(Runtime_Arguments) { | 1171 RUNTIME_FUNCTION(Runtime_Arguments) { |
1154 SealHandleScope shs(isolate); | 1172 SealHandleScope shs(isolate); |
1155 return __RT_impl_Runtime_GetArgumentsProperty(args, isolate); | 1173 return __RT_impl_Runtime_GetArgumentsProperty(args, isolate); |
1156 } | 1174 } |
1157 } // namespace internal | 1175 } // namespace internal |
1158 } // namespace v8 | 1176 } // namespace v8 |
OLD | NEW |