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

Side by Side Diff: src/v8natives.js

Issue 7475: - Specialized IsClassOf for Number, Boolean, Arguments, and Function. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 12 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
« src/runtime.cc ('K') | « src/runtime.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 285
286 SetupObject(); 286 SetupObject();
287 287
288 288
289 // ---------------------------------------------------------------------------- 289 // ----------------------------------------------------------------------------
290 // Boolean 290 // Boolean
291 291
292 function BooleanToString() { 292 function BooleanToString() {
293 // NOTE: Both Boolean objects and values can enter here as 293 // NOTE: Both Boolean objects and values can enter here as
294 // 'this'. This is not as dictated by ECMA-262. 294 // 'this'. This is not as dictated by ECMA-262.
295 if (!IS_BOOLEAN(this) && %ClassOf(this) !== 'Boolean') 295 if (!IS_BOOLEAN(this) && !%IsBooleanClass(this))
296 throw new $TypeError('Boolean.prototype.toString is not generic'); 296 throw new $TypeError('Boolean.prototype.toString is not generic');
297 return ToString(%_ValueOf(this)); 297 return ToString(%_ValueOf(this));
298 } 298 }
299 299
300 300
301 function BooleanValueOf() { 301 function BooleanValueOf() {
302 // NOTE: Both Boolean objects and values can enter here as 302 // NOTE: Both Boolean objects and values can enter here as
303 // 'this'. This is not as dictated by ECMA-262. 303 // 'this'. This is not as dictated by ECMA-262.
304 if (!IS_BOOLEAN(this) && %ClassOf(this) !== 'Boolean') 304 if (!IS_BOOLEAN(this) && !%IsBooleanClass(this))
305 throw new $TypeError('Boolean.prototype.valueOf is not generic'); 305 throw new $TypeError('Boolean.prototype.valueOf is not generic');
306 return %_ValueOf(this); 306 return %_ValueOf(this);
307 } 307 }
308 308
309 309
310 // ---------------------------------------------------------------------------- 310 // ----------------------------------------------------------------------------
311 311
312 312
313 function SetupBoolean() { 313 function SetupBoolean() {
314 InstallFunctions($Boolean.prototype, DONT_ENUM, $Array( 314 InstallFunctions($Boolean.prototype, DONT_ENUM, $Array(
(...skipping 18 matching lines...) Expand all
333 }); 333 });
334 334
335 %FunctionSetPrototype($Number, new $Number(0)); 335 %FunctionSetPrototype($Number, new $Number(0));
336 336
337 // ECMA-262 section 15.7.4.2. 337 // ECMA-262 section 15.7.4.2.
338 function NumberToString(radix) { 338 function NumberToString(radix) {
339 // NOTE: Both Number objects and values can enter here as 339 // NOTE: Both Number objects and values can enter here as
340 // 'this'. This is not as dictated by ECMA-262. 340 // 'this'. This is not as dictated by ECMA-262.
341 var number = this; 341 var number = this;
342 if (!IS_NUMBER(this)) { 342 if (!IS_NUMBER(this)) {
343 if (%ClassOf(this) !== 'Number') 343 if (!%IsNumberClass(this))
344 throw new $TypeError('Number.prototype.toString is not generic'); 344 throw new $TypeError('Number.prototype.toString is not generic');
345 // Get the value of this number in case it's an object. 345 // Get the value of this number in case it's an object.
346 number = %_ValueOf(this); 346 number = %_ValueOf(this);
347 } 347 }
348 // Fast case: Convert number in radix 10. 348 // Fast case: Convert number in radix 10.
349 if (IS_UNDEFINED(radix) || radix === 10) { 349 if (IS_UNDEFINED(radix) || radix === 10) {
350 return ToString(number); 350 return ToString(number);
351 } 351 }
352 352
353 // Convert the radix to an integer and check the range. 353 // Convert the radix to an integer and check the range.
354 radix = TO_INTEGER(radix); 354 radix = TO_INTEGER(radix);
355 if (radix < 2 || radix > 36) { 355 if (radix < 2 || radix > 36) {
356 throw new $RangeError('toString() radix argument must be between 2 and 36'); 356 throw new $RangeError('toString() radix argument must be between 2 and 36');
357 } 357 }
358 // Convert the number to a string in the given radix. 358 // Convert the number to a string in the given radix.
359 return %NumberToRadixString(number, radix); 359 return %NumberToRadixString(number, radix);
360 } 360 }
361 361
362 362
363 // ECMA-262 section 15.7.4.3 363 // ECMA-262 section 15.7.4.3
364 function NumberToLocaleString() { 364 function NumberToLocaleString() {
365 return this.toString(); 365 return this.toString();
366 } 366 }
367 367
368 368
369 // ECMA-262 section 15.7.4.4 369 // ECMA-262 section 15.7.4.4
370 function NumberValueOf() { 370 function NumberValueOf() {
371 // NOTE: Both Number objects and values can enter here as 371 // NOTE: Both Number objects and values can enter here as
372 // 'this'. This is not as dictated by ECMA-262. 372 // 'this'. This is not as dictated by ECMA-262.
373 if (!IS_NUMBER(this) && %ClassOf(this) !== 'Number') 373 if (!IS_NUMBER(this) && !%IsNumberClass(this))
374 throw new $TypeError('Number.prototype.valueOf is not generic'); 374 throw new $TypeError('Number.prototype.valueOf is not generic');
375 return %_ValueOf(this); 375 return %_ValueOf(this);
376 } 376 }
377 377
378 378
379 // ECMA-262 section 15.7.4.5 379 // ECMA-262 section 15.7.4.5
380 function NumberToFixed(fractionDigits) { 380 function NumberToFixed(fractionDigits) {
381 var f = TO_INTEGER(fractionDigits); 381 var f = TO_INTEGER(fractionDigits);
382 if (f < 0 || f > 20) { 382 if (f < 0 || f > 20) {
383 throw new $RangeError("toFixed() digits argument must be between 0 and 20"); 383 throw new $RangeError("toFixed() digits argument must be between 0 and 20");
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 459
460 460
461 // ---------------------------------------------------------------------------- 461 // ----------------------------------------------------------------------------
462 // Function 462 // Function
463 463
464 $Function.prototype.constructor = $Function; 464 $Function.prototype.constructor = $Function;
465 465
466 function FunctionSourceString(func) { 466 function FunctionSourceString(func) {
467 // NOTE: Both Function objects and values can enter here as 467 // NOTE: Both Function objects and values can enter here as
468 // 'func'. This is not as dictated by ECMA-262. 468 // 'func'. This is not as dictated by ECMA-262.
469 if (!IS_FUNCTION(func) && %ClassOf(func) != 'Function') 469 if (!IS_FUNCTION(func) && !%IsFunctionClass(func))
470 throw new $TypeError('Function.prototype.toString is not generic'); 470 throw new $TypeError('Function.prototype.toString is not generic');
471 471
472 var source = %FunctionGetSourceCode(func); 472 var source = %FunctionGetSourceCode(func);
473 if (!IS_STRING(source)) { 473 if (!IS_STRING(source)) {
474 var name = %FunctionGetName(func); 474 var name = %FunctionGetName(func);
475 if (name) { 475 if (name) {
476 // Mimic what KJS does. 476 // Mimic what KJS does.
477 return 'function ' + name + '() { [native code] }'; 477 return 'function ' + name + '() { [native code] }';
478 } else { 478 } else {
479 return 'function () { [native code] }'; 479 return 'function () { [native code] }';
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 // ---------------------------------------------------------------------------- 526 // ----------------------------------------------------------------------------
527 527
528 function SetupFunction() { 528 function SetupFunction() {
529 InstallFunctions($Function.prototype, DONT_ENUM, $Array( 529 InstallFunctions($Function.prototype, DONT_ENUM, $Array(
530 "toString", FunctionToString 530 "toString", FunctionToString
531 )); 531 ));
532 } 532 }
533 533
534 SetupFunction(); 534 SetupFunction();
535 535
OLDNEW
« src/runtime.cc ('K') | « src/runtime.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698