Make the runtime entry for setting/changing accessors "atomic".
Previously, there were 1 or 2 calls to the runtime when accessors were changed
or set. This doesn't really work well with property attributes, leading to some
hacks and complicates things even further when trying to share maps in presence
of accessors. Therefore, the runtime entry now takes the full triple (getter,
setter, attributes), where the getter and/or the setter can be null in case they
shouldn't be changed.
For now, we do basically the same on the native side as we did before on the
JavaScript side, but this will change in future CLs, the current CL is already
large enough.
Note that object literals with a getter and a setter for the same property still
do 2 calls, but this is a little bit more tricky to fix and will be handled in a
separate CL.
Review URL: https://chromiumcodereview.appspot.com/9616016
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10956 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-03-07 13:24:44 +00:00
// Copyright 2012 the V8 project authors. All rights reserved.
2014-04-29 06:42:26 +00:00
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
2008-07-03 15:10:15 +00:00
// -------------------------------------------------------------------
2012-11-09 08:22:02 +00:00
var kMessages = {
// Error
cyclic _proto : [ "Cyclic __proto__ value" ] ,
code _gen _from _strings : [ "%0" ] ,
2013-04-24 13:00:16 +00:00
generator _running : [ "Generator is already running" ] ,
generator _finished : [ "Generator has already finished" ] ,
2012-11-09 08:22:02 +00:00
// TypeError
unexpected _token : [ "Unexpected token " , "%0" ] ,
unexpected _token _number : [ "Unexpected number" ] ,
unexpected _token _string : [ "Unexpected string" ] ,
unexpected _token _identifier : [ "Unexpected identifier" ] ,
unexpected _reserved : [ "Unexpected reserved word" ] ,
unexpected _strict _reserved : [ "Unexpected strict mode reserved word" ] ,
unexpected _eos : [ "Unexpected end of input" ] ,
malformed _regexp : [ "Invalid regular expression: /" , "%0" , "/: " , "%1" ] ,
unterminated _regexp : [ "Invalid regular expression: missing /" ] ,
regexp _flags : [ "Cannot supply flags when constructing one RegExp from another" ] ,
incompatible _method _receiver : [ "Method " , "%0" , " called on incompatible receiver " , "%1" ] ,
multiple _defaults _in _switch : [ "More than one default clause in switch statement" ] ,
newline _after _throw : [ "Illegal newline after throw" ] ,
2014-04-02 12:38:01 +00:00
label _redeclaration : [ "Label '" , "%0" , "' has already been declared" ] ,
var _redeclaration : [ "Identifier '" , "%0" , "' has already been declared" ] ,
2012-11-09 08:22:02 +00:00
no _catch _or _finally : [ "Missing catch or finally after try" ] ,
unknown _label : [ "Undefined label '" , "%0" , "'" ] ,
uncaught _exception : [ "Uncaught " , "%0" ] ,
stack _trace : [ "Stack Trace:\n" , "%0" ] ,
called _non _callable : [ "%0" , " is not a function" ] ,
undefined _method : [ "Object " , "%1" , " has no method '" , "%0" , "'" ] ,
property _not _function : [ "Property '" , "%0" , "' of object " , "%1" , " is not a function" ] ,
cannot _convert _to _primitive : [ "Cannot convert object to primitive value" ] ,
not _constructor : [ "%0" , " is not a constructor" ] ,
not _defined : [ "%0" , " is not defined" ] ,
non _object _property _load : [ "Cannot read property '" , "%0" , "' of " , "%1" ] ,
non _object _property _store : [ "Cannot set property '" , "%0" , "' of " , "%1" ] ,
with _expression : [ "%0" , " has no properties" ] ,
illegal _invocation : [ "Illegal invocation" ] ,
no _setter _in _callback : [ "Cannot set property " , "%0" , " of " , "%1" , " which has only a getter" ] ,
apply _non _function : [ "Function.prototype.apply was called on " , "%0" , ", which is a " , "%1" , " and not a function" ] ,
apply _wrong _args : [ "Function.prototype.apply: Arguments list has wrong type" ] ,
invalid _in _operator _use : [ "Cannot use 'in' operator to search for '" , "%0" , "' in " , "%1" ] ,
instanceof _function _expected : [ "Expecting a function in instanceof check, but got " , "%0" ] ,
instanceof _nonobject _proto : [ "Function has non-object prototype '" , "%0" , "' in instanceof check" ] ,
2013-07-05 08:34:31 +00:00
undefined _or _null _to _object : [ "Cannot convert undefined or null to object" ] ,
2012-11-09 08:22:02 +00:00
reduce _no _initial : [ "Reduce of empty array with no initial value" ] ,
getter _must _be _callable : [ "Getter must be a function: " , "%0" ] ,
setter _must _be _callable : [ "Setter must be a function: " , "%0" ] ,
value _and _accessor : [ "Invalid property. A property cannot both have accessors and be writable or have a value, " , "%0" ] ,
2014-01-22 12:15:57 +00:00
proto _object _or _null : [ "Object prototype may only be an Object or null: " , "%0" ] ,
2012-11-09 08:22:02 +00:00
property _desc _object : [ "Property description must be an object: " , "%0" ] ,
redefine _disallowed : [ "Cannot redefine property: " , "%0" ] ,
define _disallowed : [ "Cannot define property:" , "%0" , ", object is not extensible." ] ,
non _extensible _proto : [ "%0" , " is not extensible" ] ,
handler _non _object : [ "Proxy." , "%0" , " called with non-object as handler" ] ,
proto _non _object : [ "Proxy." , "%0" , " called with non-object as prototype" ] ,
trap _function _expected : [ "Proxy." , "%0" , " called with non-function for '" , "%1" , "' trap" ] ,
handler _trap _missing : [ "Proxy handler " , "%0" , " has no '" , "%1" , "' trap" ] ,
handler _trap _must _be _callable : [ "Proxy handler " , "%0" , " has non-callable '" , "%1" , "' trap" ] ,
handler _returned _false : [ "Proxy handler " , "%0" , " returned false from '" , "%1" , "' trap" ] ,
handler _returned _undefined : [ "Proxy handler " , "%0" , " returned undefined from '" , "%1" , "' trap" ] ,
proxy _prop _not _configurable : [ "Proxy handler " , "%0" , " returned non-configurable descriptor for property '" , "%2" , "' from '" , "%1" , "' trap" ] ,
proxy _non _object _prop _names : [ "Trap '" , "%1" , "' returned non-object " , "%0" ] ,
proxy _repeated _prop _name : [ "Trap '" , "%1" , "' returned repeated property name '" , "%2" , "'" ] ,
invalid _weakmap _key : [ "Invalid value used as weak map key" ] ,
2013-07-22 08:32:24 +00:00
invalid _weakset _value : [ "Invalid value used in weak set" ] ,
2012-11-09 08:22:02 +00:00
not _date _object : [ "this is not a Date object." ] ,
observe _non _object : [ "Object." , "%0" , " cannot " , "%0" , " non-object" ] ,
observe _non _function : [ "Object." , "%0" , " cannot deliver to non-function" ] ,
observe _callback _frozen : [ "Object.observe cannot deliver to a frozen function object" ] ,
2013-05-15 22:09:40 +00:00
observe _invalid _accept : [ "Object.observe accept must be an array of strings." ] ,
2012-11-09 16:14:42 +00:00
observe _type _non _string : [ "Invalid changeRecord with non-string 'type' property" ] ,
2013-05-15 22:09:40 +00:00
observe _perform _non _string : [ "Invalid non-string changeType" ] ,
observe _perform _non _function : [ "Cannot perform non-function" ] ,
2012-11-09 16:14:42 +00:00
observe _notify _non _notifier : [ "notify called on non-notifier object" ] ,
2013-05-03 09:59:50 +00:00
not _typed _array : [ "this is not a typed array." ] ,
2013-05-07 14:42:17 +00:00
invalid _argument : [ "invalid_argument" ] ,
2013-06-21 13:02:38 +00:00
data _view _not _array _buffer : [ "First argument to DataView constructor must be an ArrayBuffer" ] ,
2013-06-27 07:42:08 +00:00
constructor _not _function : [ "Constructor " , "%0" , " requires 'new'" ] ,
2014-03-20 16:13:09 +00:00
not _a _symbol : [ "%0" , " is not a symbol" ] ,
2014-01-09 13:00:56 +00:00
not _a _promise : [ "%0" , " is not a promise" ] ,
resolver _not _a _function : [ "Promise resolver " , "%0" , " is not a function" ] ,
promise _cyclic : [ "Chaining cycle detected for promise " , "%0" ] ,
2013-11-29 15:22:16 +00:00
array _functions _on _frozen : [ "Cannot modify frozen array elements" ] ,
array _functions _change _sealed : [ "Cannot add/remove sealed array elements" ] ,
2014-01-28 10:31:05 +00:00
first _argument _not _regexp : [ "First argument to " , "%0" , " must not be a regular expression" ] ,
2012-11-09 08:22:02 +00:00
// RangeError
invalid _array _length : [ "Invalid array length" ] ,
2013-03-28 12:50:18 +00:00
invalid _array _buffer _length : [ "Invalid array buffer length" ] ,
2014-01-31 12:21:17 +00:00
invalid _string _length : [ "Invalid string length" ] ,
2013-06-24 13:58:52 +00:00
invalid _typed _array _offset : [ "Start offset is too large:" ] ,
invalid _typed _array _length : [ "Invalid typed array length" ] ,
2014-02-14 09:33:03 +00:00
invalid _typed _array _alignment : [ "%0" , " of " , "%1" , " should be a multiple of " , "%2" ] ,
2013-05-07 14:42:17 +00:00
typed _array _set _source _too _large :
[ "Source is too large" ] ,
2013-06-24 13:58:52 +00:00
typed _array _set _negative _offset :
[ "Start offset is negative" ] ,
2013-06-21 13:02:38 +00:00
invalid _data _view _offset : [ "Start offset is outside the bounds of the buffer" ] ,
2013-06-24 13:58:52 +00:00
invalid _data _view _length : [ "Invalid data view length" ] ,
2013-06-21 13:02:38 +00:00
invalid _data _view _accessor _offset :
[ "Offset is outside the bounds of the DataView" ] ,
2012-11-09 08:22:02 +00:00
stack _overflow : [ "Maximum call stack size exceeded" ] ,
invalid _time _value : [ "Invalid time value" ] ,
2013-07-30 16:33:08 +00:00
invalid _count _value : [ "Invalid count value" ] ,
2014-03-17 10:21:01 +00:00
// ReferenceError
invalid _lhs _in _assignment : [ "Invalid left-hand side in assignment" ] ,
invalid _lhs _in _for : [ "Invalid left-hand side in for-loop" ] ,
invalid _lhs _in _postfix _op : [ "Invalid left-hand side expression in postfix operation" ] ,
invalid _lhs _in _prefix _op : [ "Invalid left-hand side expression in prefix operation" ] ,
2012-11-09 08:22:02 +00:00
// SyntaxError
2013-04-26 14:26:54 +00:00
paren _in _arg _string : [ "Function arg string contains parenthesis" ] ,
not _isvar : [ "builtin %IS_VAR: not a variable" ] ,
single _function _literal : [ "Single function literal required" ] ,
2012-11-09 08:22:02 +00:00
invalid _regexp _flags : [ "Invalid flags supplied to RegExp constructor '" , "%0" , "'" ] ,
invalid _regexp : [ "Invalid RegExp pattern /" , "%0" , "/" ] ,
illegal _break : [ "Illegal break statement" ] ,
illegal _continue : [ "Illegal continue statement" ] ,
illegal _return : [ "Illegal return statement" ] ,
illegal _let : [ "Illegal let declaration outside extended mode" ] ,
error _loading _debugger : [ "Error loading debugger" ] ,
no _input _to _regexp : [ "No input to " , "%0" ] ,
invalid _json : [ "String '" , "%0" , "' is not valid JSON" ] ,
circular _structure : [ "Converting circular structure to JSON" ] ,
called _on _non _object : [ "%0" , " called on non-object" ] ,
called _on _null _or _undefined : [ "%0" , " called on null or undefined" ] ,
array _indexof _not _defined : [ "Array.getIndexOf: Argument undefined" ] ,
object _not _extensible : [ "Can't add property " , "%0" , ", object is not extensible" ] ,
illegal _access : [ "Illegal access" ] ,
2014-04-14 07:35:46 +00:00
invalid _cached _data _function : [ "Invalid cached data for function " , "%0" ] ,
invalid _cached _data : [ "Invalid cached data" ] ,
2012-11-09 08:22:02 +00:00
strict _mode _with : [ "Strict mode code may not include a with statement" ] ,
2014-02-05 16:26:48 +00:00
strict _eval _arguments : [ "Unexpected eval or arguments in strict mode" ] ,
2014-03-11 16:30:47 +00:00
too _many _arguments : [ "Too many arguments in function call (only 65535 allowed)" ] ,
too _many _parameters : [ "Too many parameters in function definition (only 65535 allowed)" ] ,
2014-03-20 13:37:26 +00:00
too _many _variables : [ "Too many variables declared (only 4194303 allowed)" ] ,
2012-11-09 08:22:02 +00:00
strict _param _dupe : [ "Strict mode function may not have duplicate parameter names" ] ,
strict _octal _literal : [ "Octal literals are not allowed in strict mode." ] ,
strict _duplicate _property : [ "Duplicate data property in object literal not allowed in strict mode" ] ,
accessor _data _property : [ "Object literal may not have data and accessor property with the same name" ] ,
accessor _get _set : [ "Object literal may not have multiple get/set accessors with the same name" ] ,
strict _delete : [ "Delete of an unqualified identifier in strict mode." ] ,
strict _delete _property : [ "Cannot delete property '" , "%0" , "' of " , "%1" ] ,
strict _const : [ "Use of const in strict mode." ] ,
strict _function : [ "In strict mode code, functions can only be declared at top level or immediately within another function." ] ,
strict _read _only _property : [ "Cannot assign to read only property '" , "%0" , "' of " , "%1" ] ,
strict _cannot _assign : [ "Cannot assign to read only '" , "%0" , "' in strict mode" ] ,
strict _poison _pill : [ "'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them" ] ,
strict _caller : [ "Illegal access to a strict mode caller function." ] ,
unprotected _let : [ "Illegal let declaration in unprotected statement context." ] ,
unprotected _const : [ "Illegal const declaration in unprotected statement context." ] ,
cant _prevent _ext _external _array _elements : [ "Cannot prevent extension of an object with external array elements" ] ,
redef _external _array _element : [ "Cannot redefine a property of an object with external array elements" ] ,
harmony _const _assign : [ "Assignment to constant variable." ] ,
Upgrade Symbol implementation to match current ES6 behavior.
Refresh the implementation of Symbols to catch up with what the
specification now mandates:
* The global Symbol() function manufactures new Symbol values,
optionally with a string description attached.
* Invoking Symbol() as a constructor will now throw.
* ToString() over Symbol values still throws, and
Object.prototype.toString() stringifies like before.
* A Symbol value is wrapped in a Symbol object either implicitly if
it is the receiver, or explicitly done via Object(symbolValue) or
(new Object(symbolValue).)
* The Symbol.prototype.toString() method no longer throws on Symbol
wrapper objects (nor Symbol values.) Ditto for Symbol.prototype.valueOf().
* Symbol.prototype.toString() stringifies as "Symbol("<description>"),
valueOf() returns the wrapper's Symbol value.
* ToPrimitive() over Symbol wrapper objects now throws.
Overall, this provides a stricter separation between Symbol values and
wrapper objects than before, and the explicit fetching out of the
description (nee name) via the "name" property is no longer supported
(by the spec nor the implementation.)
Adjusted existing Symbol test files to fit current, adding some extra
tests for new/changed behavior.
LOG=N
R=arv@chromium.org, rossberg@chromium.org, arv, rossberg
BUG=v8:3053
Review URL: https://codereview.chromium.org/118553003
Patch from Sigbjorn Finne <sigbjornf@opera.com>.
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19490 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-02-19 14:19:42 +00:00
symbol _to _string : [ "Cannot convert a Symbol value to a string" ] ,
symbol _to _primitive : [ "Cannot convert a Symbol wrapper object to a primitive value" ] ,
2012-11-09 08:22:02 +00:00
invalid _module _path : [ "Module does not export '" , "%0" , "', or export is not itself a module" ] ,
module _type _error : [ "Module '" , "%0" , "' used improperly" ] ,
2013-04-24 13:00:16 +00:00
module _export _undefined : [ "Export '" , "%0" , "' is not defined in module" ]
2012-11-09 08:22:02 +00:00
} ;
function FormatString ( format , args ) {
2011-02-01 12:31:16 +00:00
var result = "" ;
var arg _num = 0 ;
for ( var i = 0 ; i < format . length ; i ++ ) {
var str = format [ i ] ;
2011-09-01 07:39:22 +00:00
if ( str . length == 2 && % _StringCharCodeAt ( str , 0 ) == 0x25 ) {
// Two-char string starts with "%".
var arg _num = ( % _StringCharCodeAt ( str , 1 ) - 0x30 ) >>> 0 ;
if ( arg _num < 4 ) {
// str is one of %0, %1, %2 or %3.
2011-08-22 12:54:03 +00:00
try {
2012-11-12 10:33:20 +00:00
str = NoSideEffectToString ( args [ arg _num ] ) ;
2013-11-28 08:59:45 +00:00
if ( str . length > 256 ) {
2014-04-02 08:21:37 +00:00
str = % _SubString ( str , 0 , 239 ) + "...<omitted>..." +
% _SubString ( str , str . length - 2 , str . length ) ;
2013-11-28 08:59:45 +00:00
}
2011-08-22 12:54:03 +00:00
} catch ( e ) {
2012-07-09 08:59:03 +00:00
if ( % IsJSModule ( args [ arg _num ] ) )
str = "module" ;
else if ( IS _SPEC _OBJECT ( args [ arg _num ] ) )
str = "object" ;
else
str = "#<error>" ;
2011-08-22 12:54:03 +00:00
}
2011-02-01 12:31:16 +00:00
}
2011-01-26 15:16:13 +00:00
}
2011-02-01 12:31:16 +00:00
result += str ;
2008-07-03 15:10:15 +00:00
}
return result ;
2008-10-03 07:14:31 +00:00
}
2008-07-03 15:10:15 +00:00
2012-11-12 10:33:20 +00:00
function NoSideEffectToString ( obj ) {
if ( IS _STRING ( obj ) ) return obj ;
if ( IS _NUMBER ( obj ) ) return % _NumberToString ( obj ) ;
if ( IS _BOOLEAN ( obj ) ) return x ? 'true' : 'false' ;
if ( IS _UNDEFINED ( obj ) ) return 'undefined' ;
if ( IS _NULL ( obj ) ) return 'null' ;
2012-11-13 09:01:43 +00:00
if ( IS _FUNCTION ( obj ) ) return % _CallFunction ( obj , FunctionToString ) ;
2012-11-12 10:33:20 +00:00
if ( IS _OBJECT ( obj ) && % GetDataProperty ( obj , "toString" ) === ObjectToString ) {
2012-12-17 14:00:50 +00:00
var constructor = % GetDataProperty ( obj , "constructor" ) ;
2012-11-12 10:33:20 +00:00
if ( typeof constructor == "function" ) {
var constructorName = constructor . name ;
if ( IS _STRING ( constructorName ) && constructorName !== "" ) {
return "#<" + constructorName + ">" ;
}
}
}
2013-08-06 13:58:21 +00:00
if ( CanBeSafelyTreatedAsAnErrorObject ( obj ) ) {
return % _CallFunction ( obj , ErrorToString ) ;
}
2012-11-12 10:33:20 +00:00
return % _CallFunction ( obj , ObjectToString ) ;
}
2013-08-06 13:58:21 +00:00
// To determine whether we can safely stringify an object using ErrorToString
// without the risk of side-effects, we need to check whether the object is
// either an instance of a native error type (via '%_ClassOf'), or has $Error
// in its prototype chain and hasn't overwritten 'toString' with something
// strange and unusual.
function CanBeSafelyTreatedAsAnErrorObject ( obj ) {
2012-05-18 09:45:10 +00:00
switch ( % _ClassOf ( obj ) ) {
case 'Error' :
case 'EvalError' :
case 'RangeError' :
case 'ReferenceError' :
case 'SyntaxError' :
case 'TypeError' :
case 'URIError' :
return true ;
}
2013-08-06 13:58:21 +00:00
var objToString = % GetDataProperty ( obj , "toString" ) ;
return obj instanceof $Error && objToString === ErrorToString ;
2011-01-25 08:48:59 +00:00
}
2011-01-24 07:59:40 +00:00
// When formatting internally created error messages, do not
// invoke overwritten error toString methods but explicitly use
// the error to string method. This is to avoid leaking error
// objects between script tags in a browser setting.
function ToStringCheckErrorObject ( obj ) {
2013-08-06 13:58:21 +00:00
if ( CanBeSafelyTreatedAsAnErrorObject ( obj ) ) {
2011-10-26 10:41:52 +00:00
return % _CallFunction ( obj , ErrorToString ) ;
2011-01-24 07:59:40 +00:00
} else {
return ToString ( obj ) ;
}
}
2008-07-03 15:10:15 +00:00
function ToDetailString ( obj ) {
2011-09-01 07:39:22 +00:00
if ( obj != null && IS _OBJECT ( obj ) && obj . toString === ObjectToString ) {
2008-07-03 15:10:15 +00:00
var constructor = obj . constructor ;
2011-09-01 07:39:22 +00:00
if ( typeof constructor == "function" ) {
var constructorName = constructor . name ;
if ( IS _STRING ( constructorName ) && constructorName !== "" ) {
return "#<" + constructorName + ">" ;
}
2011-01-26 15:16:13 +00:00
}
2008-07-03 15:10:15 +00:00
}
2011-09-01 07:39:22 +00:00
return ToStringCheckErrorObject ( obj ) ;
2008-10-03 07:14:31 +00:00
}
2008-07-03 15:10:15 +00:00
function MakeGenericError ( constructor , type , args ) {
2012-11-14 09:14:47 +00:00
if ( IS _UNDEFINED ( args ) ) args = [ ] ;
return new constructor ( FormatMessage ( type , args ) ) ;
2008-10-03 07:14:31 +00:00
}
2008-07-03 15:10:15 +00:00
/ * *
2011-09-05 07:30:35 +00:00
* Set up the Script function and constructor .
2008-07-03 15:10:15 +00:00
* /
% FunctionSetInstanceClassName ( Script , 'Script' ) ;
2011-09-05 07:30:35 +00:00
% SetProperty ( Script . prototype , 'constructor' , Script ,
DONT _ENUM | DONT _DELETE | READ _ONLY ) ;
2008-07-03 15:10:15 +00:00
% SetCode ( Script , function ( x ) {
// Script objects can only be created by the VM.
throw new $Error ( "Not supported" ) ;
} ) ;
// Helper functions; called from the runtime system.
2012-11-09 08:22:02 +00:00
function FormatMessage ( type , args ) {
var format = kMessages [ type ] ;
if ( ! format ) return "<unknown message " + type + ">" ;
return FormatString ( format , args ) ;
2008-10-03 07:14:31 +00:00
}
2008-07-03 15:10:15 +00:00
function GetLineNumber ( message ) {
2011-02-02 13:31:52 +00:00
var start _position = % MessageGetStartPosition ( message ) ;
if ( start _position == - 1 ) return kNoLineNumberInfo ;
var script = % MessageGetScript ( message ) ;
var location = script . locationFromPosition ( start _position , true ) ;
2010-05-06 07:32:44 +00:00
if ( location == null ) return kNoLineNumberInfo ;
2008-07-03 15:10:15 +00:00
return location . line + 1 ;
2008-10-03 07:14:31 +00:00
}
2008-07-03 15:10:15 +00:00
// Returns the source code line containing the given source
// position, or the empty string if the position is invalid.
function GetSourceLine ( message ) {
2011-02-02 13:31:52 +00:00
var script = % MessageGetScript ( message ) ;
var start _position = % MessageGetStartPosition ( message ) ;
var location = script . locationFromPosition ( start _position , true ) ;
2008-07-03 15:10:15 +00:00
if ( location == null ) return "" ;
location . restrict ( ) ;
return location . sourceText ( ) ;
2008-10-03 07:14:31 +00:00
}
2008-07-03 15:10:15 +00:00
function MakeTypeError ( type , args ) {
return MakeGenericError ( $TypeError , type , args ) ;
2008-10-03 07:14:31 +00:00
}
2008-07-03 15:10:15 +00:00
function MakeRangeError ( type , args ) {
return MakeGenericError ( $RangeError , type , args ) ;
2008-10-03 07:14:31 +00:00
}
2008-07-03 15:10:15 +00:00
function MakeSyntaxError ( type , args ) {
return MakeGenericError ( $SyntaxError , type , args ) ;
2008-10-03 07:14:31 +00:00
}
2008-07-03 15:10:15 +00:00
function MakeReferenceError ( type , args ) {
return MakeGenericError ( $ReferenceError , type , args ) ;
2008-10-03 07:14:31 +00:00
}
2008-07-03 15:10:15 +00:00
function MakeEvalError ( type , args ) {
return MakeGenericError ( $EvalError , type , args ) ;
2008-10-03 07:14:31 +00:00
}
2008-07-03 15:10:15 +00:00
function MakeError ( type , args ) {
return MakeGenericError ( $Error , type , args ) ;
2008-10-03 07:14:31 +00:00
}
2008-07-03 15:10:15 +00:00
2009-06-09 07:03:21 +00:00
/ * *
* Find a line number given a specific source position .
* @ param { number } position The source position .
* @ return { number } 0 if input too small , - 1 if input too large ,
else the line number .
* /
2011-09-05 07:30:35 +00:00
function ScriptLineFromPosition ( position ) {
2009-06-09 07:03:21 +00:00
var lower = 0 ;
var upper = this . lineCount ( ) - 1 ;
2009-11-27 14:10:48 +00:00
var line _ends = this . line _ends ;
2009-06-09 07:03:21 +00:00
// We'll never find invalid positions so bail right away.
2009-11-27 14:10:48 +00:00
if ( position > line _ends [ upper ] ) {
2009-06-09 07:03:21 +00:00
return - 1 ;
}
// This means we don't have to safe-guard indexing line_ends[i - 1].
2009-11-27 14:10:48 +00:00
if ( position <= line _ends [ 0 ] ) {
2009-06-09 07:03:21 +00:00
return 0 ;
}
// Binary search to find line # from position range.
while ( upper >= 1 ) {
var i = ( lower + upper ) >> 1 ;
2009-11-27 14:10:48 +00:00
if ( position > line _ends [ i ] ) {
2009-06-09 07:03:21 +00:00
lower = i + 1 ;
2009-11-27 14:10:48 +00:00
} else if ( position <= line _ends [ i - 1 ] ) {
2009-06-09 07:03:21 +00:00
upper = i - 1 ;
} else {
return i ;
}
}
2011-02-08 07:49:59 +00:00
2009-06-09 07:03:21 +00:00
return - 1 ;
}
2008-07-03 15:10:15 +00:00
/ * *
* Get information on a specific source position .
* @ param { number } position The source position
2009-03-09 17:59:25 +00:00
* @ param { boolean } include _resource _offset Set to true to have the resource
* offset added to the location
2008-07-03 15:10:15 +00:00
* @ return { SourceLocation }
* If line is negative or not in the source null is returned .
* /
2011-09-05 07:30:35 +00:00
function ScriptLocationFromPosition ( position ,
include _resource _offset ) {
2009-06-09 07:03:21 +00:00
var line = this . lineFromPosition ( position ) ;
2008-07-03 15:10:15 +00:00
if ( line == - 1 ) return null ;
2008-08-22 13:33:59 +00:00
2008-07-03 15:10:15 +00:00
// Determine start, end and column.
2009-11-27 14:10:48 +00:00
var line _ends = this . line _ends ;
var start = line == 0 ? 0 : line _ends [ line - 1 ] + 1 ;
var end = line _ends [ line ] ;
2011-09-05 07:30:35 +00:00
if ( end > 0 && % _CallFunction ( this . source , end - 1 , StringCharAt ) == '\r' ) {
end -- ;
}
2008-07-03 15:10:15 +00:00
var column = position - start ;
// Adjust according to the offset within the resource.
2009-03-09 17:59:25 +00:00
if ( include _resource _offset ) {
line += this . line _offset ;
if ( line == this . line _offset ) {
column += this . column _offset ;
}
2008-07-03 15:10:15 +00:00
}
return new SourceLocation ( this , position , line , column , start , end ) ;
2011-11-28 12:11:00 +00:00
}
2008-07-03 15:10:15 +00:00
/ * *
* Get information on a specific source line and column possibly offset by a
* fixed source position . This function is used to find a source position from
* a line and column position . The fixed source position offset is typically
* used to find a source position in a function based on a line and column in
* the source for the function alone . The offset passed will then be the
* start position of the source for the function within the full script source .
* @ param { number } opt _line The line within the source . Default value is 0
* @ param { number } opt _column The column in within the line . Default value is 0
* @ param { number } opt _offset _position The offset from the begining of the
2011-09-05 07:30:35 +00:00
* source from where the line and column calculation starts .
* Default value is 0
2008-07-03 15:10:15 +00:00
* @ return { SourceLocation }
* If line is negative or not in the source null is returned .
* /
2011-09-05 07:30:35 +00:00
function ScriptLocationFromLine ( opt _line , opt _column , opt _offset _position ) {
2008-07-03 15:10:15 +00:00
// Default is the first line in the script. Lines in the script is relative
// to the offset within the resource.
var line = 0 ;
if ( ! IS _UNDEFINED ( opt _line ) ) {
line = opt _line - this . line _offset ;
}
2008-08-22 13:33:59 +00:00
2008-07-03 15:10:15 +00:00
// Default is first column. If on the first line add the offset within the
// resource.
var column = opt _column || 0 ;
if ( line == 0 ) {
2011-11-28 12:11:00 +00:00
column -= this . column _offset ;
2008-07-03 15:10:15 +00:00
}
var offset _position = opt _offset _position || 0 ;
if ( line < 0 || column < 0 || offset _position < 0 ) return null ;
if ( line == 0 ) {
2009-03-12 14:03:05 +00:00
return this . locationFromPosition ( offset _position + column , false ) ;
2008-07-03 15:10:15 +00:00
} else {
2009-06-09 07:03:21 +00:00
// Find the line where the offset position is located.
var offset _line = this . lineFromPosition ( offset _position ) ;
if ( offset _line == - 1 || offset _line + line >= this . lineCount ( ) ) {
return null ;
2008-07-03 15:10:15 +00:00
}
2009-06-09 07:03:21 +00:00
2011-11-28 12:11:00 +00:00
return this . locationFromPosition (
this . line _ends [ offset _line + line - 1 ] + 1 + column ) ; // line > 0 here.
2008-07-03 15:10:15 +00:00
}
}
/ * *
* Get a slice of source code from the script . The boundaries for the slice is
* specified in lines .
* @ param { number } opt _from _line The first line ( zero bound ) in the slice .
* Default is 0
* @ param { number } opt _to _column The last line ( zero bound ) in the slice ( non
* inclusive ) . Default is the number of lines in the script
* @ return { SourceSlice } The source slice or null of the parameters where
* invalid
* /
2011-09-05 07:30:35 +00:00
function ScriptSourceSlice ( opt _from _line , opt _to _line ) {
2011-11-28 12:11:00 +00:00
var from _line = IS _UNDEFINED ( opt _from _line ) ? this . line _offset
: opt _from _line ;
var to _line = IS _UNDEFINED ( opt _to _line ) ? this . line _offset + this . lineCount ( )
: opt _to _line ;
2008-07-03 15:10:15 +00:00
// Adjust according to the offset within the resource.
from _line -= this . line _offset ;
to _line -= this . line _offset ;
if ( from _line < 0 ) from _line = 0 ;
if ( to _line > this . lineCount ( ) ) to _line = this . lineCount ( ) ;
2009-02-04 12:07:45 +00:00
// Check parameters.
2008-07-03 15:10:15 +00:00
if ( from _line >= this . lineCount ( ) ||
to _line < 0 ||
from _line > to _line ) {
return null ;
}
2009-11-27 14:10:48 +00:00
var line _ends = this . line _ends ;
var from _position = from _line == 0 ? 0 : line _ends [ from _line - 1 ] + 1 ;
var to _position = to _line == 0 ? 0 : line _ends [ to _line - 1 ] + 1 ;
2008-07-03 15:10:15 +00:00
// Return a source slice with line numbers re-adjusted to the resource.
2011-11-28 12:11:00 +00:00
return new SourceSlice ( this ,
from _line + this . line _offset ,
to _line + this . line _offset ,
from _position , to _position ) ;
2008-07-03 15:10:15 +00:00
}
2011-09-05 07:30:35 +00:00
function ScriptSourceLine ( opt _line ) {
2008-07-03 15:10:15 +00:00
// Default is the first line in the script. Lines in the script are relative
// to the offset within the resource.
var line = 0 ;
if ( ! IS _UNDEFINED ( opt _line ) ) {
line = opt _line - this . line _offset ;
}
2009-02-04 12:07:45 +00:00
// Check parameter.
2008-07-03 15:10:15 +00:00
if ( line < 0 || this . lineCount ( ) <= line ) {
return null ;
}
2009-02-04 12:07:45 +00:00
// Return the source line.
2009-11-27 14:10:48 +00:00
var line _ends = this . line _ends ;
var start = line == 0 ? 0 : line _ends [ line - 1 ] + 1 ;
var end = line _ends [ line ] ;
2011-01-28 10:33:10 +00:00
return % _CallFunction ( this . source , start , end , StringSubstring ) ;
2008-07-03 15:10:15 +00:00
}
/ * *
* Returns the number of source lines .
* @ return { number }
* Number of source lines .
* /
2011-09-05 07:30:35 +00:00
function ScriptLineCount ( ) {
2009-02-04 12:07:45 +00:00
// Return number of source lines.
return this . line _ends . length ;
2011-11-28 12:11:00 +00:00
}
2008-07-03 15:10:15 +00:00
2010-04-01 16:25:07 +00:00
/ * *
2012-09-21 08:09:34 +00:00
* If sourceURL comment is available and script starts at zero returns sourceURL
* comment contents . Otherwise , script name is returned . See
2010-04-01 16:25:07 +00:00
* http : //fbug.googlecode.com/svn/branches/firebug1.1/docs/ReleaseNotes_1.1.txt
2013-05-29 12:40:21 +00:00
* and Source Map Revision 3 proposal for details on using //# sourceURL and
* deprecated //@ sourceURL comment to identify scripts that don't have name.
2010-10-15 13:03:59 +00:00
*
2013-05-29 12:40:21 +00:00
* @ return { ? string } script name if present , value for //# sourceURL or
* deprecated //@ sourceURL comment otherwise.
2010-04-01 16:25:07 +00:00
* /
2011-09-05 07:30:35 +00:00
function ScriptNameOrSourceURL ( ) {
2012-09-21 08:09:34 +00:00
if ( this . line _offset > 0 || this . column _offset > 0 ) {
2010-04-01 16:25:07 +00:00
return this . name ;
2011-09-05 07:30:35 +00:00
}
2012-03-02 12:27:15 +00:00
// The result is cached as on long scripts it takes noticable time to search
// for the sourceURL.
2012-09-21 08:09:34 +00:00
if ( this . hasCachedNameOrSourceURL ) {
return this . cachedNameOrSourceURL ;
}
2012-03-02 12:27:15 +00:00
this . hasCachedNameOrSourceURL = true ;
2010-10-15 13:03:59 +00:00
// TODO(608): the spaces in a regexp below had to be escaped as \040
2010-04-01 16:25:07 +00:00
// because this file is being processed by js2c whose handling of spaces
// in regexps is broken. Also, ['"] are excluded from allowed URLs to
// avoid matches against sources that invoke evals with sourceURL.
2011-03-18 13:40:48 +00:00
// A better solution would be to detect these special comments in
// the scanner/parser.
var source = ToString ( this . source ) ;
var sourceUrlPos = % StringIndexOf ( source , "sourceURL=" , 0 ) ;
2012-03-02 12:27:15 +00:00
this . cachedNameOrSourceURL = this . name ;
2011-03-18 13:40:48 +00:00
if ( sourceUrlPos > 4 ) {
var sourceUrlPattern =
2013-05-29 12:40:21 +00:00
/\/\/[#@][\040\t]sourceURL=[\040\t]*([^\s\'\"]*)[\040\t]*$/gm ;
2011-03-18 13:40:48 +00:00
// Don't reuse lastMatchInfo here, so we create a new array with room
// for four captures (array with length one longer than the index
// of the fourth capture, where the numbering is zero-based).
2013-02-15 16:21:03 +00:00
var matchInfo = new InternalArray ( CAPTURE ( 3 ) + 1 ) ;
2011-03-18 13:40:48 +00:00
var match =
% _RegExpExec ( sourceUrlPattern , source , sourceUrlPos - 4 , matchInfo ) ;
if ( match ) {
2012-03-02 12:27:15 +00:00
this . cachedNameOrSourceURL =
2013-02-20 14:29:40 +00:00
% _SubString ( source , matchInfo [ CAPTURE ( 2 ) ] , matchInfo [ CAPTURE ( 3 ) ] ) ;
2011-03-18 13:40:48 +00:00
}
}
2012-03-02 12:27:15 +00:00
return this . cachedNameOrSourceURL ;
2010-04-01 16:25:07 +00:00
}
2011-09-05 07:30:35 +00:00
SetUpLockedPrototype ( Script ,
2012-03-02 12:27:15 +00:00
$Array ( "source" , "name" , "line_ends" , "line_offset" , "column_offset" ,
"cachedNameOrSourceURL" , "hasCachedNameOrSourceURL" ) ,
2011-09-05 07:30:35 +00:00
$Array (
"lineFromPosition" , ScriptLineFromPosition ,
"locationFromPosition" , ScriptLocationFromPosition ,
"locationFromLine" , ScriptLocationFromLine ,
"sourceSlice" , ScriptSourceSlice ,
"sourceLine" , ScriptSourceLine ,
"lineCount" , ScriptLineCount ,
"nameOrSourceURL" , ScriptNameOrSourceURL
)
) ;
2008-07-03 15:10:15 +00:00
/ * *
* Class for source location . A source location is a position within some
* source with the following properties :
* script : script object for the source
* line : source line number
* column : source column within the line
* position : position within the source
* start : position of start of source context ( inclusive )
* end : position of end of source context ( not inclusive )
2011-11-28 12:11:00 +00:00
* Source text for the source context is the character interval
* [ start , end [ . In most cases end will point to a newline character .
* It might point just past the final position of the source if the last
* source line does not end with a newline character .
2008-07-03 15:10:15 +00:00
* @ param { Script } script The Script object for which this is a location
* @ param { number } position Source position for the location
* @ param { number } line The line number for the location
* @ param { number } column The column within the line for the location
* @ param { number } start Source position for start of source context
* @ param { number } end Source position for end of source context
* @ constructor
* /
function SourceLocation ( script , position , line , column , start , end ) {
this . script = script ;
this . position = position ;
this . line = line ;
this . column = column ;
this . start = start ;
this . end = end ;
2008-10-03 07:14:31 +00:00
}
2008-07-03 15:10:15 +00:00
2012-02-20 13:48:24 +00:00
var kLineLengthLimit = 78 ;
2008-07-03 15:10:15 +00:00
/ * *
* Restrict source location start and end positions to make the source slice
* no more that a certain number of characters wide .
* @ param { number } opt _limit The with limit of the source text with a default
* of 78
* @ param { number } opt _before The number of characters to prefer before the
* position with a default value of 10 less that the limit
* /
2011-09-05 07:30:35 +00:00
function SourceLocationRestrict ( opt _limit , opt _before ) {
2008-07-03 15:10:15 +00:00
// Find the actual limit to use.
var limit ;
var before ;
if ( ! IS _UNDEFINED ( opt _limit ) ) {
limit = opt _limit ;
} else {
limit = kLineLengthLimit ;
}
if ( ! IS _UNDEFINED ( opt _before ) ) {
before = opt _before ;
} else {
// If no before is specified center for small limits and perfer more source
// before the the position that after for longer limits.
if ( limit <= 20 ) {
2008-10-03 07:14:31 +00:00
before = $floor ( limit / 2 ) ;
2008-07-03 15:10:15 +00:00
} else {
before = limit - 10 ;
}
}
if ( before >= limit ) {
before = limit - 1 ;
}
// If the [start, end[ interval is too big we restrict
// it in one or both ends. We make sure to always produce
// restricted intervals of maximum allowed size.
if ( this . end - this . start > limit ) {
var start _limit = this . position - before ;
var end _limit = this . position + limit - before ;
if ( this . start < start _limit && end _limit < this . end ) {
this . start = start _limit ;
this . end = end _limit ;
} else if ( this . start < start _limit ) {
this . start = this . end - limit ;
} else {
this . end = this . start + limit ;
}
}
2011-11-28 12:11:00 +00:00
}
2008-07-03 15:10:15 +00:00
/ * *
* Get the source text for a SourceLocation
* @ return { String }
* Source text for this location .
* /
2011-09-05 07:30:35 +00:00
function SourceLocationSourceText ( ) {
2011-11-28 12:11:00 +00:00
return % _CallFunction ( this . script . source ,
this . start ,
this . end ,
StringSubstring ) ;
}
2008-07-03 15:10:15 +00:00
2011-09-05 07:30:35 +00:00
SetUpLockedPrototype ( SourceLocation ,
$Array ( "script" , "position" , "line" , "column" , "start" , "end" ) ,
$Array (
"restrict" , SourceLocationRestrict ,
"sourceText" , SourceLocationSourceText
2011-11-28 12:11:00 +00:00
)
2011-09-05 07:30:35 +00:00
) ;
2008-07-03 15:10:15 +00:00
/ * *
* Class for a source slice . A source slice is a part of a script source with
* the following properties :
* script : script object for the source
* from _line : line number for the first line in the slice
* to _line : source line number for the last line in the slice
* from _position : position of the first character in the slice
* to _position : position of the last character in the slice
* The to _line and to _position are not included in the slice , that is the lines
* in the slice are [ from _line , to _line [ . Likewise the characters in the slice
* are [ from _position , to _position [ .
* @ param { Script } script The Script object for the source slice
* @ param { number } from _line
* @ param { number } to _line
* @ param { number } from _position
* @ param { number } to _position
* @ constructor
* /
function SourceSlice ( script , from _line , to _line , from _position , to _position ) {
this . script = script ;
this . from _line = from _line ;
this . to _line = to _line ;
this . from _position = from _position ;
this . to _position = to _position ;
}
/ * *
* Get the source text for a SourceSlice
* @ return { String } Source text for this slice . The last line will include
* the line terminating characters ( if any )
* /
2011-09-05 07:30:35 +00:00
function SourceSliceSourceText ( ) {
2011-01-28 10:33:10 +00:00
return % _CallFunction ( this . script . source ,
this . from _position ,
this . to _position ,
StringSubstring ) ;
2011-11-28 12:11:00 +00:00
}
2008-07-03 15:10:15 +00:00
2011-09-05 07:30:35 +00:00
SetUpLockedPrototype ( SourceSlice ,
$Array ( "script" , "from_line" , "to_line" , "from_position" , "to_position" ) ,
$Array ( "sourceText" , SourceSliceSourceText )
) ;
2008-07-03 15:10:15 +00:00
// Returns the offset of the given position within the containing
// line.
function GetPositionInLine ( message ) {
2011-02-02 13:31:52 +00:00
var script = % MessageGetScript ( message ) ;
var start _position = % MessageGetStartPosition ( message ) ;
var location = script . locationFromPosition ( start _position , false ) ;
2008-07-03 15:10:15 +00:00
if ( location == null ) return - 1 ;
location . restrict ( ) ;
2011-02-02 13:31:52 +00:00
return start _position - location . start ;
2008-10-03 07:14:31 +00:00
}
2008-07-03 15:10:15 +00:00
function GetStackTraceLine ( recv , fun , pos , isGlobal ) {
2013-03-28 10:40:07 +00:00
return new CallSite ( recv , fun , pos , false ) . toString ( ) ;
2008-10-03 07:14:31 +00:00
}
2008-07-03 15:10:15 +00:00
// ----------------------------------------------------------------------------
// Error implementation
2014-03-24 16:34:06 +00:00
var CallSiteReceiverKey = NEW _PRIVATE ( "CallSite#receiver" ) ;
var CallSiteFunctionKey = NEW _PRIVATE ( "CallSite#function" ) ;
var CallSitePositionKey = NEW _PRIVATE ( "CallSite#position" ) ;
var CallSiteStrictModeKey = NEW _PRIVATE ( "CallSite#strict_mode" ) ;
2013-03-28 10:40:07 +00:00
function CallSite ( receiver , fun , pos , strict _mode ) {
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
SET _PRIVATE ( this , CallSiteReceiverKey , receiver ) ;
SET _PRIVATE ( this , CallSiteFunctionKey , fun ) ;
SET _PRIVATE ( this , CallSitePositionKey , pos ) ;
SET _PRIVATE ( this , CallSiteStrictModeKey , strict _mode ) ;
2009-06-30 11:08:37 +00:00
}
2011-09-05 07:30:35 +00:00
function CallSiteGetThis ( ) {
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
return GET _PRIVATE ( this , CallSiteStrictModeKey )
? UNDEFINED : GET _PRIVATE ( this , CallSiteReceiverKey ) ;
2011-11-28 12:11:00 +00:00
}
2009-06-30 11:08:37 +00:00
2011-09-05 07:30:35 +00:00
function CallSiteGetTypeName ( ) {
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
return GetTypeName ( GET _PRIVATE ( this , CallSiteReceiverKey ) , false ) ;
2011-11-28 12:11:00 +00:00
}
2009-06-30 11:08:37 +00:00
2011-09-05 07:30:35 +00:00
function CallSiteIsToplevel ( ) {
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
if ( GET _PRIVATE ( this , CallSiteReceiverKey ) == null ) {
2009-06-30 11:08:37 +00:00
return true ;
2011-08-22 09:51:56 +00:00
}
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
return IS _GLOBAL ( GET _PRIVATE ( this , CallSiteReceiverKey ) ) ;
2011-11-28 12:11:00 +00:00
}
2009-06-30 11:08:37 +00:00
2011-09-05 07:30:35 +00:00
function CallSiteIsEval ( ) {
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
var script = % FunctionGetScript ( GET _PRIVATE ( this , CallSiteFunctionKey ) ) ;
2010-03-23 11:40:38 +00:00
return script && script . compilation _type == COMPILATION _TYPE _EVAL ;
2011-11-28 12:11:00 +00:00
}
2009-06-30 11:08:37 +00:00
2011-09-05 07:30:35 +00:00
function CallSiteGetEvalOrigin ( ) {
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
var script = % FunctionGetScript ( GET _PRIVATE ( this , CallSiteFunctionKey ) ) ;
2009-12-01 14:36:45 +00:00
return FormatEvalOrigin ( script ) ;
2011-11-28 12:11:00 +00:00
}
2009-06-30 11:08:37 +00:00
2011-09-05 07:30:35 +00:00
function CallSiteGetScriptNameOrSourceURL ( ) {
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
var script = % FunctionGetScript ( GET _PRIVATE ( this , CallSiteFunctionKey ) ) ;
2010-09-20 15:55:28 +00:00
return script ? script . nameOrSourceURL ( ) : null ;
2011-11-28 12:11:00 +00:00
}
2010-09-20 15:55:28 +00:00
2011-09-05 07:30:35 +00:00
function CallSiteGetFunction ( ) {
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
return GET _PRIVATE ( this , CallSiteStrictModeKey )
? UNDEFINED : GET _PRIVATE ( this , CallSiteFunctionKey ) ;
2011-11-28 12:11:00 +00:00
}
2009-07-02 15:30:03 +00:00
2011-09-05 07:30:35 +00:00
function CallSiteGetFunctionName ( ) {
2009-06-30 11:08:37 +00:00
// See if the function knows its own name
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
var name = GET _PRIVATE ( this , CallSiteFunctionKey ) . name ;
2009-07-02 12:26:31 +00:00
if ( name ) {
2009-06-30 11:08:37 +00:00
return name ;
2012-05-24 11:00:05 +00:00
}
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
name = % FunctionGetInferredName ( GET _PRIVATE ( this , CallSiteFunctionKey ) ) ;
2012-05-24 11:00:05 +00:00
if ( name ) {
return name ;
2009-07-02 12:26:31 +00:00
}
// Maybe this is an evaluation?
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
var script = % FunctionGetScript ( GET _PRIVATE ( this , CallSiteFunctionKey ) ) ;
2011-08-22 09:51:56 +00:00
if ( script && script . compilation _type == COMPILATION _TYPE _EVAL ) {
2009-07-02 12:26:31 +00:00
return "eval" ;
2011-08-22 09:51:56 +00:00
}
2009-07-02 12:26:31 +00:00
return null ;
2011-11-28 12:11:00 +00:00
}
2009-07-02 12:26:31 +00:00
2011-09-05 07:30:35 +00:00
function CallSiteGetMethodName ( ) {
2009-06-30 11:08:37 +00:00
// See if we can find a unique property on the receiver that holds
// this function.
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
var receiver = GET _PRIVATE ( this , CallSiteReceiverKey ) ;
var fun = GET _PRIVATE ( this , CallSiteFunctionKey ) ;
2013-03-28 10:40:07 +00:00
var ownName = fun . name ;
if ( ownName && receiver &&
( % _CallFunction ( receiver , ownName , ObjectLookupGetter ) === fun ||
% _CallFunction ( receiver , ownName , ObjectLookupSetter ) === fun ||
( IS _OBJECT ( receiver ) && % GetDataProperty ( receiver , ownName ) === fun ) ) ) {
2009-07-02 15:30:03 +00:00
// To handle DontEnum properties we guess that the method has
// the same name as the function.
return ownName ;
2010-08-13 08:31:52 +00:00
}
2009-07-02 12:26:31 +00:00
var name = null ;
2013-03-28 10:40:07 +00:00
for ( var prop in receiver ) {
if ( % _CallFunction ( receiver , prop , ObjectLookupGetter ) === fun ||
% _CallFunction ( receiver , prop , ObjectLookupSetter ) === fun ||
( IS _OBJECT ( receiver ) && % GetDataProperty ( receiver , prop ) === fun ) ) {
2010-08-13 08:31:52 +00:00
// If we find more than one match bail out to avoid confusion.
2011-08-22 09:51:56 +00:00
if ( name ) {
2009-06-30 11:08:37 +00:00
return null ;
2011-08-22 09:51:56 +00:00
}
2009-06-30 11:08:37 +00:00
name = prop ;
}
}
2011-08-22 09:51:56 +00:00
if ( name ) {
2009-06-30 11:08:37 +00:00
return name ;
2011-08-22 09:51:56 +00:00
}
2009-06-30 11:08:37 +00:00
return null ;
2011-11-28 12:11:00 +00:00
}
2009-06-30 11:08:37 +00:00
2011-09-05 07:30:35 +00:00
function CallSiteGetFileName ( ) {
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
var script = % FunctionGetScript ( GET _PRIVATE ( this , CallSiteFunctionKey ) ) ;
2009-06-30 11:08:37 +00:00
return script ? script . name : null ;
2011-11-28 12:11:00 +00:00
}
2009-06-30 11:08:37 +00:00
2011-09-05 07:30:35 +00:00
function CallSiteGetLineNumber ( ) {
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
if ( GET _PRIVATE ( this , CallSitePositionKey ) == - 1 ) {
2009-06-30 11:08:37 +00:00
return null ;
2011-08-22 09:51:56 +00:00
}
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
var script = % FunctionGetScript ( GET _PRIVATE ( this , CallSiteFunctionKey ) ) ;
2009-06-30 11:08:37 +00:00
var location = null ;
if ( script ) {
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
location = script . locationFromPosition (
GET _PRIVATE ( this , CallSitePositionKey ) , true ) ;
2009-06-30 11:08:37 +00:00
}
return location ? location . line + 1 : null ;
2011-11-28 12:11:00 +00:00
}
2009-06-30 11:08:37 +00:00
2011-09-05 07:30:35 +00:00
function CallSiteGetColumnNumber ( ) {
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
if ( GET _PRIVATE ( this , CallSitePositionKey ) == - 1 ) {
2009-06-30 11:08:37 +00:00
return null ;
2011-08-22 09:51:56 +00:00
}
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
var script = % FunctionGetScript ( GET _PRIVATE ( this , CallSiteFunctionKey ) ) ;
2009-06-30 11:08:37 +00:00
var location = null ;
if ( script ) {
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
location = script . locationFromPosition (
GET _PRIVATE ( this , CallSitePositionKey ) , true ) ;
2009-06-30 11:08:37 +00:00
}
2009-12-01 14:36:45 +00:00
return location ? location . column + 1 : null ;
2011-11-28 12:11:00 +00:00
}
2009-06-30 11:08:37 +00:00
2011-09-05 07:30:35 +00:00
function CallSiteIsNative ( ) {
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
var script = % FunctionGetScript ( GET _PRIVATE ( this , CallSiteFunctionKey ) ) ;
2010-03-23 11:40:38 +00:00
return script ? ( script . type == TYPE _NATIVE ) : false ;
2011-11-28 12:11:00 +00:00
}
2009-06-30 11:08:37 +00:00
2011-09-05 07:30:35 +00:00
function CallSiteGetPosition ( ) {
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
return GET _PRIVATE ( this , CallSitePositionKey ) ;
2011-11-28 12:11:00 +00:00
}
2009-06-30 11:08:37 +00:00
2011-09-05 07:30:35 +00:00
function CallSiteIsConstructor ( ) {
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
var receiver = GET _PRIVATE ( this , CallSiteReceiverKey ) ;
2013-05-24 11:33:46 +00:00
var constructor = ( receiver != null && IS _OBJECT ( receiver ) )
? % GetDataProperty ( receiver , "constructor" ) : null ;
2013-03-01 14:50:14 +00:00
if ( ! constructor ) return false ;
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
return GET _PRIVATE ( this , CallSiteFunctionKey ) === constructor ;
2011-11-28 12:11:00 +00:00
}
2009-06-30 11:08:37 +00:00
2012-05-15 12:24:44 +00:00
function CallSiteToString ( ) {
var fileName ;
var fileLocation = "" ;
if ( this . isNative ( ) ) {
fileLocation = "native" ;
} else {
2014-02-12 15:50:23 +00:00
fileName = this . getScriptNameOrSourceURL ( ) ;
if ( ! fileName && this . isEval ( ) ) {
fileLocation = this . getEvalOrigin ( ) ;
fileLocation += ", " ; // Expecting source position to follow.
2012-06-18 13:39:24 +00:00
}
2012-05-15 12:24:44 +00:00
2012-06-18 13:39:24 +00:00
if ( fileName ) {
fileLocation += fileName ;
} else {
// Source code does not originate from a file and is not native, but we
// can still get the source position inside the source string, e.g. in
// an eval string.
fileLocation += "<anonymous>" ;
}
2012-05-15 12:24:44 +00:00
var lineNumber = this . getLineNumber ( ) ;
if ( lineNumber != null ) {
fileLocation += ":" + lineNumber ;
var columnNumber = this . getColumnNumber ( ) ;
if ( columnNumber ) {
fileLocation += ":" + columnNumber ;
}
}
}
var line = "" ;
2012-05-24 11:00:05 +00:00
var functionName = this . getFunctionName ( ) ;
var addSuffix = true ;
2012-05-15 12:24:44 +00:00
var isConstructor = this . isConstructor ( ) ;
var isMethodCall = ! ( this . isToplevel ( ) || isConstructor ) ;
if ( isMethodCall ) {
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
var typeName = GetTypeName ( GET _PRIVATE ( this , CallSiteReceiverKey ) , true ) ;
2012-05-15 12:24:44 +00:00
var methodName = this . getMethodName ( ) ;
if ( functionName ) {
2013-01-14 13:19:27 +00:00
if ( typeName &&
% _CallFunction ( functionName , typeName , StringIndexOf ) != 0 ) {
2012-05-24 11:00:05 +00:00
line += typeName + "." ;
}
2012-05-15 12:24:44 +00:00
line += functionName ;
2013-01-14 13:19:27 +00:00
if ( methodName &&
( % _CallFunction ( functionName , "." + methodName , StringIndexOf ) !=
functionName . length - methodName . length - 1 ) ) {
2012-05-15 12:24:44 +00:00
line += " [as " + methodName + "]" ;
}
} else {
2012-05-24 11:00:05 +00:00
line += typeName + "." + ( methodName || "<anonymous>" ) ;
2012-05-15 12:24:44 +00:00
}
} else if ( isConstructor ) {
line += "new " + ( functionName || "<anonymous>" ) ;
} else if ( functionName ) {
line += functionName ;
} else {
line += fileLocation ;
2012-05-24 11:00:05 +00:00
addSuffix = false ;
2012-05-15 12:24:44 +00:00
}
2012-05-24 11:00:05 +00:00
if ( addSuffix ) {
2012-05-15 12:24:44 +00:00
line += " (" + fileLocation + ")" ;
}
return line ;
}
2011-09-05 07:30:35 +00:00
SetUpLockedPrototype ( CallSite , $Array ( "receiver" , "fun" , "pos" ) , $Array (
"getThis" , CallSiteGetThis ,
"getTypeName" , CallSiteGetTypeName ,
"isToplevel" , CallSiteIsToplevel ,
"isEval" , CallSiteIsEval ,
"getEvalOrigin" , CallSiteGetEvalOrigin ,
"getScriptNameOrSourceURL" , CallSiteGetScriptNameOrSourceURL ,
"getFunction" , CallSiteGetFunction ,
"getFunctionName" , CallSiteGetFunctionName ,
"getMethodName" , CallSiteGetMethodName ,
"getFileName" , CallSiteGetFileName ,
"getLineNumber" , CallSiteGetLineNumber ,
"getColumnNumber" , CallSiteGetColumnNumber ,
"isNative" , CallSiteIsNative ,
"getPosition" , CallSiteGetPosition ,
2012-05-15 12:24:44 +00:00
"isConstructor" , CallSiteIsConstructor ,
"toString" , CallSiteToString
2011-09-05 07:30:35 +00:00
) ) ;
2009-12-01 14:36:45 +00:00
function FormatEvalOrigin ( script ) {
2010-09-20 15:55:28 +00:00
var sourceURL = script . nameOrSourceURL ( ) ;
2011-08-22 09:51:56 +00:00
if ( sourceURL ) {
2010-09-20 15:55:28 +00:00
return sourceURL ;
2011-08-22 09:51:56 +00:00
}
2010-09-20 15:55:28 +00:00
var eval _origin = "eval at " ;
2009-12-01 14:36:45 +00:00
if ( script . eval _from _function _name ) {
eval _origin += script . eval _from _function _name ;
} else {
eval _origin += "<anonymous>" ;
}
2010-03-30 07:15:23 +00:00
2009-12-01 14:36:45 +00:00
var eval _from _script = script . eval _from _script ;
if ( eval _from _script ) {
2010-03-23 11:40:38 +00:00
if ( eval _from _script . compilation _type == COMPILATION _TYPE _EVAL ) {
2009-12-01 14:36:45 +00:00
// eval script originated from another eval.
2010-09-20 15:55:28 +00:00
eval _origin += " (" + FormatEvalOrigin ( eval _from _script ) + ")" ;
2009-12-01 14:36:45 +00:00
} else {
2010-09-20 15:55:28 +00:00
// eval script originated from "real" source.
2009-12-01 14:36:45 +00:00
if ( eval _from _script . name ) {
eval _origin += " (" + eval _from _script . name ;
2011-11-28 12:11:00 +00:00
var location = eval _from _script . locationFromPosition (
script . eval _from _script _position , true ) ;
2009-12-01 14:36:45 +00:00
if ( location ) {
eval _origin += ":" + ( location . line + 1 ) ;
eval _origin += ":" + ( location . column + 1 ) ;
}
2011-11-28 12:11:00 +00:00
eval _origin += ")" ;
2009-12-01 14:36:45 +00:00
} else {
eval _origin += " (unknown source)" ;
}
}
}
2010-03-30 07:15:23 +00:00
2009-12-01 14:36:45 +00:00
return eval _origin ;
2011-11-28 12:11:00 +00:00
}
2009-12-01 14:36:45 +00:00
2013-01-14 13:19:27 +00:00
function FormatErrorString ( error ) {
2009-06-30 11:08:37 +00:00
try {
2013-01-14 13:19:27 +00:00
return % _CallFunction ( error , ErrorToString ) ;
2009-06-30 11:08:37 +00:00
} catch ( e ) {
try {
2013-01-14 13:19:27 +00:00
return "<error: " + e + ">" ;
2009-06-30 11:08:37 +00:00
} catch ( ee ) {
2013-01-14 13:19:27 +00:00
return "<error>" ;
2009-06-30 11:08:37 +00:00
}
}
2013-01-14 13:19:27 +00:00
}
function GetStackFrames ( raw _stack ) {
2013-02-15 16:21:03 +00:00
var frames = new InternalArray ( ) ;
2014-03-11 14:39:08 +00:00
var sloppy _frames = raw _stack [ 0 ] ;
2013-03-28 10:40:07 +00:00
for ( var i = 1 ; i < raw _stack . length ; i += 4 ) {
2013-01-14 13:19:27 +00:00
var recv = raw _stack [ i ] ;
var fun = raw _stack [ i + 1 ] ;
var code = raw _stack [ i + 2 ] ;
var pc = raw _stack [ i + 3 ] ;
var pos = % FunctionGetPositionForOffset ( code , pc ) ;
2014-03-11 14:39:08 +00:00
sloppy _frames -- ;
frames . push ( new CallSite ( recv , fun , pos , ( sloppy _frames < 0 ) ) ) ;
2013-01-14 13:19:27 +00:00
}
return frames ;
}
2013-07-26 11:28:08 +00:00
// Flag to prevent recursive call of Error.prepareStackTrace.
var formatting _custom _stack _trace = false ;
function FormatStackTrace ( obj , error _string , frames ) {
if ( IS _FUNCTION ( $Error . prepareStackTrace ) && ! formatting _custom _stack _trace ) {
var array = [ ] ;
% MoveArrayContents ( frames , array ) ;
formatting _custom _stack _trace = true ;
2013-10-17 10:02:45 +00:00
var stack _trace = UNDEFINED ;
2013-07-26 11:28:08 +00:00
try {
stack _trace = $Error . prepareStackTrace ( obj , array ) ;
} catch ( e ) {
throw e ; // The custom formatting function threw. Rethrow.
} finally {
formatting _custom _stack _trace = false ;
}
return stack _trace ;
}
2013-02-15 16:21:03 +00:00
var lines = new InternalArray ( ) ;
2013-01-14 13:19:27 +00:00
lines . push ( error _string ) ;
2009-06-30 11:08:37 +00:00
for ( var i = 0 ; i < frames . length ; i ++ ) {
var frame = frames [ i ] ;
2009-09-23 12:32:24 +00:00
var line ;
2009-06-30 11:08:37 +00:00
try {
2012-05-15 12:24:44 +00:00
line = frame . toString ( ) ;
2009-06-30 11:08:37 +00:00
} catch ( e ) {
try {
2009-09-23 12:32:24 +00:00
line = "<error: " + e + ">" ;
2009-06-30 11:08:37 +00:00
} catch ( ee ) {
// Any code that reaches this point is seriously nasty!
2009-09-23 12:32:24 +00:00
line = "<error>" ;
2009-06-30 11:08:37 +00:00
}
}
lines . push ( " at " + line ) ;
}
2013-01-14 13:19:27 +00:00
return % _CallFunction ( lines , "\n" , ArrayJoin ) ;
2009-06-30 11:08:37 +00:00
}
2013-03-28 10:40:07 +00:00
function GetTypeName ( receiver , requireConstructor ) {
var constructor = receiver . constructor ;
2012-05-24 11:00:05 +00:00
if ( ! constructor ) {
return requireConstructor ? null :
2013-03-28 10:40:07 +00:00
% _CallFunction ( receiver , ObjectToString ) ;
2012-05-24 11:00:05 +00:00
}
var constructorName = constructor . name ;
if ( ! constructorName ) {
return requireConstructor ? null :
2013-03-28 10:40:07 +00:00
% _CallFunction ( receiver , ObjectToString ) ;
2012-05-24 11:00:05 +00:00
}
return constructorName ;
}
2011-09-05 07:30:35 +00:00
2013-01-14 13:19:27 +00:00
2009-07-27 12:01:32 +00:00
function captureStackTrace ( obj , cons _opt ) {
var stackTraceLimit = $Error . stackTraceLimit ;
2011-02-02 13:31:52 +00:00
if ( ! stackTraceLimit || ! IS _NUMBER ( stackTraceLimit ) ) return ;
2011-08-22 09:51:56 +00:00
if ( stackTraceLimit < 0 || stackTraceLimit > 10000 ) {
2009-07-27 12:01:32 +00:00
stackTraceLimit = 10000 ;
2011-08-22 09:51:56 +00:00
}
2013-01-14 13:19:27 +00:00
var stack = % CollectStackTrace ( obj ,
cons _opt ? cons _opt : captureStackTrace ,
stackTraceLimit ) ;
var error _string = FormatErrorString ( obj ) ;
2013-07-24 12:16:02 +00:00
// Set the 'stack' property on the receiver. If the receiver is the same as
// holder of this setter, the accessor pair is turned into a data property.
2012-11-12 14:54:29 +00:00
var setter = function ( v ) {
2013-07-24 12:16:02 +00:00
// Set data property on the receiver (not necessarily holder).
2012-11-12 14:54:29 +00:00
% DefineOrRedefineDataProperty ( this , 'stack' , v , NONE ) ;
2013-07-24 12:16:02 +00:00
if ( this === obj ) {
// Release context values if holder is the same as the receiver.
2013-10-17 10:02:45 +00:00
stack = error _string = UNDEFINED ;
2013-07-24 12:16:02 +00:00
}
2012-11-12 14:54:29 +00:00
} ;
2014-04-28 12:14:36 +00:00
// The holder of this getter ('obj') may not be the receiver ('this').
// When this getter is called the first time, we use the context values to
// format a stack trace string and turn this accessor pair into a data
// property (on the holder).
var getter = function ( ) {
// Stack is still a raw array awaiting to be formatted.
var result = FormatStackTrace ( obj , error _string , GetStackFrames ( stack ) ) ;
// Replace this accessor to return result directly.
% DefineOrRedefineAccessorProperty (
obj , 'stack' , function ( ) { return result } , setter , DONT _ENUM ) ;
// Release context values.
stack = error _string = UNDEFINED ;
return result ;
} ;
2012-11-12 14:54:29 +00:00
% DefineOrRedefineAccessorProperty ( obj , 'stack' , getter , setter , DONT _ENUM ) ;
2011-11-28 12:11:00 +00:00
}
2009-07-27 12:01:32 +00:00
2008-07-03 15:10:15 +00:00
2011-09-05 07:30:35 +00:00
function SetUpError ( ) {
2011-09-01 07:39:22 +00:00
// Define special error type constructors.
2012-02-20 13:48:24 +00:00
var DefineError = function ( f ) {
2011-09-01 07:39:22 +00:00
// Store the error function in both the global object
// and the runtime object. The function is fetched
// from the runtime object when throwing errors from
// within the runtime system to avoid strange side
// effects when overwriting the error functions from
// user code.
var name = f . name ;
% SetProperty ( global , name , f , DONT _ENUM ) ;
2011-09-01 11:57:02 +00:00
% SetProperty ( builtins , '$' + name , f , DONT _ENUM | DONT _DELETE | READ _ONLY ) ;
2011-09-01 07:39:22 +00:00
// Configure the error function.
if ( name == 'Error' ) {
// The prototype of the Error object must itself be an error.
// However, it can't be an instance of the Error object because
// it hasn't been properly configured yet. Instead we create a
// special not-a-true-error-but-close-enough object.
2012-02-20 13:48:24 +00:00
var ErrorPrototype = function ( ) { } ;
2011-09-01 07:39:22 +00:00
% FunctionSetPrototype ( ErrorPrototype , $Object . prototype ) ;
% FunctionSetInstanceClassName ( ErrorPrototype , 'Error' ) ;
% FunctionSetPrototype ( f , new ErrorPrototype ( ) ) ;
} else {
% FunctionSetPrototype ( f , new $Error ( ) ) ;
}
% FunctionSetInstanceClassName ( f , 'Error' ) ;
% SetProperty ( f . prototype , 'constructor' , f , DONT _ENUM ) ;
2012-05-09 12:35:11 +00:00
% SetProperty ( f . prototype , "name" , name , DONT _ENUM ) ;
2011-09-01 07:39:22 +00:00
% SetCode ( f , function ( m ) {
if ( % _IsConstructCall ( ) ) {
// Define all the expected properties directly on the error
// object. This avoids going through getters and setters defined
// on prototype objects.
2013-10-17 10:02:45 +00:00
% IgnoreAttributesAndSetProperty ( this , 'stack' , UNDEFINED , DONT _ENUM ) ;
2012-11-09 08:22:02 +00:00
if ( ! IS _UNDEFINED ( m ) ) {
2012-05-09 12:35:11 +00:00
% IgnoreAttributesAndSetProperty (
this , 'message' , ToString ( m ) , DONT _ENUM ) ;
2011-09-01 07:39:22 +00:00
}
captureStackTrace ( this , f ) ;
} else {
return new f ( m ) ;
}
} ) ;
2011-10-20 12:31:33 +00:00
% SetNativeFlag ( f ) ;
2012-02-20 13:48:24 +00:00
} ;
2009-07-27 12:01:32 +00:00
2011-09-01 07:39:22 +00:00
DefineError ( function Error ( ) { } ) ;
DefineError ( function TypeError ( ) { } ) ;
DefineError ( function RangeError ( ) { } ) ;
DefineError ( function SyntaxError ( ) { } ) ;
DefineError ( function ReferenceError ( ) { } ) ;
DefineError ( function EvalError ( ) { } ) ;
DefineError ( function URIError ( ) { } ) ;
2011-09-05 07:30:35 +00:00
}
SetUpError ( ) ;
2011-06-15 13:54:40 +00:00
2011-09-01 07:39:22 +00:00
$Error . captureStackTrace = captureStackTrace ;
2011-06-15 13:54:40 +00:00
2011-09-01 07:39:22 +00:00
% SetProperty ( $Error . prototype , 'message' , '' , DONT _ENUM ) ;
2008-07-03 15:10:15 +00:00
2011-10-26 10:41:52 +00:00
// Global list of error objects visited during ErrorToString. This is
2011-01-21 11:44:29 +00:00
// used to detect cycles in error toString formatting.
2012-02-20 13:48:24 +00:00
var visited _errors = new InternalArray ( ) ;
var cyclic _error _marker = new $Object ( ) ;
2011-01-21 11:44:29 +00:00
2012-05-09 12:35:11 +00:00
function GetPropertyWithoutInvokingMonkeyGetters ( error , name ) {
2013-11-05 13:04:51 +00:00
var current = error ;
2012-05-09 12:35:11 +00:00
// Climb the prototype chain until we find the holder.
2013-11-05 13:04:51 +00:00
while ( current && ! % HasLocalProperty ( current , name ) ) {
current = % GetPrototype ( current ) ;
2012-05-09 12:35:11 +00:00
}
2013-11-05 13:04:51 +00:00
if ( IS _NULL ( current ) ) return UNDEFINED ;
if ( ! IS _OBJECT ( current ) ) return error [ name ] ;
2012-05-09 12:35:11 +00:00
// If the property is an accessor on one of the predefined errors that can be
// generated statically by the compiler, don't touch it. This is to address
// http://code.google.com/p/chromium/issues/detail?id=69187
2013-11-05 13:04:51 +00:00
var desc = % GetOwnProperty ( current , name ) ;
2012-05-09 12:35:11 +00:00
if ( desc && desc [ IS _ACCESSOR _INDEX ] ) {
var isName = name === "name" ;
2013-11-05 13:04:51 +00:00
if ( current === $ReferenceError . prototype )
2013-10-17 10:02:45 +00:00
return isName ? "ReferenceError" : UNDEFINED ;
2013-11-05 13:04:51 +00:00
if ( current === $SyntaxError . prototype )
2013-10-17 10:02:45 +00:00
return isName ? "SyntaxError" : UNDEFINED ;
2013-11-05 13:04:51 +00:00
if ( current === $TypeError . prototype )
2013-10-17 10:02:45 +00:00
return isName ? "TypeError" : UNDEFINED ;
2012-05-09 12:35:11 +00:00
}
// Otherwise, read normally.
return error [ name ] ;
}
2011-10-26 10:41:52 +00:00
function ErrorToStringDetectCycle ( error ) {
2011-09-01 07:39:22 +00:00
if ( ! % PushIfAbsent ( visited _errors , error ) ) throw cyclic _error _marker ;
2011-01-21 11:44:29 +00:00
try {
2012-05-09 12:35:11 +00:00
var name = GetPropertyWithoutInvokingMonkeyGetters ( error , "name" ) ;
2011-10-26 10:41:52 +00:00
name = IS _UNDEFINED ( name ) ? "Error" : TO _STRING _INLINE ( name ) ;
2012-05-09 12:35:11 +00:00
var message = GetPropertyWithoutInvokingMonkeyGetters ( error , "message" ) ;
2011-10-26 10:41:52 +00:00
message = IS _UNDEFINED ( message ) ? "" : TO _STRING _INLINE ( message ) ;
if ( name === "" ) return message ;
if ( message === "" ) return name ;
return name + ": " + message ;
2011-01-21 11:44:29 +00:00
} finally {
2011-02-01 12:31:16 +00:00
visited _errors . length = visited _errors . length - 1 ;
2011-01-21 11:44:29 +00:00
}
}
2011-10-26 10:41:52 +00:00
function ErrorToString ( ) {
2012-03-05 13:57:48 +00:00
if ( ! IS _SPEC _OBJECT ( this ) ) {
throw MakeTypeError ( "called_on_non_object" , [ "Error.prototype.toString" ] ) ;
2011-05-05 05:21:30 +00:00
}
2011-01-21 11:44:29 +00:00
try {
2011-10-26 10:41:52 +00:00
return ErrorToStringDetectCycle ( this ) ;
2011-01-21 11:44:29 +00:00
} catch ( e ) {
2011-01-21 14:11:35 +00:00
// If this error message was encountered already return the empty
// string for it instead of recursively formatting it.
2011-10-26 10:41:52 +00:00
if ( e === cyclic _error _marker ) {
2011-08-22 09:51:56 +00:00
return '' ;
}
throw e ;
2008-07-03 15:10:15 +00:00
}
2011-01-14 12:51:04 +00:00
}
2011-01-14 14:51:19 +00:00
2011-02-28 13:29:05 +00:00
2011-10-26 10:41:52 +00:00
InstallFunctions ( $Error . prototype , DONT _ENUM , [ 'toString' , ErrorToString ] ) ;
2008-07-03 15:10:15 +00:00
// Boilerplate for exceptions for stack overflows. Used from
2011-03-18 20:35:07 +00:00
// Isolate::StackOverflow().
2012-11-12 14:54:29 +00:00
function SetUpStackOverflowBoilerplate ( ) {
var boilerplate = MakeRangeError ( 'stack_overflow' , [ ] ) ;
2013-01-14 13:19:27 +00:00
var error _string = boilerplate . name + ": " + boilerplate . message ;
2014-04-28 12:14:36 +00:00
// Set the 'stack' property on the receiver. If the receiver is the same as
// holder of this setter, the accessor pair is turned into a data property.
var setter = function ( v ) {
% DefineOrRedefineDataProperty ( this , 'stack' , v , NONE ) ;
// Tentatively clear the hidden property. If the receiver is the same as
// holder, we release the raw stack trace this way.
% GetAndClearOverflowedStackTrace ( this ) ;
} ;
2013-07-24 12:16:02 +00:00
// The raw stack trace is stored as a hidden property on the holder of this
// getter, which may not be the same as the receiver. Find the holder to
// retrieve the raw stack trace and then turn this accessor pair into a
// data property.
var getter = function ( ) {
2012-11-12 14:54:29 +00:00
var holder = this ;
while ( ! IS _ERROR ( holder ) ) {
holder = % GetPrototype ( holder ) ;
2013-07-24 12:16:02 +00:00
if ( IS _NULL ( holder ) ) return MakeSyntaxError ( 'illegal_access' , [ ] ) ;
2012-11-12 14:54:29 +00:00
}
2013-07-24 12:16:02 +00:00
var stack = % GetAndClearOverflowedStackTrace ( holder ) ;
// We may not have captured any stack trace.
if ( IS _UNDEFINED ( stack ) ) return stack ;
2013-07-26 11:28:08 +00:00
var result = FormatStackTrace ( holder , error _string , GetStackFrames ( stack ) ) ;
2014-04-28 12:14:36 +00:00
// Replace this accessor to return result directly.
% DefineOrRedefineAccessorProperty (
holder , 'stack' , function ( ) { return result } , setter , DONT _ENUM ) ;
2013-07-24 12:16:02 +00:00
return result ;
} ;
2012-11-12 14:54:29 +00:00
% DefineOrRedefineAccessorProperty (
boilerplate , 'stack' , getter , setter , DONT _ENUM ) ;
return boilerplate ;
}
var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate ( ) ;