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/isolate-inl.h" | 10 #include "src/isolate-inl.h" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 CONVERT_ARG_HANDLE_CHECKED(JSObject, home_object, 1); | 148 CONVERT_ARG_HANDLE_CHECKED(JSObject, home_object, 1); |
149 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); | 149 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); |
150 CONVERT_ARG_HANDLE_CHECKED(Name, name, 3); | 150 CONVERT_ARG_HANDLE_CHECKED(Name, name, 3); |
151 | 151 |
152 return StoreToSuper(isolate, home_object, receiver, name, value, SLOPPY); | 152 return StoreToSuper(isolate, home_object, receiver, name, value, SLOPPY); |
153 } | 153 } |
154 | 154 |
155 | 155 |
156 RUNTIME_FUNCTION(Runtime_DefineClass) { | 156 RUNTIME_FUNCTION(Runtime_DefineClass) { |
157 HandleScope scope(isolate); | 157 HandleScope scope(isolate); |
158 DCHECK(args.length() == 3); | 158 DCHECK(args.length() == 6); |
159 CONVERT_ARG_HANDLE_CHECKED(Object, name, 0); | 159 CONVERT_ARG_HANDLE_CHECKED(Object, name, 0); |
160 CONVERT_ARG_HANDLE_CHECKED(Object, super_class, 1); | 160 CONVERT_ARG_HANDLE_CHECKED(Object, super_class, 1); |
161 CONVERT_ARG_HANDLE_CHECKED(Object, constructor, 2); | 161 CONVERT_ARG_HANDLE_CHECKED(Object, constructor, 2); |
162 CONVERT_ARG_HANDLE_CHECKED(Script, script, 3); | |
163 CONVERT_SMI_ARG_CHECKED(start_position, 4); | |
164 CONVERT_SMI_ARG_CHECKED(end_position, 5); | |
162 | 165 |
163 Handle<Object> prototype_parent; | 166 Handle<Object> prototype_parent; |
164 Handle<Object> constructor_parent; | 167 Handle<Object> constructor_parent; |
165 | 168 |
166 if (super_class->IsTheHole()) { | 169 if (super_class->IsTheHole()) { |
167 prototype_parent = isolate->initial_object_prototype(); | 170 prototype_parent = isolate->initial_object_prototype(); |
168 } else { | 171 } else { |
169 if (super_class->IsNull()) { | 172 if (super_class->IsNull()) { |
170 prototype_parent = isolate->factory()->null_value(); | 173 prototype_parent = isolate->factory()->null_value(); |
171 } else if (super_class->IsSpecFunction()) { | 174 } else if (super_class->IsSpecFunction()) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
221 ctor, home_object_symbol, prototype, DONT_ENUM)); | 224 ctor, home_object_symbol, prototype, DONT_ENUM)); |
222 | 225 |
223 if (!constructor_parent.is_null()) { | 226 if (!constructor_parent.is_null()) { |
224 RETURN_FAILURE_ON_EXCEPTION( | 227 RETURN_FAILURE_ON_EXCEPTION( |
225 isolate, JSObject::SetPrototype(ctor, constructor_parent, false)); | 228 isolate, JSObject::SetPrototype(ctor, constructor_parent, false)); |
226 } | 229 } |
227 | 230 |
228 JSObject::AddProperty(prototype, isolate->factory()->constructor_string(), | 231 JSObject::AddProperty(prototype, isolate->factory()->constructor_string(), |
229 ctor, DONT_ENUM); | 232 ctor, DONT_ENUM); |
230 | 233 |
234 // Install private properties that are used to construct the FunctionToString. | |
235 RETURN_FAILURE_ON_EXCEPTION( | |
236 isolate, | |
237 Object::SetProperty(ctor, isolate->factory()->class_script_symbol(), | |
238 script, STRICT)); | |
239 RETURN_FAILURE_ON_EXCEPTION( | |
240 isolate, Object::SetProperty( | |
241 ctor, isolate->factory()->class_start_position_symbol(), | |
242 handle(Smi::FromInt(start_position), isolate), STRICT)); | |
243 RETURN_FAILURE_ON_EXCEPTION( | |
244 isolate, | |
245 Object::SetProperty(ctor, isolate->factory()->class_end_position_symbol(), | |
246 handle(Smi::FromInt(end_position), isolate), STRICT)); | |
247 | |
231 return *ctor; | 248 return *ctor; |
232 } | 249 } |
250 | |
251 | |
252 RUNTIME_FUNCTION(Runtime_ClassGetSourceCode) { | |
253 HandleScope shs(isolate); | |
254 DCHECK(args.length() == 1); | |
255 CONVERT_ARG_HANDLE_CHECKED(JSFunction, fun, 0); | |
256 | |
257 Handle<Object> script; | |
258 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
259 isolate, script, | |
260 Object::GetProperty(fun, isolate->factory()->class_script_symbol())); | |
261 if (!script->IsScript()) { | |
262 return isolate->heap()->undefined_value(); | |
263 } | |
264 | |
265 Handle<Symbol> start_position_symbol( | |
266 isolate->heap()->class_start_position_symbol()); | |
267 Handle<Object> start_position; | |
268 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
269 isolate, start_position, Object::GetProperty(fun, start_position_symbol)); | |
270 | |
271 Handle<Symbol> end_position_symbol( | |
272 isolate->heap()->class_end_position_symbol()); | |
273 Handle<Object> end_position; | |
274 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
275 isolate, end_position, Object::GetProperty(fun, end_position_symbol)); | |
276 | |
277 Handle<String> source(String::cast(Handle<Script>::cast(script)->source())); | |
278 return *isolate->factory()->NewSubString( | |
279 source, Handle<Smi>::cast(start_position)->value(), | |
Dmitry Lomov (no reviews)
2014/10/08 09:43:59
Some defensive programming here: check that start_
arv (Not doing code reviews)
2014/10/08 14:00:32
Done.
| |
280 Handle<Smi>::cast(end_position)->value()); | |
281 } | |
233 } | 282 } |
234 } // namespace v8::internal | 283 } // namespace v8::internal |
OLD | NEW |