| 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 21 matching lines...) Expand all Loading... |
| 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 Handle<String> name_string = name->IsString() | 104 Handle<String> name_string = name->IsString() |
| 105 ? Handle<String>::cast(name) | 105 ? Handle<String>::cast(name) |
| 106 : isolate->factory()->empty_string(); | 106 : isolate->factory()->empty_string(); |
| 107 constructor->shared()->set_name(*name_string); |
| 107 | 108 |
| 108 Handle<JSFunction> ctor; | 109 JSFunction::SetPrototype(constructor, prototype); |
| 109 if (constructor->IsSpecFunction()) { | 110 PropertyAttributes attribs = |
| 110 ctor = Handle<JSFunction>::cast(constructor); | 111 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 111 JSFunction::SetPrototype(ctor, prototype); | 112 RETURN_FAILURE_ON_EXCEPTION( |
| 112 PropertyAttributes attribs = | 113 isolate, JSObject::SetOwnPropertyIgnoreAttributes( |
| 113 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); | 114 constructor, isolate->factory()->prototype_string(), |
| 114 RETURN_FAILURE_ON_EXCEPTION( | 115 prototype, attribs)); |
| 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()); | 116 Handle<Symbol> home_object_symbol(isolate->heap()->home_object_symbol()); |
| 126 RETURN_FAILURE_ON_EXCEPTION( | 117 RETURN_FAILURE_ON_EXCEPTION( |
| 127 isolate, JSObject::SetOwnPropertyIgnoreAttributes( | 118 isolate, JSObject::SetOwnPropertyIgnoreAttributes( |
| 128 ctor, home_object_symbol, prototype, DONT_ENUM)); | 119 constructor, home_object_symbol, prototype, DONT_ENUM)); |
| 129 | 120 |
| 130 if (!constructor_parent.is_null()) { | 121 if (!constructor_parent.is_null()) { |
| 131 RETURN_FAILURE_ON_EXCEPTION( | 122 RETURN_FAILURE_ON_EXCEPTION( |
| 132 isolate, JSObject::SetPrototype(ctor, constructor_parent, false)); | 123 isolate, |
| 124 JSObject::SetPrototype(constructor, constructor_parent, false)); |
| 133 } | 125 } |
| 134 | 126 |
| 135 JSObject::AddProperty(prototype, isolate->factory()->constructor_string(), | 127 JSObject::AddProperty(prototype, isolate->factory()->constructor_string(), |
| 136 ctor, DONT_ENUM); | 128 constructor, DONT_ENUM); |
| 137 | 129 |
| 138 // Install private properties that are used to construct the FunctionToString. | 130 // Install private properties that are used to construct the FunctionToString. |
| 139 RETURN_FAILURE_ON_EXCEPTION( | 131 RETURN_FAILURE_ON_EXCEPTION( |
| 132 isolate, Object::SetProperty(constructor, |
| 133 isolate->factory()->class_script_symbol(), |
| 134 script, STRICT)); |
| 135 RETURN_FAILURE_ON_EXCEPTION( |
| 140 isolate, | 136 isolate, |
| 141 Object::SetProperty(ctor, isolate->factory()->class_script_symbol(), | 137 Object::SetProperty( |
| 142 script, STRICT)); | 138 constructor, isolate->factory()->class_start_position_symbol(), |
| 139 handle(Smi::FromInt(start_position), isolate), STRICT)); |
| 143 RETURN_FAILURE_ON_EXCEPTION( | 140 RETURN_FAILURE_ON_EXCEPTION( |
| 144 isolate, Object::SetProperty( | 141 isolate, Object::SetProperty( |
| 145 ctor, isolate->factory()->class_start_position_symbol(), | 142 constructor, isolate->factory()->class_end_position_symbol(), |
| 146 handle(Smi::FromInt(start_position), isolate), STRICT)); | 143 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 | 144 |
| 152 return *ctor; | 145 return *constructor; |
| 153 } | 146 } |
| 154 | 147 |
| 155 | 148 |
| 156 RUNTIME_FUNCTION(Runtime_DefineClassMethod) { | 149 RUNTIME_FUNCTION(Runtime_DefineClassMethod) { |
| 157 HandleScope scope(isolate); | 150 HandleScope scope(isolate); |
| 158 DCHECK(args.length() == 3); | 151 DCHECK(args.length() == 3); |
| 159 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); | 152 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); |
| 160 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); | 153 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); |
| 161 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 2); | 154 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 2); |
| 162 | 155 |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 DCHECK(args.length() == 4); | 443 DCHECK(args.length() == 4); |
| 451 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 0); | 444 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 0); |
| 452 CONVERT_ARG_HANDLE_CHECKED(JSObject, home_object, 1); | 445 CONVERT_ARG_HANDLE_CHECKED(JSObject, home_object, 1); |
| 453 CONVERT_ARG_HANDLE_CHECKED(Object, key, 2); | 446 CONVERT_ARG_HANDLE_CHECKED(Object, key, 2); |
| 454 CONVERT_ARG_HANDLE_CHECKED(Object, value, 3); | 447 CONVERT_ARG_HANDLE_CHECKED(Object, value, 3); |
| 455 | 448 |
| 456 return StoreKeyedToSuper(isolate, home_object, receiver, key, value, SLOPPY); | 449 return StoreKeyedToSuper(isolate, home_object, receiver, key, value, SLOPPY); |
| 457 } | 450 } |
| 458 } | 451 } |
| 459 } // namespace v8::internal | 452 } // namespace v8::internal |
| OLD | NEW |