I have an object called twillioObject.
When I do a console.log of twillioObject, I get this output in developer tools:
I want an object of the Connection and Device classes. It seems that I can't reach it.
I have experience in JavaScript but I haven't seen this situation before. How does this work?
Related
I'm using .kendoTabStrip and it have some methods like .reload. I'm looking at this doc and what I'm doing is:
let tabStrip = $(".k-tabstrip").data("kendoTabStrip");
debugger
console.log(tabStrip)
tabStrip.reload("li.k-state-active")
$(".k-tabstrip").data("kendoTabStrip"); is equivalent to creating a tabStrip like in the doc, I'm just accessing it in a different way.
The strange part is that when I do the console.log or I inspect tabStrip while debugging, I can't see the methods like .reload like in the pictures below.
Debug
Console
But when I access the method, it's there, .reload exits even though I can't see it in other ways.
Accessing the variable
Why this is happening here and how can I see the .reload methods (or all the others) while debugging?
That happens because that reference is in fact the Kendo's Widget object from which TabStrip inherits(as seen here). To see the TabStrip's methods you have to expand the __proto__ property:
While working on JavaScript projects, I often use the console to check on objects. In the project I'm currently working with I've somehow altered the scope of the console. When I type this into the console (in Chrome Developer Tools) after everything loads I get one of the objects. Every other time I've done this (this) with other projects and sites (including StackOverflow), I've gotten back the window object.
How is it possible that the console's scope can be changed? Also helpful if you have any tips for how to debug this.
I think my problem was due to a break-point I had in the code within a component. When I was running this during the break it was returning the scope from the point of the break-point.
So it seems that the scope of the console changes along with the code execution. Somehow I never noticed this before.
We are using the V8 version 5.3.332 in my Android App. We are trying to debug the javascript using the Node-Inspector(0.11.3)(Also tried with Eclipse Chrome Dev Tools) but strangely values of certain object properties are not shown when we hover or seen it in scoped variables section. This behaviour is particularly seen for the V8 objects which has Named Property handler attached. If the V8 object is prepared with SetAccessor then values of all properties are shown properly.
We observed that, For Named Property objects, its NamedGetter is not called for its properties so all properties are being shown as undefined.
We are preparing the V8 object as below
Local funTem = FunctionTemplate::New(isolate,callback);
Local inst = funTem->InstanceTemplate();
inst->SetNamedPropertyHandler(NamedGetter,NamedSetter,NamedQueryCallback,0,NamedEnumerator);
When Debugger tries to evaluate the expression of this object, only its NamedEnumarator is called but not its NamedGetter.
Can you please let me know what could be the issue here.
For reference, this was also asked and answered on the mailing list: https://groups.google.com/forum/#!topic/v8-dev/wTYrzdx4Y3Y.
I'm a longtime Java/C++ programmer and novice Javascript programmer. I'm trying to make a web app with a class I have previously coded in C++.
In my Javascript web app, I'm using Embind to create and use the class originally coded in C++. On the Embind documentation page it says,
JavaScript code must explicitly delete any C++ object handles it has received, or the Emscripten heap will grow indefinitely.
and the examples on the page show the created object being deleted immediately after use:
var x = new Module.MyClass;
x.method();
x.delete();
In my web app, I want my object from C++ to persist for the lifetime of the webpage. I want to be able to press a button on the page and update the state of my object. If I .delete() the object at the end of the script, it won't persist when I try pushing the button later.
In the Embind example, embind.test.js, it is possible to call .deleteLater() on a newly created object:
var v = (new cm.ValHolder({})).deleteLater();
My question is, if I simply call .deleteLater() upon the object creation, is this enough for the object to be deleted when the app is done running or when the page is closed? I'm trying to avoid growing the heap indefinitely or cause any memory leaks.
Again, I'm new to Javascript so please point out if I'm missing anything obvious or if ignorant of a best practice concerning memory leaks and pointers in Javascript.
Let me know if I need to clarify anything. Thanks!
reference: https://kripken.github.io/emscripten-site/docs/porting/connecting_cpp_and_javascript/embind.html#memory-management
I'm on the same path and really don't have a concrete answer for you, but as a JS developer I can collaborate with this:
Calling delete() on an already deleted object throws an ugly exception (uncatchable from JS). There is an undocumented method to check this: obj.isDeleted(). Also obj.SS.count will be 0 when the object is "deleted"
In the browser not deleting objects could for sure break your application but from the point of view of a C++ developer this only happens in the context of the document - so by just reloading the page - you get all the memory back (is not necessary to kill the browser)
when exceptions are thrown from C++ code , like sigint, bad memory allocation, etc, it seems is not possible to catch them, even using DISABLE_EXCEPTION_CATCHING or the rest of the debug flags. Module.onAbort or similar also won't handle them. So If anybody will handle deleteLater() registered objects when the program throws must be at C++ side.
I see there's no documentation about delete(), isDeleted() deleteLater() I think those would be great candidates for a PR.
I got a question regarding C++ Object & Javascript Object life cycle mis-synchronization and hope here your gurus could help me out.
Specifically, I am embedding SpiderMonkey in my C++ program. I am not sure if my approach is right or not. What I am doing is like
(1) C++ program loads a Javascript file and call an entry function.
(2) In the entry function, some C++ functions are called to initialize the program. During these calls, some C++ objects will be created.
(3) Based on user interaction, corresponding script function will be called as event handler.
This approach works, but with one problem (there could be unidentified more :)
That is,
In my JS event handler function, I need to fetch a C++ object to the Javascript context and call it member function. For this, in my C++ fetching function, I check if its corresponding JS peer object has been created or not. If not, I use JS_NewObject to create one and return it. Then the JS function could call native function on it.
The problem is that in some cases, the result of such native function call will lead the death of the C++ object. However, I can not find a way to notify the JS context to delete its JS peer object too. I failed to find a JSAPI function to do so.
In my current program, all the JS objects created using JS_NewObject are destroyed when finally the JS runtime is destroyed.
I guess this has something do with SipderMonkey's "garbage collection". But I have not found a good guide yet. Many thanks for any suggestionto
JS is a GC'd environment so you can't simply "delete" a GC allocated object. There are basically 2 options you can take:
Make your C++ object be dependent on the JS wrapper object, if you were using refcounting for instance you would increment the C++ object's ref when you created a wrapper, and decrement the ref in the wrapper objects finalizer.
When you destroy the C++ object, fetch the wrapper object (if it exists) as clear the reference to the C++ object. All your callbacks will now need to null check prior to using the C++ object, but you won't crash (you could throw a JS exception in response perhaps?)
In most cases option 1 is what users expect.
I'd point to the required API but i don't know the SM API (I know the JSC API instead, but they same concepts apply)