Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > "eval" query

Reply
Thread Tools

"eval" query

 
 
Dr J R Stockton
Guest
Posts: n/a
 
      09-24-2011
Is there any string S for which eval(S) will give a Date Object? If
so, for the pedants, what is it?

If there is, existing code will serve with added text. Otherwise, new
code will need to be written.

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk DOS 3.3 6.20 ; WinXP.
Web <http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.
 
Reply With Quote
 
 
 
 
Eric Bednarz
Guest
Posts: n/a
 
      09-24-2011
Dr J R Stockton <> writes:

> Is there any string S for which eval(S) will give a Date Object? If
> so, for the pedants, what is it?


I really wonder what you intended to ask. As far as I am concerned,

'new Date()'

is a string and

eval('new Date()')

does the obvious.

 
Reply With Quote
 
 
 
 
Dr J R Stockton
Guest
Posts: n/a
 
      09-25-2011
On Sep 25, 12:28*am, Eric Bednarz <bedn...@fahr-zur-hoelle.org> wrote:
> Dr J R Stockton <reply1...@merlyn.demon.co.uk> writes:
>
> > Is there any string S for which * eval(S) * will give a Date Object? *If
> > so, for the pedants, what is it?

>
> I really wonder what you intended to ask. As far as I am concerned,
>
> * 'new Date()'
>
> is a string and
>
> * eval('new Date()')
>
> does the obvious.



But what do you think is obvious? Did you test it? Would you expect
to get a function, another type of Object, or a string? Would you be
right?


I intended to ask what I asked; and that is not what you have
answered. Your answer only tells us that you think you are right.


The page in question being open at the time, S = "new Date()" is
exactly what I tried first - because it was the quickest first move,
quicker than opening or trying to remember the code. Only on reading
the code did I *know* that it used eval(S) .

If I put S = "Math" , I get an Object, with properties such as sin &
cos which Safari can list. If I put S = "Date" , I get a function,
with properties such as UTC & now which Safari can list.

But I want to get an Object with value an IEEE Double of integer value
and properties such as setDate & toJSON which Safari can list, and I
want to do it by entering a string S, containing "new Date" and
suitable other characters. It may not be possible.


Also, what is the proper terminology to sustinguish between objects
like the Math object and a Date object?


--
(c) John Stockton, near London, UK. Using Google, no spell-check.
Mail: J.R.""""""""@physics.org or (better) via Home Page at
Web: <http://www.merlyn.demon.co.uk/>
FAQish topics, acronyms, links, etc.; Date, Pascal, JavaScript, ....|
 
Reply With Quote
 
Lasse Reichstein Nielsen
Guest
Posts: n/a
 
      09-25-2011
Dr J R Stockton <> writes:

> On Sep 25, 12:28*am, Eric Bednarz <bedn...@fahr-zur-hoelle.org> wrote:
>> Dr J R Stockton <reply1...@merlyn.demon.co.uk> writes:
>>
>> > Is there any string S for which * eval(S) * will give a Date Object? *If
>> > so, for the pedants, what is it?

>>
>> I really wonder what you intended to ask. As far as I am concerned,
>>
>> * 'new Date()'
>>
>> is a string and
>>
>> * eval('new Date()')
>>
>> does the obvious.

>
>
> But what do you think is obvious?


That
eval('new Date()')
evaluates to a Date object?

> Did you test it?


No. That's what the specification of eval says should happen. I don't
test things for doing what they are supposed to do without a reason
to suspect that thay don't. Do you have any reason to suppose it won't
give a Date object?

> Would you expect to get a function, another type of Object, or a string?


No.

> Would you be right?


No if I expected something not a Date object, no.


> I intended to ask what I asked; and that is not what you have
> answered. Your answer only tells us that you think you are right.


And yet, that answer contained an answer to your question. It have a
string such that eval of that string gives a Date object.

> The page in question being open at the time, S = "new Date()" is
> exactly what I tried first - because it was the quickest first move,
> quicker than opening or trying to remember the code. Only on reading
> the code did I *know* that it used eval(S) .
>
> If I put S = "Math" , I get an Object, with properties such as sin &
> cos which Safari can list. If I put S = "Date" , I get a function,
> with properties such as UTC & now which Safari can list.


As expected.

> But I want to get an Object with value an IEEE Double of integer value
> and properties such as setDate & toJSON which Safari can list, and I
> want to do it by entering a string S, containing "new Date" and
> suitable other characters. It may not be possible.


You haven't yet said what you did get when you tried. I.e.,
What did you do? What happened? What did you expect to happen?

So, now I tested it. If I execute:
var S = "new Date";
alert(Object.prototype.toString.call(eval(S)));
it alerts "[object Date]".
And if I execute:
var S = "new Date";
alert("setDate" in eval(S));
it alerts "true"

And I just checked it in Safari too. Same result.
If you get something else, you are doing something else.

> Also, what is the proper terminology to sustinguish between objects
> like the Math object and a Date object?


Are you trying to distinguish between the Date function (aka. Date
constructor), and a Date object? The latter is an object created
by using the Date constructor with the "new" operator. The former
is a function, the latter is not.

I see no reason to distinguish between the Math object and a Date
object, except for the detail that there is only one Math object
(hence the "the"), but using the Date constructor you can create
multiple Date objects.

/L
--
Lasse Reichstein Holst Nielsen
'Javascript frameworks is a disruptive technology'

 
Reply With Quote
 
Eric Bednarz
Guest
Posts: n/a
 
      09-26-2011
Dr J R Stockton <> writes:

> On Sep 25, 12:28Â*am, Eric Bednarz <bedn...@fahr-zur-hoelle.org> wrote:
>> Dr J R Stockton <reply1...@merlyn.demon.co.uk> writes:


> The page in question


Is undisclosed, hence irrelevant.

> But I want to get an Object with value an IEEE Double of integer value
> and properties such as setDate & toJSON which Safari can list, and I
> want to do it by entering a string S, containing "new Date" and
> suitable other characters. It may not be possible.


osx:~ eric$ js
Rhino 1.7 release 3 2011 05 09
js> var evil = eval('new Date')
js> evil
Mon Sep 26 2011 02:04:59 GMT+0200 (CEST)
js> +evil
1316995499868
js> typeof evil
object
js> evil.constructor
function Date() { [native code for Date.Date, arity=1] }

js> evil.setDate
function setDate() { [native code for Date.setDate, arity=1] }

js> evil.setDate(1)
1314835499868
js> evil.toJSON
function toJSON() { [native code for Date.toJSON, arity=1] }

js> evil.toJSON()
2011-09-01T00:04:59.868Z
js>

etc.

I agree with Lasse; what did you do, what did you expect, what did you
get instead.

> --


I would appreciate if that was supposed to be an em dash.

 
Reply With Quote
 
Dr J R Stockton
Guest
Posts: n/a
 
      09-26-2011
On Sep 25, 10:14*pm, Lasse Reichstein Nielsen <lrn.unr...@gmail.com>
wrote:
> Dr J R Stockton <J.R.Stock...@physics.org> writes:
> > On Sep 25, 12:28*am, Eric Bednarz <bedn...@fahr-zur-hoelle.org> wrote:
> >> Dr J R Stockton <reply1...@merlyn.demon.co.uk> writes:

>
> >> > Is there any string S for which * eval(S) * will give a Date Object? *If
> >> > so, for the pedants, what is it?

>
> >> I really wonder what you intended to ask. As far as I am concerned,

>
> >> * 'new Date()'

>
> >> is a string and

>
> >> * eval('new Date()')

>
> >> does the obvious.

>
> > But what do you think is obvious? *

>
> That
> * eval('new Date()')
> evaluates to a Date object?
>
> > Did you test it? *


I'm a little confused here - to reply "No" there you need to be Eric
Bednarz.

> No. That's what the specification of eval says should happen. I
> don't
> test things for doing what they are supposed to do without a reason
> to suspect that thay don't. Do you have any reason to suppose it
> won't give a Date object?


I did. As I recall, and as I said in my previous reply, if I put in
"Math" I got results appropriate to the Math object, showing for
example that its .cos existed; but when I put in, or thought I put in,
"new Date()" I did not get an indication that its .getTime existed.


> > Also, what is the proper terminology to sustinguish between
> > objects like the Math object and a Date object?

>
> Are you trying to distinguish between the Date function (aka. Date
> constructor), and a Date object? The latter is an object created
> by using the Date constructor with the "new" operator. The former
> is a function, the latter is not.
>
> I see no reason to distinguish between the Math object and a Date
> object, except for the detail that there is only one Math object
> (hence the "the"), but using the Date constructor you can create
> multiple Date objects.


The distinction is that, when JavaScript starts, a Date object exists,
with a property referenced by Date.UTC; AFAIK, that Date contains no
value, there is bo Date.valueOf. But, when JavaScript starts, there
are no objects such as are created ny new Date().

Earlier, my page shwed distinct difference in behavious between the
two cases, and therefore I needed a suitable nomenclature. Now that
both are broken, that's less important, at least if neither or both
get mended.

I see that the small Flanagan book ... fumble fumble ... and the big
one class .getDate under "Methods" and .UTC under "Static Methods",
which is not entirely satisfactory - I'd need to use "non-Static
Methods".


In my earlier testing independently of the page of interest, I must
have been doing something wrong.


To show why one should not believe that browsers always behave as the
standards imply, consider
new Date(Y, 0, 1) - new Date(Y + "/01/01")
One might expect a result of zero, always. But not in my Safari 5.1
(Win XP sp3), where y=2050 gives 864e5 (IIRC, about a third of years
do that). Then, for some of us, there's always the possibility of
having misunderstood the standard.


For further possible response, I'll wait till my proper newsreader
gets the articles.

--
(c) John Stockton, near London, UK. Using Google, no spell-check.
Mail: J.R.""""""""@physics.org or (better) via Home Page at
Web: <http://www.merlyn.demon.co.uk/>
FAQish topics, acronyms, links, etc.; Date, Pascal, JavaScript, ....|
 
Reply With Quote
 
Jukka K. Korpela
Guest
Posts: n/a
 
      09-26-2011
26.9.2011 22:11, Dr J R Stockton wrote:

>As I recall, and as I said in my previous reply, if I put in
> "Math" I got results appropriate to the Math object, showing for
> example that its .cos existed; but when I put in, or thought I put in,
> "new Date()" I did not get an indication that its .getTime existed.


You could have made this discussion much shorter by telling what you
actually tested and why you think it failed.

For example, document.write(eval('new Date()').getTime()) appears to
write what one might expect, a large number.

--
Yucca, http://www.cs.tut.fi/~jkorpela/
 
Reply With Quote
 
Dr J R Stockton
Guest
Posts: n/a
 
      09-27-2011
In comp.lang.javascript message <j5ql00$afi$>, Mon, 26
Sep 2011 22:49:19, Jukka K. Korpela <> posted:

>26.9.2011 22:11, Dr J R Stockton wrote:
>
>>As I recall, and as I said in my previous reply, if I put in
>> "Math" I got results appropriate to the Math object, showing for
>> example that its .cos existed; but when I put in, or thought I put in,
>> "new Date()" I did not get an indication that its .getTime existed.

>
>You could have made this discussion much shorter by telling what you
>actually tested and why you think it failed.


Only if I could remember what it actually was.

Veterans might have suspected it to have initially been the first form
in <http://www.merlyn.demon.co.uk/js-props.htm>, for which the code is
in <http://www.merlyn.demon.co.uk/inc-prop.js>.

The next thing is that entering the strings Math & Date give,
with the lower radio-button selected, entries for sections 2 to 6; but
with new Date() sections 2 to 6 do not appear with either button.

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk BP7, Delphi 3 & 2006.
<http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
<http://www.bancoems.com/CompLangPascalDelphiMisc-MiniFAQ.htm> clpdmFAQ;
NOT <http://support.codegear.com/newsgroups/>: news:borland.* Guidelines
 
Reply With Quote
 
Jukka K. Korpela
Guest
Posts: n/a
 
      09-28-2011
27.9.2011 21:23, Dr J R Stockton wrote:

>> You could have made this discussion much shorter by telling what you
>> actually tested and why you think it failed.

>
> Only if I could remember what it actually was.


I guess that's your way of apologizing the confusion you've caused.

> Veterans might have suspected it to have initially been the first form
> in <http://www.merlyn.demon.co.uk/js-props.htm>, for which the code is
> in <http://www.merlyn.demon.co.uk/inc-prop.js>.


Are "veterans" supposed to be mind-readers and make sense of a
pointlessly messy form?

> The next thing is that entering the strings Math & Date give,
> with the lower radio-button selected, entries for sections 2 to 6; but
> with new Date() sections 2 to 6 do not appear with either button.


This looks like a rather indirect way of saying that you called
Object.getOwnPropertyNames() with an argument that is a Date instance
and was surprised at seeing that it returned an empty array.

The issue does not seem to have anything to do with eval(). You can test
it directly by using e.g.
alert(Object.getOwnPropertyNames(new Date()).length);

Which own properties did you expect a Date instance to have? ECMA-262
does not mention any. It says:

"15.9.6 Properties of Date Instances
Date instances inherit properties from the Date prototype object and
their [[Class]] internal property value is "Date". Date instances also
have a [[PrimitiveValue]] internal property."

Internal properties are not returned by Object.getOwnPropertyNames().

Thus, eval('new Date()') returns a Date instance. Your method of testing
whether it does is just faulty.

--
Yucca, http://www.cs.tut.fi/~jkorpela/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET won't retrieve query results that depend on union query Eric Nelson ASP .Net 5 02-04-2009 10:51 PM
Trying to query the Address table data of AdventureWorks database from Query Analyzer - need help! Learner ASP .Net 1 01-30-2006 08:58 PM
Build dynamic sql query for JSTL <sql:query> Anonymous Java 0 10-13-2005 10:01 PM
xpath query query David Gordon XML 2 05-18-2005 03:33 PM
CAML Query: Multiple Query Fields Issue Jon F. ASP .Net Web Services 0 05-12-2004 08:19 PM



Advertisments