kokizzu / plv8js

Automatically exported from code.google.com/p/plv8js
Other
0 stars 0 forks source link

Shared data #11

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
pl/perl has $_SHARED and pl/python has SD/GD. I heard from someone that he 
wants to use something like them. I found plv8 can do it with "this" but am not 
sure if it should be used or such global variables should be supported. If yes, 
we need to take care of it and document it.

db1=# create function f() returns int as $$ if (!this.i) this.i = 0; this.i++; 
return this.i; $$ language plv8;
CREATE FUNCTION
db1=# select f();
 f 

---
 1
(1 row)

db1=# select f();
 f 

---
 2
(1 row)

db1=# select f();
 f 

---
 3
(1 row)

Original issue reported on code.google.com by umi.tan...@gmail.com on 3 Feb 2012 at 10:29

GoogleCodeExporter commented 9 years ago
I'm inclined to introduce a new pre-defined object, "global" (or GD) to save 
the shared data.  My idea is not to let normal functions modify it, but only 
the start-up process Andrew is thinking of can modify it and after that it's 
read-only.

Maybe my Separate Context approach was wrong; Still, we have function-local 
"this" object.

Original comment by umi.tan...@gmail.com on 17 Apr 2012 at 9:43

GoogleCodeExporter commented 9 years ago
Something not modifiable won't meet the case. It's intended as a 
between-invocation stash.

Original comment by AMDuns...@gmail.com on 19 Apr 2012 at 12:29

GoogleCodeExporter commented 9 years ago
But the behavior is unpredictable as the invocation order may be changed during 
planning.  What's the real world use case?

Original comment by umi.tan...@gmail.com on 19 Apr 2012 at 12:52

GoogleCodeExporter commented 9 years ago
Invocation order is only unpredictable when a statement calls more than one 
function. The real world use case is as a stash for data between statements. 
That's how it's used in PLPerl and PLPython.

Original comment by AMDuns...@gmail.com on 26 Apr 2012 at 2:41

GoogleCodeExporter commented 9 years ago
My concern is JavaScript is fragile language.  A lot of premature developers 
break the runtime environment by modifying the global variable and builtin 
objects.  That is, if that is the case, today you can assign any properties to 
the plv8 object which is visible from everyone.

Original comment by umi.tan...@gmail.com on 27 Apr 2012 at 12:56

GoogleCodeExporter commented 9 years ago
And there has been a lot of effort to guard this nature from the language 
specification like Object.freeze(), Object.seal(), plus from the framework like 
commonJS where each module can play only in the separated namespace.

Original comment by umi.tan...@gmail.com on 27 Apr 2012 at 12:59

GoogleCodeExporter commented 9 years ago
I think it's enough to just have plv8 as it stands today, isn't it?  The object 
can have any property except for pre-defined functions.  If there's no 
objection, I'm closing this.

Original comment by umi.tan...@gmail.com on 2 May 2012 at 7:21

GoogleCodeExporter commented 9 years ago
Closing, given my comment above.

Original comment by umi.tan...@gmail.com on 30 May 2012 at 5:53