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

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

Issue 624013005: Classes: Add support for toString (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add type checks 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') | src/v8natives.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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 if (!start_position->IsSmi() || !end_position->IsSmi() ||
278 !Handle<Script>::cast(script)->HasValidSource()) {
279 return isolate->ThrowIllegalOperation();
280 }
281
282 Handle<String> source(String::cast(Handle<Script>::cast(script)->source()));
283 return *isolate->factory()->NewSubString(
284 source, Handle<Smi>::cast(start_position)->value(),
285 Handle<Smi>::cast(end_position)->value());
286 }
233 } 287 }
234 } // namespace v8::internal 288 } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime/runtime.h ('k') | src/v8natives.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698