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 <stdlib.h> | 5 #include <stdlib.h> |
6 #include <limits> | 6 #include <limits> |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/arguments.h" | 10 #include "src/arguments.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 | 90 |
91 RUNTIME_FUNCTION(Runtime_HomeObjectSymbol) { | 91 RUNTIME_FUNCTION(Runtime_HomeObjectSymbol) { |
92 DCHECK(args.length() == 0); | 92 DCHECK(args.length() == 0); |
93 return isolate->heap()->home_object_symbol(); | 93 return isolate->heap()->home_object_symbol(); |
94 } | 94 } |
95 | 95 |
96 | 96 |
97 static MaybeHandle<Object> DefineClass(Isolate* isolate, Handle<Object> name, | 97 static MaybeHandle<Object> DefineClass(Isolate* isolate, Handle<Object> name, |
98 Handle<Object> super_class, | 98 Handle<Object> super_class, |
99 Handle<JSFunction> constructor, | 99 Handle<JSFunction> constructor, |
100 Handle<Script> script, | |
101 int start_position, int end_position) { | 100 int start_position, int end_position) { |
102 Handle<Object> prototype_parent; | 101 Handle<Object> prototype_parent; |
103 Handle<Object> constructor_parent; | 102 Handle<Object> constructor_parent; |
104 | 103 |
105 if (super_class->IsTheHole()) { | 104 if (super_class->IsTheHole()) { |
106 prototype_parent = isolate->initial_object_prototype(); | 105 prototype_parent = isolate->initial_object_prototype(); |
107 } else { | 106 } else { |
108 if (super_class->IsNull()) { | 107 if (super_class->IsNull()) { |
109 prototype_parent = isolate->factory()->null_value(); | 108 prototype_parent = isolate->factory()->null_value(); |
110 } else if (super_class->IsSpecFunction()) { | 109 } else if (super_class->IsSpecFunction()) { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 RETURN_ON_EXCEPTION( | 174 RETURN_ON_EXCEPTION( |
176 isolate, JSObject::SetPrototype(constructor, constructor_parent, false), | 175 isolate, JSObject::SetPrototype(constructor, constructor_parent, false), |
177 Object); | 176 Object); |
178 } | 177 } |
179 | 178 |
180 JSObject::AddProperty(prototype, isolate->factory()->constructor_string(), | 179 JSObject::AddProperty(prototype, isolate->factory()->constructor_string(), |
181 constructor, DONT_ENUM); | 180 constructor, DONT_ENUM); |
182 | 181 |
183 // Install private properties that are used to construct the FunctionToString. | 182 // Install private properties that are used to construct the FunctionToString. |
184 RETURN_ON_EXCEPTION( | 183 RETURN_ON_EXCEPTION( |
185 isolate, Object::SetProperty(constructor, | |
186 isolate->factory()->class_script_symbol(), | |
187 script, STRICT), | |
188 Object); | |
189 RETURN_ON_EXCEPTION( | |
190 isolate, | 184 isolate, |
191 Object::SetProperty( | 185 Object::SetProperty( |
192 constructor, isolate->factory()->class_start_position_symbol(), | 186 constructor, isolate->factory()->class_start_position_symbol(), |
193 handle(Smi::FromInt(start_position), isolate), STRICT), | 187 handle(Smi::FromInt(start_position), isolate), STRICT), |
194 Object); | 188 Object); |
195 RETURN_ON_EXCEPTION( | 189 RETURN_ON_EXCEPTION( |
196 isolate, Object::SetProperty( | 190 isolate, Object::SetProperty( |
197 constructor, isolate->factory()->class_end_position_symbol(), | 191 constructor, isolate->factory()->class_end_position_symbol(), |
198 handle(Smi::FromInt(end_position), isolate), STRICT), | 192 handle(Smi::FromInt(end_position), isolate), STRICT), |
199 Object); | 193 Object); |
200 | 194 |
201 return constructor; | 195 return constructor; |
202 } | 196 } |
203 | 197 |
204 | 198 |
205 RUNTIME_FUNCTION(Runtime_DefineClass) { | 199 RUNTIME_FUNCTION(Runtime_DefineClass) { |
206 HandleScope scope(isolate); | 200 HandleScope scope(isolate); |
207 DCHECK(args.length() == 6); | 201 DCHECK(args.length() == 5); |
208 CONVERT_ARG_HANDLE_CHECKED(Object, name, 0); | 202 CONVERT_ARG_HANDLE_CHECKED(Object, name, 0); |
209 CONVERT_ARG_HANDLE_CHECKED(Object, super_class, 1); | 203 CONVERT_ARG_HANDLE_CHECKED(Object, super_class, 1); |
210 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 2); | 204 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 2); |
211 CONVERT_ARG_HANDLE_CHECKED(Script, script, 3); | 205 CONVERT_SMI_ARG_CHECKED(start_position, 3); |
212 CONVERT_SMI_ARG_CHECKED(start_position, 4); | 206 CONVERT_SMI_ARG_CHECKED(end_position, 4); |
213 CONVERT_SMI_ARG_CHECKED(end_position, 5); | |
214 | 207 |
215 Handle<Object> result; | 208 Handle<Object> result; |
216 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 209 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
217 isolate, result, DefineClass(isolate, name, super_class, constructor, | 210 isolate, result, DefineClass(isolate, name, super_class, constructor, |
218 script, start_position, end_position)); | 211 start_position, end_position)); |
219 return *result; | 212 return *result; |
220 } | 213 } |
221 | 214 |
222 | 215 |
223 RUNTIME_FUNCTION(Runtime_DefineClassStrong) { | 216 RUNTIME_FUNCTION(Runtime_DefineClassStrong) { |
224 HandleScope scope(isolate); | 217 HandleScope scope(isolate); |
225 DCHECK(args.length() == 6); | 218 DCHECK(args.length() == 5); |
226 CONVERT_ARG_HANDLE_CHECKED(Object, name, 0); | 219 CONVERT_ARG_HANDLE_CHECKED(Object, name, 0); |
227 CONVERT_ARG_HANDLE_CHECKED(Object, super_class, 1); | 220 CONVERT_ARG_HANDLE_CHECKED(Object, super_class, 1); |
228 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 2); | 221 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 2); |
229 CONVERT_ARG_HANDLE_CHECKED(Script, script, 3); | 222 CONVERT_SMI_ARG_CHECKED(start_position, 3); |
230 CONVERT_SMI_ARG_CHECKED(start_position, 4); | 223 CONVERT_SMI_ARG_CHECKED(end_position, 4); |
231 CONVERT_SMI_ARG_CHECKED(end_position, 5); | |
232 | 224 |
233 if (super_class->IsNull()) { | 225 if (super_class->IsNull()) { |
234 THROW_NEW_ERROR_RETURN_FAILURE( | 226 THROW_NEW_ERROR_RETURN_FAILURE( |
235 isolate, NewTypeError(MessageTemplate::kStrongExtendNull)); | 227 isolate, NewTypeError(MessageTemplate::kStrongExtendNull)); |
236 } | 228 } |
237 | 229 |
238 Handle<Object> result; | 230 Handle<Object> result; |
239 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 231 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
240 isolate, result, DefineClass(isolate, name, super_class, constructor, | 232 isolate, result, DefineClass(isolate, name, super_class, constructor, |
241 script, start_position, end_position)); | 233 start_position, end_position)); |
242 return *result; | 234 return *result; |
243 } | 235 } |
244 | 236 |
245 | 237 |
246 RUNTIME_FUNCTION(Runtime_DefineClassMethod) { | 238 RUNTIME_FUNCTION(Runtime_DefineClassMethod) { |
247 HandleScope scope(isolate); | 239 HandleScope scope(isolate); |
248 DCHECK(args.length() == 3); | 240 DCHECK(args.length() == 3); |
249 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); | 241 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); |
250 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); | 242 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); |
251 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 2); | 243 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 2); |
(...skipping 24 matching lines...) Expand all Loading... |
276 } | 268 } |
277 return *constructor; | 269 return *constructor; |
278 } | 270 } |
279 | 271 |
280 | 272 |
281 RUNTIME_FUNCTION(Runtime_ClassGetSourceCode) { | 273 RUNTIME_FUNCTION(Runtime_ClassGetSourceCode) { |
282 HandleScope shs(isolate); | 274 HandleScope shs(isolate); |
283 DCHECK(args.length() == 1); | 275 DCHECK(args.length() == 1); |
284 CONVERT_ARG_HANDLE_CHECKED(JSFunction, fun, 0); | 276 CONVERT_ARG_HANDLE_CHECKED(JSFunction, fun, 0); |
285 | 277 |
286 Handle<Object> script; | |
287 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
288 isolate, script, | |
289 Object::GetProperty(fun, isolate->factory()->class_script_symbol())); | |
290 if (!script->IsScript()) { | |
291 return isolate->heap()->undefined_value(); | |
292 } | |
293 | |
294 Handle<Symbol> start_position_symbol( | 278 Handle<Symbol> start_position_symbol( |
295 isolate->heap()->class_start_position_symbol()); | 279 isolate->heap()->class_start_position_symbol()); |
296 Handle<Object> start_position; | 280 Handle<Object> start_position = |
297 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 281 JSReceiver::GetDataProperty(fun, start_position_symbol); |
298 isolate, start_position, Object::GetProperty(fun, start_position_symbol)); | 282 if (!start_position->IsSmi()) return isolate->heap()->undefined_value(); |
299 | 283 |
300 Handle<Symbol> end_position_symbol( | 284 Handle<Symbol> end_position_symbol( |
301 isolate->heap()->class_end_position_symbol()); | 285 isolate->heap()->class_end_position_symbol()); |
302 Handle<Object> end_position; | 286 Handle<Object> end_position = |
303 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 287 JSReceiver::GetDataProperty(fun, end_position_symbol); |
304 isolate, end_position, Object::GetProperty(fun, end_position_symbol)); | 288 CHECK(end_position->IsSmi()); |
305 | 289 |
306 if (!start_position->IsSmi() || !end_position->IsSmi() || | 290 Handle<String> source( |
307 !Handle<Script>::cast(script)->HasValidSource()) { | 291 String::cast(Script::cast(fun->shared()->script())->source())); |
308 return isolate->ThrowIllegalOperation(); | |
309 } | |
310 | |
311 Handle<String> source(String::cast(Handle<Script>::cast(script)->source())); | |
312 return *isolate->factory()->NewSubString( | 292 return *isolate->factory()->NewSubString( |
313 source, Handle<Smi>::cast(start_position)->value(), | 293 source, Handle<Smi>::cast(start_position)->value(), |
314 Handle<Smi>::cast(end_position)->value()); | 294 Handle<Smi>::cast(end_position)->value()); |
315 } | 295 } |
316 | 296 |
317 | 297 |
318 static MaybeHandle<Object> LoadFromSuper(Isolate* isolate, | 298 static MaybeHandle<Object> LoadFromSuper(Isolate* isolate, |
319 Handle<Object> receiver, | 299 Handle<Object> receiver, |
320 Handle<JSObject> home_object, | 300 Handle<JSObject> home_object, |
321 Handle<Name> name, | 301 Handle<Name> name, |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 Handle<Object> result; | 565 Handle<Object> result; |
586 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 566 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
587 isolate, result, | 567 isolate, result, |
588 Execution::Call(isolate, reflect, isolate->factory()->undefined_value(), | 568 Execution::Call(isolate, reflect, isolate->factory()->undefined_value(), |
589 arraysize(argv), argv)); | 569 arraysize(argv), argv)); |
590 | 570 |
591 return *result; | 571 return *result; |
592 } | 572 } |
593 } // namespace internal | 573 } // namespace internal |
594 } // namespace v8 | 574 } // namespace v8 |
OLD | NEW |