edbrowse-dev - development list for edbrowse
 help / color / mirror / Atom feed
* Re: [Edbrowse-dev] [patch] [experimental] JS console patch
       [not found] <5608d799.c539440a.54033.3b99SMTPIN_ADDED_BROKEN@mx.google.com>
@ 2015-09-29  7:03 ` Adam Thompson
  2015-09-29  9:04   ` Kevin Carhart
  0 siblings, 1 reply; 4+ messages in thread
From: Adam Thompson @ 2015-09-29  7:03 UTC (permalink / raw)
  To: Kevin Carhart; +Cc: Edbrowse-dev

[-- Attachment #1: Type: text/plain, Size: 418 bytes --]

On Sun, Sep 27, 2015 at 11:00:52PM -0700, Kevin Carhart wrote:
> Here is my JS console code.
> The commands I currently use are:
> eg = enumerate globals
> jex = javascript execute
> ok = object keys - this is the JS function that eg runs,
> so you can then call it in an expression like alert(ok(blah))

Looks good to me from a command point of view. How've you done the ok function?
Is that a piece of js somewhere?

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Edbrowse-dev] [patch] [experimental] JS console patch
  2015-09-29  7:03 ` [Edbrowse-dev] [patch] [experimental] JS console patch Adam Thompson
@ 2015-09-29  9:04   ` Kevin Carhart
  0 siblings, 0 replies; 4+ messages in thread
From: Kevin Carhart @ 2015-09-29  9:04 UTC (permalink / raw)
  To: Adam Thompson; +Cc: Edbrowse-dev



Hi group,

Thanks for pushing the console code and improving it!

Adam and Karl asked:

> How've you done the ok function?
> Is that a piece of js somewhere?

> Wow! First of all, I don't undderstand that javascript at all,
> but I see that it works, so on we go.

Yes, I didn't write that, it's on MDN here,
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys

I brought it in without totally understanding it, but I know one
distinction that they talk about is whether you want to
echo all the methods just on the thing being passed in,
or also on its prototype.

While we're on the subject of what in the world is the
Object.keys code doing, there's another distinction which
may come up some day.  "IsEnumerable" is used in the
function.
Objects can have properties like enumerable,
configurable and writeable. 
It has to do with a permissions idea - I think.
If an object's enumerable is false, I think ok
would return nothing, or is supposed to.
I think it's something to do with protecting
the inaccessibility of private methods.


Kevin






>

--------
Kevin Carhart * 415 225 5306 * The Ten Ninety Nihilists

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Edbrowse-dev]  [patch] [experimental] JS console patch
  2015-09-28  6:00 Kevin Carhart
@ 2015-09-28  9:47 ` Karl Dahlke
  0 siblings, 0 replies; 4+ messages in thread
From: Karl Dahlke @ 2015-09-28  9:47 UTC (permalink / raw)
  To: Edbrowse-dev

> Here is my JS console code.

Wow! First of all, I don't undderstand that javascript at all,
but I see that it works, so on we go.
It is now included in startwindow.js as per the latest push.
You don't have to type an extra command; the ok (object keys) function is there.

Type jex (javascript executions) from a running web page
to enter this mode.
I very much didn't want to type jex each and every time, so it's a mode,
like a in the editor.
Type . by itself to exit this mode.
So now you can look at and change variables, and use the ok function for
the members of any object.
alert(ok(document.body));
But there are two major things to fix.

1. All the gc variables under document are damn annoying.
These are artificial placeholders in edbrowse to protect
certain things from garbage collection.
They could all be members of the object document.gc$,
instead of variables under document.
That's not hard to do but not trivial, and must be done in both decorate.c
and jseng-moz.cpp.

2. The real nuisance is having to type alert all the time.
When you run a js shell, from mozilla or v8 or whomever,
the result of your entered command is  displayed if there is a result.
You don't have to type alert all the time.
This is obviously what we want.
So javaParseExecute should return a string if the
executed script has a result,
a string we can print if not null,
or perhaps a new function javaParseExecuteResult for this purpose.
Then this feature won't be quite so painful to use.

If you set db3 before you enter then you will see syntax errors etc,
instead of just silence, assuming your entered command worked
when maybe it didn't.

this is not documented yet, because I don't think we have
the final interface or all the details worked out.
But we all wanted it, and it was so damn easy to do,
especially since Kevin handed me the ok() function,
so why not move forward on it.
If someone wants to address either of the shortcomings above,
or suggest improvements, let me know.

Karl Dahlke

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Edbrowse-dev] [patch] [experimental] JS console patch
@ 2015-09-28  6:00 Kevin Carhart
  2015-09-28  9:47 ` Karl Dahlke
  0 siblings, 1 reply; 4+ messages in thread
From: Kevin Carhart @ 2015-09-28  6:00 UTC (permalink / raw)
  To: Edbrowse-dev

[-- Attachment #1: Type: text/plain, Size: 1702 bytes --]

Here is my JS console code.
The commands I currently use are:
eg = enumerate globals
jex = javascript execute
ok = object keys - this is the JS function that eg runs,
so you can then call it in an expression like alert(ok(blah))

'eg' and 'jex' do not exactly roll off the tongue.
Could be changed into another command.
What my fingers are accustomed to is 'x' and 'y'

Here is some sample usage:
b http://pizza.com
[the page loads and the file sizes are returned]

eg
[voluminous output of about 100 objects and scalars, most having to do with google ads and god knows what]

jex alert('hello world')
hello world

jex var x = 5
?

jex alert(x)
5

jex alert(ok(document))
[voluminous output of enumeration of all objects under document, presently ending in our gc objects gc$$814, gc$$815, gc$$816]

jex for (blah in window) { alert(blah) }
[all of the objects in window, formatted with newlines]

jex alert(google_adk2_experiment)
N

[Well that's a relief!  Nice to know I am not a subject in an adk2 experiment.  All I wanted was some pizza...]


jex alert(google_jobrunner)
[object Object]

[google_jobrunner is an object.  I'm curious what's in it.]

jex alert(ok(google_jobrunner))
u,m,l,s,G


jex var jr = google_jobrunner
?

[Making an alias on the fly.]
jex alert(jr)
[object Object]

jex alert(jr.u)
[object Object]

jex alert(jr.m)
[object Window]

jex alert(jr.l)
0

jex alert(jr.s)
null

jex alert(jr.G)
0

[This scratches the surface .. function bodies can also be echoed and can be run using eval.  Get a sanity check on what you are debugging.. take 'typeof' different things to verify your assumptions... etc.]



[-- Attachment #2: /home/kevin/public_html/c7/edbrowse/jsconsole_20150927.patch --]
[-- Type: text/plain, Size: 1532 bytes --]

diff -Naur 1/src/buffers.c 2/src/buffers.c
--- 1/src/buffers.c	2015-09-27 11:06:51.000000000 -0700
+++ 2/src/buffers.c	2015-09-27 22:15:31.656778785 -0700
@@ -3554,6 +3554,44 @@
 		return true;
 	}
 
+	if (stringEqual(line, "eg")) {
+		static const char jsconsole1[] = "ok = Object.keys = Object.keys || (function () { \n\
+		var hasOwnProperty = Object.prototype.hasOwnProperty, \n\
+		hasDontEnumBug = !{toString:null}.propertyIsEnumerable(\"toString\"),\n\
+		DontEnums = [ \n\
+		'toString', 'toLocaleString', 'valueOf', 'hasOwnProperty', \n\
+		'isPrototypeOf', 'propertyIsEnumerable', 'constructor' \n\
+		], \n\
+		DontEnumsLength = DontEnums.length; \n\
+		return function (o) { \n\
+		if (typeof o != \"object\" && typeof o != \"function\" || o === null) \n\
+		throw new TypeError(\"Object.keys called on a non-object\");\n\
+		var result = []; \n\
+		for (var name in o) { \n\
+		if (hasOwnProperty.call(o, name)) \n\
+		result.push(name); \n\
+		} \n\
+		if (hasDontEnumBug) { \n\
+		for (var i = 0; i < DontEnumsLength; i++) { \n\
+		if (hasOwnProperty.call(o, DontEnums[i]))\n\
+		result.push(DontEnums[i]);\n\
+		}\n\
+		}\n\
+		return result; \n\
+		}; \n\
+		})(); \n\
+		alert(Object.keys(this)); \n\
+		";
+		javaParseExecute(cw->winobj, jsconsole1, "",1);
+		return true;
+	}
+
+	if (!strncmp(line, "jex ", 4)) {
+		char* routineonly = line + 4;
+		javaParseExecute(cw->winobj, routineonly, "",1);
+		return true;
+	}
+
 	if (stringEqual(line, "lna")) {
 		listNA ^= 1;
 		if (helpMessagesOn || debugLevel >= 1)

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-09-29  9:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <5608d799.c539440a.54033.3b99SMTPIN_ADDED_BROKEN@mx.google.com>
2015-09-29  7:03 ` [Edbrowse-dev] [patch] [experimental] JS console patch Adam Thompson
2015-09-29  9:04   ` Kevin Carhart
2015-09-28  6:00 Kevin Carhart
2015-09-28  9:47 ` Karl Dahlke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).