Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Side by Side Diff: src/runtime/runtime-classes.cc

Issue 631433002: Classes runtime (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Remove kConstructorFunction Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/runtime/runtime.h ('k') | test/mjsunit/harmony/classes.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 RUNTIME_FUNCTION(Runtime_StoreToSuper_Sloppy) { 144 RUNTIME_FUNCTION(Runtime_StoreToSuper_Sloppy) {
145 HandleScope scope(isolate); 145 HandleScope scope(isolate);
146 DCHECK(args.length() == 4); 146 DCHECK(args.length() == 4);
147 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 0); 147 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 0);
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
155
156 RUNTIME_FUNCTION(Runtime_DefineClass) {
157 HandleScope scope(isolate);
158 DCHECK(args.length() == 3);
159 CONVERT_ARG_HANDLE_CHECKED(Object, name, 0);
160 CONVERT_ARG_HANDLE_CHECKED(Object, super_class, 1);
161 CONVERT_ARG_HANDLE_CHECKED(Object, constructor, 2);
162
163 Handle<Object> prototype_parent;
164 Handle<Object> constructor_parent;
165
166 if (super_class->IsTheHole()) {
167 prototype_parent = isolate->initial_object_prototype();
168 } else {
169 if (super_class->IsNull()) {
170 prototype_parent = isolate->factory()->null_value();
171 } else if (super_class->IsSpecFunction()) {
172 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
173 isolate, prototype_parent,
174 Runtime::GetObjectProperty(isolate, super_class,
175 isolate->factory()->prototype_string()));
176 if (!prototype_parent->IsNull() && !prototype_parent->IsSpecObject()) {
177 Handle<Object> args[1] = {prototype_parent};
178 THROW_NEW_ERROR_RETURN_FAILURE(
179 isolate, NewTypeError("prototype_parent_not_an_object",
180 HandleVector(args, 1)));
181 }
182 constructor_parent = super_class;
183 } else {
184 // TODO(arv): Should be IsConstructor.
185 Handle<Object> args[1] = {super_class};
186 THROW_NEW_ERROR_RETURN_FAILURE(
187 isolate,
188 NewTypeError("extends_value_not_a_function", HandleVector(args, 1)));
189 }
190 }
191
192 Handle<Map> map =
193 isolate->factory()->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
194 map->set_prototype(*prototype_parent);
195 Handle<JSObject> prototype = isolate->factory()->NewJSObjectFromMap(map);
196
197 Handle<String> name_string = name->IsString()
198 ? Handle<String>::cast(name)
199 : isolate->factory()->empty_string();
200
201 Handle<JSFunction> ctor;
202 if (constructor->IsSpecFunction()) {
203 ctor = Handle<JSFunction>::cast(constructor);
204 JSFunction::SetPrototype(ctor, prototype);
205 PropertyAttributes attribs =
206 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);
207 RETURN_FAILURE_ON_EXCEPTION(
208 isolate,
209 JSObject::SetOwnPropertyIgnoreAttributes(
210 ctor, isolate->factory()->prototype_string(), prototype, attribs));
211 } else {
212 // TODO(arv): This should not use an empty function but a function that
213 // calls super.
214 Handle<Code> code(isolate->builtins()->builtin(Builtins::kEmptyFunction));
215 ctor = isolate->factory()->NewFunction(name_string, code, prototype, true);
216 }
217
218 Handle<Symbol> home_object_symbol(isolate->heap()->home_object_symbol());
219 RETURN_FAILURE_ON_EXCEPTION(
220 isolate, JSObject::SetOwnPropertyIgnoreAttributes(
221 ctor, home_object_symbol, prototype, DONT_ENUM));
222
223 if (!constructor_parent.is_null()) {
224 RETURN_FAILURE_ON_EXCEPTION(
225 isolate, JSObject::SetPrototype(ctor, constructor_parent, false));
226 }
227
228 JSObject::AddProperty(prototype, isolate->factory()->constructor_string(),
229 ctor, DONT_ENUM);
230
231 return *ctor;
232 }
154 } 233 }
155 } // namespace v8::internal 234 } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime/runtime.h ('k') | test/mjsunit/harmony/classes.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698