Can a JavaScript reference be stored in a Uint32Array? - tags

Can a JavaScript reference be stored in a Uint32Array? I.e., is there some way to coerce or cast a reference to, for example, a function or an object into an element of some kind of TypedArray?

Related

How to reconstitute a C# object from a ClrMd pointer

I am using ClrMd to examine memory in a C# app and successively created a runtime object on a process.
I use the runtime object to call EnumerateObjects(). This returns a collection of ulongs that are references to all the objects on the heap. If the reference is to a string, I have no problem reconstituting the string using the ClrType GetValue(). However, when I call GetValue() on a reference to other objects, GetValue returns what appears to be another reference (i.e. ulong).
Do I need to execute some kind of C# unsafe code?
By the way, I get the same result with EnumerateObjectAddresses() (is there a difference between the two?)

Inline dereferencing method return parameters

I've seen several ABAP standard methods that return a reference to data as result.
CL_ABAP_EXCEPTIONAL_VALUES=>GET_MAX_VALUE( ) is one of those methods. My natural inclination is to use this method in a single line, like this:
DATA lv_max_value TYPE i.
lv_max_value = CL_ABAP_EXCEPTIONAL_VALUES=>GET_MAX_VALUE( lv_max_value )->*.
Sadly, this doesn't work, because:
Result type of the functional method "GET_MAX_VALUE" is not an object
reference or an interface reference.
The question at hand is: is it possible to dereference such results directly?
Whenever I am certain that results are compatible I would prefer to avoid the old method of dereferencing (storing the reference, assigning it to a field-symbol and then putting it into destination variable) :
DATA lv_max_value TYPE i.
DATA ref TYPE REF TO data.
FIELD-SYMBOLS <field> TYPE any.
ref = CL_ABAP_EXCEPTIONAL_VALUES=>GET_MAX_VALUE( lv_max_value ).
ASSIGN ref->* TO <field>.
lv_max_value = <field>.
It seems like a massive operation for a simple action.
The method GET_MAX_VALUE returns a variable typed TYPE REF TO DATA which is a "reference to a generic data type".
You cannot dereference generic references (*).
However, you can first CAST them, to make ABAP aware of the concrete data type, then dereference the (now typed) result of the cast.
DATA lv_max_value TYPE i.
lv_max_value = CAST i( cl_abap_exceptional_values=>get_max_value( lv_max_value ) )->*.
(*) The documentation of TYPES - REF TO says that only references to complete data types can be dereferenced:
A data reference variable typed in full with TYPE REF TO complete_type or LIKE REF TO dobj can be dereferenced in all matching operand positions using the dereferencing operator ->*. If the static data type is structured, the object component selector enables access to the components of the structure with dref->comp.
and this documentation explains that a complete data type is a "Data type that is not generic."

Why doesn't inout pass by reference?

I'm doing something like this:
someFunction(&myClass)
where someFunction sorts an array on myClass.
someFunction(inout someclass:ClassA) {
someClass.sort({$0.price > $1.price})
}
If I print myClass after the function call, I notice the array is still unsorted. From what I know, Swift passes values by copy. But when I use inout, shouldn't it change to pass by reference?
This is because class instances and functions are reference types. Ints, structs, and everything else are value types. When you pass a reference type into a function as a parameter, you are already going to be referencing that instance. When you pass a value type as a parameter, the function gets a copy of that variable (by default), so inout is usually (see edit) only needed if you want to alter a value type from inside of a function.
Altering a class instance without & or inout:
More details
When you create a reference type var t = myClass(), you're really creating a variable t that is a pointer to a myClass instance in memory. By using an ampersand &t in front of a reference type, you are really saying "give me the pointer to the pointer of a myClass instance"
More info on reference vs value types: https://stackoverflow.com/a/27366050/580487
EDIT
As was pointed out in the comments, you can still use inout with reference types if you want to alter a pointer, etc, but I was trying to shed light on the general use case.
Below is an example of sorting an array inside of a function:
If you post your code here, it would be more meaningful. BTW, look at below links that might helpful for you,
https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Functions.html#//apple_ref/doc/uid/TP40014097-CH10-ID173
https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Declarations.html#//apple_ref/doc/uid/TP40014097-CH34-ID545

how to get NPObject from NPObject JS wrapper class

Function in NP API plugin creates NPObject and returns into javascript. Then javascript variable with returned NPObject is used as parameter for some other function of plugin. e.g.
var obj = plugin.GetObject()
plugin.UseObject( obj )
But in second function (UseObject) value of parameter is not original NPObject but NPObject JS wrapper class.
Is there way to get original NPObject from instance of NPObject JS wrapper class?
Short answer: you can't.
More involved answer: Some browsers will give you the originating object, but most these days won't, and there is no way to dereference past their opaque NPObject interface to get back to the underlying object.
Alternate solution: Instead of trying to get it that way, add a unique id to your NPObject and a global map to the pointer. Then when you get an NPObject that you think might be the object, call a method (or get a property) to get the unique ID and then you can look up the pointer.
this is the only method that I've found that works consistently across all browsers.

What Zend View Partial setObjectKey do?

i am reading zend framework docs on zend view partials
If your model is an object, you may
want to have it passed as an object to
the partial script, instead of
serializing it to an array of
variables. You can do this by setting
the 'objectKey' property of the
appropriate helper:
// Tell partial to pass objects as 'model' variable
$view->partial()->setObjectKey('model');
but what does this do. when do i use it and how.
I'm not 100% positive on this, but from what I can tell by looking at the source and documentation is that standard behavior for rendering a partial is that values are passed into it in the form of an associative array. This allows the values to be bound to variables using array keys.
echo $this->partial('partial.phtml', array ('person' => 'joe');
// in my partial..
<h1><?php echo $this->person; ?></h1> //<h1>Joe</h1>
If you pass an object as the third parameter, (ie, partial('partial.phtml', $myobject);), Zend_View_Partial will automatically serialize that object in an associative array, either by a custom implementation of toArray() or it will just grab the public properties via get_object_vars().
However, if you want to pass the whole object, as an object, you need to set the array key that gets transformed into a variable for the partial to reference.
$this->partial()->setObjectKey('myobject');
echo $this->partial('partial.phtml', $myobject);
What benefits this approach has over partial('partial.phtml', array( 'myobject' => $myobject), I'm not sure. Or I could be interpreting the documentation wrong.
Key as in array(key => value)?