Hi. I am look around the source trying to find where primitive strings are created. So far I can't find the exact spot.
Also what happens if you have: var x = "primitive string" x.<some string method>() How does the primitive string get converted to a string object such that you can run string methods on it. Matt On Dec 14, 7:27 am, "Lasse R.H. Nielsen" <[email protected]> wrote: > Hi there. > > The code inside the function is called every time the String constructor is > called, either as a constructor or as a type converter. It really is the > internal definition of the String function. > The %_IsConstructCall() test is true if the function is called as a > constructor (i.e., 'new String("foo")') [1]. > > That means that the function is called for > var x = new String("string"); > It's not called for > var x = "string"; > since it doesn't use the String function at all (it also doesn't create a > String *object*, just a primitive string value). > > The String function is also not called if you do: > var x = Object("string"); > which does create a new String object (or, it needen't be, according to the > specification, but we actually do call it internally to create the new > string - see ToObject in runtime.js). > > Regards > /L > [1] You will probably never *need* to create a new String/Number/Boolean > object though. > > > > > > > > > > On Mon, Dec 13, 2010 at 20:37, mcot <[email protected]> wrote: > > I was wondering if someone could provide details on the *.js files in > > the v8 source. > > > In string.js I see this fragment of code: > > > // Set the String function and constructor. > > %SetCode($String, function(x) { > > var value = %_ArgumentsLength() == 0 ? '' : TO_STRING_INLINE(x); > > if (%_IsConstructCall()) { > > %_SetValueOf(this, value); > > } else { > > return value; > > } > > }); > > > Is this called every time a string is created? Specifically I was > > wondering about both of these cases: > > > var x = "string" > > var x = new String("string") > > > Also, could I add my own custom code to these files to perform some > > action when a string is created? > > > Thanks in advance. > > Matt > > > -- > > v8-users mailing list > > [email protected] > >http://groups.google.com/group/v8-users > > -- > Lasse R.H. Nielsen > [email protected] > 'Faith without judgement merely degrades the spirit divine' > Google Denmark ApS - Frederiksborggade 20B, 1 sal - 1360 København K - > Denmark - CVR nr. 28 86 69 84 -- v8-users mailing list [email protected] http://groups.google.com/group/v8-users
