Skip to content

Commit bcf6a1f

Browse files
committed
implement separate and virtual deletePropertyValue function, include in spec
1 parent 426a1a1 commit bcf6a1f

File tree

4 files changed

+60
-41
lines changed

4 files changed

+60
-41
lines changed

eval.sml

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,58 @@ and defValue (regs:REGS)
909909
: unit =
910910
setPropertyValueOrVirtual regs base name v false
911911

912+
913+
and deletePropertyValueOrVirtual (regs:REGS)
914+
(obj:OBJECT)
915+
(name:NAME)
916+
(doVirtual:bool)
917+
: VALUE =
918+
let
919+
val Object { propertyMap, tag, ... } = obj
920+
val existingProp = findProp propertyMap name
921+
in
922+
case existingProp of
923+
SOME { attrs = { fixed = true, ...}, ...}
924+
925+
=> newBoolean regs false
926+
927+
| _
928+
=> if
929+
doVirtual andalso
930+
Fixture.hasFixture (getFixtureMap regs obj) (PropName meta_delete)
931+
then
932+
(trace ["running meta::delete(\"", (Ustring.toAscii (#id name)), (* INFORMATIVE *)
933+
"\") catchall on obj #", fmtObjId obj]; (* INFORMATIVE *)
934+
(* LPAREN *)(evalNamedMethodCall regs obj meta_delete [newString regs (#id name)])
935+
handle ThrowException e =>
936+
let
937+
val ty = typeOfVal regs e
938+
val defaultBehaviorClassTy =
939+
instanceType regs helper_DefaultBehaviorClass []
940+
in
941+
if ty <* defaultBehaviorClassTy then
942+
deletePropertyValueOrVirtual regs obj name false
943+
else
944+
throwExn e
945+
end
946+
)(* INFORMATIVE *)
947+
else
948+
case existingProp of
949+
SOME { attrs = { removable = true, ... }, ... }
950+
=> (delProp propertyMap name;
951+
newBoolean regs true)
952+
953+
| _
954+
=> newBoolean regs false
955+
end
956+
957+
958+
and deletePropertyValue (regs:REGS)
959+
(base:OBJECT)
960+
(name:NAME)
961+
: VALUE =
962+
deletePropertyValueOrVirtual regs base name true
963+
912964
and instantiateGlobalClass (regs:REGS)
913965
(n:NAME)
914966
(args:VALUE list)
@@ -2796,13 +2848,9 @@ and evalUnaryOp (regs:REGS)
27962848
case unop of
27972849
Delete =>
27982850
let
2799-
val (_, (Object {propertyMap, ...}, name)) = resolveRefExpr regs expr false
2851+
val (_, (obj, name)) = resolveRefExpr regs expr false
28002852
in
2801-
if (hasProp propertyMap name)
2802-
then if (#removable (#attrs (getProp propertyMap name)))
2803-
then (delProp propertyMap name; newBoolean regs true)
2804-
else newBoolean regs false
2805-
else newBoolean regs true
2853+
deletePropertyValue regs obj name
28062854
end
28072855

28082856
| PreIncrement => evalCrement regs Plus true expr

name.sml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ val meta_get = meta Ustring.get_
295295
val meta_set = meta Ustring.set_
296296
val meta_has = meta Ustring.has_
297297
val meta_call = meta Ustring.call_
298+
val meta_delete = meta Ustring.delete_
298299

299300
val public_arguments = public Ustring.arguments_
300301
val helper_argsLength = helper Ustring.argsLength_

spec/language/readwrite.html

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -179,40 +179,9 @@
179179
phrase that was recognized in a region of code that was covered by a
180180
strict mode pragma.
181181

182-
<FIXME> This protocol must be specified as SML code.
182+
183+
<FIXME>Strict mode is not implemented in this code.
183184

184185
<SEM>
185-
<PRE>
186-
fun DeleteProperty(obj, name, isStrict)
187-
if (name is a property in the property map of obj, denote it obj.name &&
188-
the fixed attribute of obj.name is true)
189-
if isStrict
190-
throw a ReferenceError, "can't delete fixture properties"
191-
end
192-
return false
193-
end
194-
195-
if (meta::delete is a property in the property map of obj,
196-
denote it obj.meta::delete
197-
&& the fixed attribute of meta::delete is true)
198-
try
199-
return obj.meta::delete(name)
200-
catch DefaultBehavior
201-
; fall through to the next case
202-
end
203-
end
204-
205-
if name is a property in the property map of obj, denote it obj.name
206-
if the removable attribute of obj.name is true
207-
remove obj.name from the property map of obj
208-
return true
209-
end
210-
211-
if isStrict
212-
throw a ReferenceError, "can't delete non-removable property"
213-
end
214-
end
215-
216-
return false
217-
end
218-
</PRE>
186+
<INCLUDE file="eval.sml" name="and deletePropertyValue">
187+
<INCLUDE file="eval.sml" name="and deletePropertyValueOrVirtual">

ustring.sml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ val has_ = fromString "has"
235235
val call_ = fromString "call"
236236
val get_ = fromString "get"
237237
val set_ = fromString "set"
238+
val delete_ = fromString "delete"
238239
val slice_ = fromString "slice"
239240
val objectHash_ = fromString "objectHash"
240241
val type_ = fromString "type"

0 commit comments

Comments
 (0)