| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 DCHECK(args.length() == 0); | 55 DCHECK(args.length() == 0); |
| 56 return isolate->heap()->home_object_symbol(); | 56 return isolate->heap()->home_object_symbol(); |
| 57 } | 57 } |
| 58 | 58 |
| 59 | 59 |
| 60 RUNTIME_FUNCTION(Runtime_DefineClass) { | 60 RUNTIME_FUNCTION(Runtime_DefineClass) { |
| 61 HandleScope scope(isolate); | 61 HandleScope scope(isolate); |
| 62 DCHECK(args.length() == 6); | 62 DCHECK(args.length() == 6); |
| 63 CONVERT_ARG_HANDLE_CHECKED(Object, name, 0); | 63 CONVERT_ARG_HANDLE_CHECKED(Object, name, 0); |
| 64 CONVERT_ARG_HANDLE_CHECKED(Object, super_class, 1); | 64 CONVERT_ARG_HANDLE_CHECKED(Object, super_class, 1); |
| 65 CONVERT_ARG_HANDLE_CHECKED(Object, constructor, 2); | 65 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 2); |
| 66 CONVERT_ARG_HANDLE_CHECKED(Script, script, 3); | 66 CONVERT_ARG_HANDLE_CHECKED(Script, script, 3); |
| 67 CONVERT_SMI_ARG_CHECKED(start_position, 4); | 67 CONVERT_SMI_ARG_CHECKED(start_position, 4); |
| 68 CONVERT_SMI_ARG_CHECKED(end_position, 5); | 68 CONVERT_SMI_ARG_CHECKED(end_position, 5); |
| 69 | 69 |
| 70 Handle<Object> prototype_parent; | 70 Handle<Object> prototype_parent; |
| 71 Handle<Object> constructor_parent; | 71 Handle<Object> constructor_parent; |
| 72 | 72 |
| 73 if (super_class->IsTheHole()) { | 73 if (super_class->IsTheHole()) { |
| 74 prototype_parent = isolate->initial_object_prototype(); | 74 prototype_parent = isolate->initial_object_prototype(); |
| 75 } else { | 75 } else { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 94 isolate, | 94 isolate, |
| 95 NewTypeError("extends_value_not_a_function", HandleVector(args, 1))); | 95 NewTypeError("extends_value_not_a_function", HandleVector(args, 1))); |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 | 98 |
| 99 Handle<Map> map = | 99 Handle<Map> map = |
| 100 isolate->factory()->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 100 isolate->factory()->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
| 101 map->set_prototype(*prototype_parent); | 101 map->set_prototype(*prototype_parent); |
| 102 Handle<JSObject> prototype = isolate->factory()->NewJSObjectFromMap(map); | 102 Handle<JSObject> prototype = isolate->factory()->NewJSObjectFromMap(map); |
| 103 | 103 |
| 104 JSFunction::SetPrototype(constructor, prototype); |
| 105 PropertyAttributes attribs = |
| 106 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 107 RETURN_FAILURE_ON_EXCEPTION( |
| 108 isolate, JSObject::SetOwnPropertyIgnoreAttributes( |
| 109 constructor, isolate->factory()->prototype_string(), |
| 110 prototype, attribs)); |
| 111 |
| 112 Handle<Symbol> home_object_symbol(isolate->heap()->home_object_symbol()); |
| 113 RETURN_FAILURE_ON_EXCEPTION( |
| 114 isolate, JSObject::SetOwnPropertyIgnoreAttributes( |
| 115 constructor, home_object_symbol, prototype, DONT_ENUM)); |
| 116 |
| 117 if (!constructor_parent.is_null()) { |
| 118 RETURN_FAILURE_ON_EXCEPTION( |
| 119 isolate, |
| 120 JSObject::SetPrototype(constructor, constructor_parent, false)); |
| 121 } |
| 122 |
| 104 Handle<String> name_string = name->IsString() | 123 Handle<String> name_string = name->IsString() |
| 105 ? Handle<String>::cast(name) | 124 ? Handle<String>::cast(name) |
| 106 : isolate->factory()->empty_string(); | 125 : isolate->factory()->empty_string(); |
| 107 | |
| 108 Handle<JSFunction> ctor; | |
| 109 if (constructor->IsSpecFunction()) { | |
| 110 ctor = Handle<JSFunction>::cast(constructor); | |
| 111 JSFunction::SetPrototype(ctor, prototype); | |
| 112 PropertyAttributes attribs = | |
| 113 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); | |
| 114 RETURN_FAILURE_ON_EXCEPTION( | |
| 115 isolate, | |
| 116 JSObject::SetOwnPropertyIgnoreAttributes( | |
| 117 ctor, isolate->factory()->prototype_string(), prototype, attribs)); | |
| 118 } else { | |
| 119 // TODO(arv): This should not use an empty function but a function that | |
| 120 // calls super. | |
| 121 Handle<Code> code(isolate->builtins()->builtin(Builtins::kEmptyFunction)); | |
| 122 ctor = isolate->factory()->NewFunction(name_string, code, prototype, true); | |
| 123 } | |
| 124 | |
| 125 Handle<Symbol> home_object_symbol(isolate->heap()->home_object_symbol()); | |
| 126 RETURN_FAILURE_ON_EXCEPTION( | 126 RETURN_FAILURE_ON_EXCEPTION( |
| 127 isolate, JSObject::SetOwnPropertyIgnoreAttributes( | 127 isolate, JSObject::SetOwnPropertyIgnoreAttributes( |
| 128 ctor, home_object_symbol, prototype, DONT_ENUM)); | 128 constructor, isolate->factory()->name_string(), name_string, |
| 129 | 129 attribs)); |
| 130 if (!constructor_parent.is_null()) { | |
| 131 RETURN_FAILURE_ON_EXCEPTION( | |
| 132 isolate, JSObject::SetPrototype(ctor, constructor_parent, false)); | |
| 133 } | |
| 134 | 130 |
| 135 JSObject::AddProperty(prototype, isolate->factory()->constructor_string(), | 131 JSObject::AddProperty(prototype, isolate->factory()->constructor_string(), |
| 136 ctor, DONT_ENUM); | 132 constructor, DONT_ENUM); |
| 137 | 133 |
| 138 // Install private properties that are used to construct the FunctionToString. | 134 // Install private properties that are used to construct the FunctionToString. |
| 139 RETURN_FAILURE_ON_EXCEPTION( | 135 RETURN_FAILURE_ON_EXCEPTION( |
| 136 isolate, Object::SetProperty(constructor, |
| 137 isolate->factory()->class_script_symbol(), |
| 138 script, STRICT)); |
| 139 RETURN_FAILURE_ON_EXCEPTION( |
| 140 isolate, | 140 isolate, |
| 141 Object::SetProperty(ctor, isolate->factory()->class_script_symbol(), | 141 Object::SetProperty( |
| 142 script, STRICT)); | 142 constructor, isolate->factory()->class_start_position_symbol(), |
| 143 handle(Smi::FromInt(start_position), isolate), STRICT)); |
| 143 RETURN_FAILURE_ON_EXCEPTION( | 144 RETURN_FAILURE_ON_EXCEPTION( |
| 144 isolate, Object::SetProperty( | 145 isolate, Object::SetProperty( |
| 145 ctor, isolate->factory()->class_start_position_symbol(), | 146 constructor, isolate->factory()->class_end_position_symbol(), |
| 146 handle(Smi::FromInt(start_position), isolate), STRICT)); | 147 handle(Smi::FromInt(end_position), isolate), STRICT)); |
| 147 RETURN_FAILURE_ON_EXCEPTION( | |
| 148 isolate, | |
| 149 Object::SetProperty(ctor, isolate->factory()->class_end_position_symbol(), | |
| 150 handle(Smi::FromInt(end_position), isolate), STRICT)); | |
| 151 | 148 |
| 152 return *ctor; | 149 return *constructor; |
| 153 } | 150 } |
| 154 | 151 |
| 155 | 152 |
| 156 RUNTIME_FUNCTION(Runtime_DefineClassMethod) { | 153 RUNTIME_FUNCTION(Runtime_DefineClassMethod) { |
| 157 HandleScope scope(isolate); | 154 HandleScope scope(isolate); |
| 158 DCHECK(args.length() == 3); | 155 DCHECK(args.length() == 3); |
| 159 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); | 156 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); |
| 160 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); | 157 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); |
| 161 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 2); | 158 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 2); |
| 162 | 159 |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 DCHECK(args.length() == 4); | 447 DCHECK(args.length() == 4); |
| 451 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 0); | 448 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 0); |
| 452 CONVERT_ARG_HANDLE_CHECKED(JSObject, home_object, 1); | 449 CONVERT_ARG_HANDLE_CHECKED(JSObject, home_object, 1); |
| 453 CONVERT_ARG_HANDLE_CHECKED(Object, key, 2); | 450 CONVERT_ARG_HANDLE_CHECKED(Object, key, 2); |
| 454 CONVERT_ARG_HANDLE_CHECKED(Object, value, 3); | 451 CONVERT_ARG_HANDLE_CHECKED(Object, value, 3); |
| 455 | 452 |
| 456 return StoreKeyedToSuper(isolate, home_object, receiver, key, value, SLOPPY); | 453 return StoreKeyedToSuper(isolate, home_object, receiver, key, value, SLOPPY); |
| 457 } | 454 } |
| 458 } | 455 } |
| 459 } // namespace v8::internal | 456 } // namespace v8::internal |
| OLD | NEW |