Bug 1286948 - [WIP] Inspecting wasm frame vars. draft
authorYury Delendik <ydelendik@mozilla.com>
Fri, 07 Oct 2016 18:25:07 -0500
changeset 422592 d4783d84d8bf3904ac86b57bad070f3cadadfc00
parent 422591 eb17a1c307d18e0d222c6487fa5d7b9a9d444f64
child 533319 b9b84e5ae080aa38b0f059ee4e08aa9894a0dbfd
push id31754
push userydelendik@mozilla.com
push dateFri, 07 Oct 2016 23:25:30 +0000
bugs1286948
milestone52.0a1
Bug 1286948 - [WIP] Inspecting wasm frame vars. MozReview-Commit-ID: 9Pbt13obfa2
js/src/vm/EnvironmentObject.cpp
js/src/vm/EnvironmentObject.h
--- a/js/src/vm/EnvironmentObject.cpp
+++ b/js/src/vm/EnvironmentObject.cpp
@@ -627,19 +627,38 @@ ModuleEnvironmentObject::enumerate(JSCon
         properties.infallibleAppend(r.front().propid());
 
     MOZ_ASSERT(properties.length() == count);
     return true;
 }
 
 /*****************************************************************************/
 
+const ObjectOps WasmFunctionCallObject::objectOps_ = {
+    WasmFunctionCallObject::lookupProperty,
+    nullptr,                                             /* defineProperty */
+    WasmFunctionCallObject::hasProperty,
+    WasmFunctionCallObject::getProperty,
+    WasmFunctionCallObject::setProperty,
+    WasmFunctionCallObject::getOwnPropertyDescriptor,
+    WasmFunctionCallObject::deleteProperty,
+    nullptr, nullptr,                                    /* watch/unwatch */
+    nullptr,                                             /* getElements */
+    WasmFunctionCallObject::enumerate,
+    nullptr
+};
+
 const Class WasmFunctionCallObject::class_ = {
     "WasmCall",
-    JSCLASS_IS_ANONYMOUS | JSCLASS_HAS_RESERVED_SLOTS(WasmFunctionCallObject::RESERVED_SLOTS)
+    JSCLASS_HAS_RESERVED_SLOTS(WasmFunctionCallObject::RESERVED_SLOTS) |
+    JSCLASS_IS_ANONYMOUS,
+    JS_NULL_CLASS_OPS,
+    JS_NULL_CLASS_SPEC,
+    JS_NULL_CLASS_EXT,
+    &WasmFunctionCallObject::objectOps_
 };
 
 /* static */  WasmFunctionCallObject*
 WasmFunctionCallObject::create(ExclusiveContext* cx,
                                HandleWasmInstanceObject instance,
                                uint32_t funcIndex)
 {
     RootedObjectGroup group(cx, ObjectGroup::defaultNewGroup(cx, &class_, TaggedProto(nullptr)));
@@ -678,16 +697,88 @@ WasmFunctionCallObject::wasmInstance() c
 }
 
 uint32_t
 WasmFunctionCallObject::funcIndex() const
 {
     return getReservedSlot(FUNC_INDEX_SLOT).toInt32();
 }
 
+/* static */ bool
+WasmFunctionCallObject::lookupProperty(JSContext* cx, HandleObject obj, HandleId id,
+                           MutableHandleObject objp, MutableHandleShape propp)
+{
+    // TODO implement lookupProperty
+    MarkNonNativePropertyFound<CanGC>(propp);
+    objp.set(obj);
+    return true;
+}
+
+/* static */ bool
+WasmFunctionCallObject::hasProperty(JSContext* cx, HandleObject obj, HandleId id, bool* foundp)
+{
+    // TODO implement hasProperty
+    *foundp = true;
+    return true;
+}
+
+/* static */ bool
+WasmFunctionCallObject::getProperty(JSContext* cx, HandleObject obj, HandleValue receiver, HandleId id,
+                        MutableHandleValue vp)
+{
+    // TODO implement getProperty
+    RootedValue value(cx, UndefinedValue());
+    vp.set(value);
+    return true;
+}
+
+/* static */ bool
+WasmFunctionCallObject::setProperty(JSContext* cx, HandleObject obj, HandleId id, HandleValue v,
+                        HandleValue receiver, JS::ObjectOpResult& result)
+{
+   // TODO implement setProperty
+    return true;
+}
+
+/* static */ bool
+WasmFunctionCallObject::getOwnPropertyDescriptor(JSContext* cx, HandleObject obj, HandleId id,
+                                     MutableHandle<PropertyDescriptor> desc)
+{
+    // TODO implement getOwnPropertyDescriptor
+    desc.setAttributes(JSPROP_ENUMERATE | JSPROP_PERMANENT);
+    desc.object().set(obj);
+    RootedValue value(cx, UndefinedValue());
+    desc.setValue(value);
+    desc.assertComplete();
+    return true;
+}
+
+/* static */ bool
+WasmFunctionCallObject::deleteProperty(JSContext* cx, HandleObject obj, HandleId id,
+                           ObjectOpResult& result)
+{
+    return result.failCantDelete();
+}
+
+/* static */ bool
+WasmFunctionCallObject::enumerate(JSContext* cx, HandleObject obj, AutoIdVector& properties,
+                      bool enumerableOnly)
+{
+    MOZ_ASSERT(properties.length() == 0);
+    size_t count = 0;
+    if (!properties.reserve(count)) {
+        ReportOutOfMemory(cx);
+        return false;
+    }
+
+    // TODO properties.infallibleAppend for each var
+
+    MOZ_ASSERT(properties.length() == count);
+    return true;
+}
 
 /*****************************************************************************/
 
 WithEnvironmentObject*
 WithEnvironmentObject::create(JSContext* cx, HandleObject object, HandleObject enclosing,
                               Handle<WithScope*> scope)
 {
     Rooted<WithEnvironmentObject*> obj(cx);
@@ -1465,16 +1556,20 @@ class DebugEnvironmentProxyHandler : pub
         *accessResult = ACCESS_GENERIC;
         LiveEnvironmentVal* maybeLiveEnv = DebugEnvironments::hasLiveEnvironment(*env);
 
         if (env->is<ModuleEnvironmentObject>()) {
             /* Everything is aliased and stored in the environment object. */
             return true;
         }
 
+        if (env->is<WasmFunctionCallObject>()) {
+             return true; // TODO
+        }
+
         /* Handle unaliased formals, vars, lets, and consts at function scope. */
         if (env->is<CallObject>()) {
             CallObject& callobj = env->as<CallObject>();
             RootedScript script(cx, callobj.callee().getOrCreateScript(cx));
             if (!script->ensureHasTypes(cx) || !script->ensureHasAnalyzedArgsUsage(cx))
                 return false;
 
             BindingIter bi(script);
--- a/js/src/vm/EnvironmentObject.h
+++ b/js/src/vm/EnvironmentObject.h
@@ -426,30 +426,51 @@ typedef Rooted<ModuleEnvironmentObject*>
 typedef Handle<ModuleEnvironmentObject*> HandleModuleEnvironmentObject;
 typedef MutableHandle<ModuleEnvironmentObject*> MutableHandleModuleEnvironmentObject;
 
 class WasmFunctionCallObject : public EnvironmentObject
 {
     static const uint32_t INSTANCE_SLOT = 1;
     static const uint32_t FUNC_INDEX_SLOT = 2;
 
+    static const ObjectOps objectOps_;
+
   public:
     static const Class class_;
 
     static const uint32_t RESERVED_SLOTS = 3;
 
     static WasmFunctionCallObject* create(ExclusiveContext* cx,
                                           HandleWasmInstanceObject instance,
                                           uint32_t funcIndex);
 
     WasmInstanceObject& wasmInstance() const;
 
     uint32_t funcIndex() const;
+
+  private:
+    static bool lookupProperty(JSContext* cx, HandleObject obj, HandleId id,
+                               MutableHandleObject objp, MutableHandleShape propp);
+    static bool hasProperty(JSContext* cx, HandleObject obj, HandleId id, bool* foundp);
+    static bool getProperty(JSContext* cx, HandleObject obj, HandleValue receiver, HandleId id,
+                            MutableHandleValue vp);
+    static bool setProperty(JSContext* cx, HandleObject obj, HandleId id, HandleValue v,
+                            HandleValue receiver, JS::ObjectOpResult& result);
+    static bool getOwnPropertyDescriptor(JSContext* cx, HandleObject obj, HandleId id,
+                                         MutableHandle<PropertyDescriptor> desc);
+    static bool deleteProperty(JSContext* cx, HandleObject obj, HandleId id,
+                               ObjectOpResult& result);
+    static bool enumerate(JSContext* cx, HandleObject obj, AutoIdVector& properties,
+                          bool enumerableOnly);
 };
 
+typedef Rooted<WasmFunctionCallObject*> RootedWasmFunctionCallObject;
+typedef Handle<WasmFunctionCallObject*> HandleWasmFunctionCallObject;
+typedef MutableHandle<WasmFunctionCallObject*> MutableHandleWasmFunctionCallObject;
+
 class LexicalEnvironmentObject : public EnvironmentObject
 {
     // Global and non-syntactic lexical environments need to store a 'this'
     // value and all other lexical environments have a fixed shape and store a
     // backpointer to the LexicalScope.
     //
     // Since the two sets are disjoint, we only use one slot to save space.
     static const unsigned THIS_VALUE_OR_SCOPE_SLOT = 1;